Handle Errors and Retries
Every error from the API has the same body:
The SDKs raise one typed error for each HTTP status, so you can catch the ones you can handle.
The Python errors are in sarvamai.errors, and ApiError is in sarvamai.core.api_error. The full list of classes is in the SDK.
Catch the error
Keep the request_id (it is also in the x-request-id response header). Send it to support when you report a problem.
Which errors to retry
What the SDK retries for you
The SDK retries 408, 429 and every 5xx up to 2 more times, with a growing wait that follows Retry-After. You
only see the error when those tries are used up. To change the number, pass it with the call:
The SDK also retries 503 service_unavailable, which is not worth retrying. If you see it, stop and report it.
A 200 can still be a soft failure
The finishing step never fails a call. If it fails or is too slow, you get a 200 where text is the raw
transcript and degraded says why. A degraded call is not billed. Check degraded in every response, and
output.degraded when you send output_rules. Send the clip again if you need the finished text.
An empty text is not an error
A clip with no speech, such as background noise, returns 200 with an empty text, degraded as null, and no
finishing tokens. With language_code=auto, the language_code in the response is null. Check for an empty text
before you use it.
On the live socket
The socket reports a problem as an error message, and ends with a close code. 1012 means the service is restarting:
connect again. 1013 means overloaded: wait, then connect again. 1011 with keepalive ping timeout means your client stopped reading, so it stopped answering the server’s pings: read messages in their own task. See the close codes.