Responses and errors
Read streamed text, retry an interrupted call and identify API errors.
Read the response
For a JSON completion, read the assistant’s text at choices[0].message.content.
For incremental text, set stream to true and read choices[0].delta.content from each data event that carries text.
Retry a request
Generate one UUID per operation and send it in Idempotency-Key on Chat Completions, Messages or Responses. For a retry within 24 hours, use the same API key, endpoint and exact JSON body. Kavren returns the original request ID and bills a model call once.
-H "Idempotency-Key: $REQUEST_UUID"A replay carries Idempotency-Replayed: true. Stream replays start from the first event. Encrypted replies up to 2 MiB can be replayed for up to one hour, subject to cache space. If the reply is unavailable, the 24-hour duplicate guard still applies.
Troubleshoot a call
Send Accept-Language: en or Accept-Language: tr to choose the language of API error messages. The default is English. Handle errors using the HTTP status and error.code when present. A replay preserves the original response, including its language.
400 Request format
Check the model’s input types, image encoding and output limit.
401 Invalid key
Check the Bearer header and confirm that your customer key is enabled.
402 Available balance
Check your available balance in Wallet. The reservation covers the context window and requested output allowance.
403 Access denied
Inspect error.code. For ip_not_allowed check your server’s egress IP. For model_not_allowed choose a model permitted by the key.
404 Unknown route or model
Check the path, model ID and requested capability. An embedding request can return model_not_found for a chat model.
409 Repeated request
For idempotency_in_progress, wait for Retry-After and retry with the same key. For idempotency_conflict, check the endpoint and body. For idempotency_result_unavailable, look up the original request ID in usage before making a new call.
411 Missing body length
Send a JSON request with Content-Length. Standard SDKs and curl set it when sending a complete body.
413 Payload too large
Keep the complete JSON body within 6 MiB and each decoded inline image within 512 KiB.
415 Media type
Set Content-Type to application/json on POST requests.
429 Request limit
Reduce concurrent calls and wait for the number of seconds in Retry-After if that header is present.
502 Invalid model response
Keep the request ID and check Usage before sending a new generation.
503 Temporarily unavailable
Wait for available capacity. If present, respect Retry-After.
504 Request timed out
Check the request in Usage and retry with the original idempotency key.