Skip to main content
Not every error from Piramyd warrants a retry — some indicate a problem with your request that no amount of waiting will fix, while others are transient conditions that resolve on their own within seconds. Build your integration to distinguish between the two from the start, and you will avoid wasting quota on futile retries while recovering automatically from the errors that are genuinely recoverable.

Which Errors to Retry

Retry these status codes

Do NOT retry these status codes

Fix the underlying cause before attempting another request.

Special case: context_length_exceeded

You do not need to handle this one manually. When a context_length_exceeded error occurs and your request includes a thread_id (or conversation_id), the API automatically retries once after compacting older messages into a structured summary. The retry is transparent — you receive a successful response as if the error never happened. Without a thread_id, reduce your message history and retry yourself.

Exponential Backoff Strategy

Use the following parameters for all retryable errors:
  • Base delay: 1 second
  • Maximum delay: 8 seconds
  • Jitter: add a random fraction of the current delay to avoid thundering-herd collisions
  • Retry-After override: on 429 responses, use the value from the Retry-After header as the minimum wait, then apply your backoff on top for subsequent attempts
The Python example below shows a manual retry loop that covers all retryable status codes and honours Retry-After:
If you prefer a library approach, tenacity integrates cleanly. Wrap the httpx.post call with @retry(wait=wait_exponential(min=1, max=8), stop=stop_after_attempt(5)) and add a before_sleep hook to inspect Retry-After.

Request Tracing

Attach a unique X-Request-ID header to every request. Piramyd echoes the value back in the response headers, and streaming errors include it in the request_id field of the error payload. Persisting this ID in your logs dramatically reduces time-to-resolution when you open a support ticket.
Generate a fresh ID per request — not per session. UUIDs work well, but any string that is unique within your system is fine.

Upstream Errors

A 502 response means an upstream inference provider returned an error or became temporarily unreachable. Piramyd normalises all upstream errors into the same standard error shape before returning them to you — you do not need to handle provider-specific error formats. Apply the same exponential backoff logic you use for other 5xx responses. Upstream outages are typically short-lived, and a request that fails immediately often succeeds within a few seconds.
Log the X-Request-ID (or the request_id field from streaming errors) for every failed request before your retry loop moves on. Having that ID ready when you contact support means issues get diagnosed in minutes rather than hours.