import time
from tracia import Tracia, TraciaError, TraciaErrorCode
client = Tracia(api_key="tr_your_api_key")
NON_RETRYABLE = {
TraciaErrorCode.UNAUTHORIZED,
TraciaErrorCode.NOT_FOUND,
TraciaErrorCode.MISSING_VARIABLES,
TraciaErrorCode.INVALID_REQUEST,
}
def run_with_retry(slug: str, variables: dict[str, str], max_retries: int = 3):
for attempt in range(1, max_retries + 1):
try:
return client.prompts.run(slug, variables)
except TraciaError as error:
if error.code in NON_RETRYABLE:
raise
if attempt < max_retries:
delay = 2**attempt
time.sleep(delay)
continue
raise