TypeScript
error.code, giving a request error if:
- Your original request is invalid
- Your API key/account is out of credits
200 and any error occurred while the LLM is producing the output will be emitted in the response body or as an SSE data event.
Example code for printing errors:
TypeScript
Error Codes
400: Bad Request (invalid or missing params, CORS)401: Invalid credentials (OAuth session expired, disabled/invalid API key)402: Your account or API key has insufficient credits. Add more credits and retry the request.403: Your chosen model requires moderation and your input was flagged408: Your request timed out429: You are being rate limited502: Your chosen model is down or we received an invalid response from it503: There is no available model provider that meets your routing requirements
Moderation Errors
If your input was flagged, theerror.metadata will contain information about the issue. The shape of the metadata is as follows:
TypeScript
Provider Errors
If the model provider encounters an error, theerror.metadata will contain information about the issue. The shape of the metadata is as follows:
TypeScript
Common Errors & How to Avoid Them
These are the errors we see most often in production, what causes them, and how to keep them out of your requests.Invalid image data (400)
gpt-5.4, gpt-5.5). It means the bytes behind your image_url could not be decoded into a real image. The request never reaches the model — it’s rejected up front — so retrying the exact same payload will always fail.
How to avoid it
- Validate every image before sending — decode the base64 and confirm it opens as a real image:
Python
- Build the data URL with the detected MIME type, not a hard-coded one (use
Image.formator apython-magicsniff). - Strip whitespace from base64:
b64 = b64.replace("\n", "").replace(" ", ""). - For remote images, prefer fetching and inlining them as base64 yourself so you control the bytes, rather than passing a third-party URL the upstream must download.
- Downscale large images (e.g. longest edge ≤ 2048 px) to stay under size limits and reduce latency/cost.
Model produced invalid content (500)
- Retry with backoff — this is usually transient. A single retry clears most occurrences, and our router will already failover across regions.
- Simplify the request if it’s persistent — overly complex tool JSON schemas, deeply nested
requiredfields, or ambiguous instructions make the model more likely to emit malformed tool arguments. Flatten schemas and tighten the prompt. - Keep the request ID from the message when escalating to support.