401 and 403 with missing_api_key, invalid_api_key, or missing_api_key_scope) carry "status": "failure" instead of "failed". Branch on the HTTP status and error.code, not on status.
HTTP Policy
Common authentication codes are
missing_api_key, invalid_api_key, and missing_api_key_scope. Validation codes begin with developer_v3_search_ or developer_v3_enrich_ and identify the affected contract.
Not every error body is JSON. Read the body as text and parse it only when the Content-Type is application/json.
Async Failures
An accepted request can later finish with a failed result. These failures appear inside the resource rather than as an HTTP error:completed_with_errors is a terminal aggregate with usable results. Keep every ready result and handle failed items individually. Treat failed as a terminal search with no ready results.
For Enrich, stop polling on completed or failed. The request_id in the response is the status handle for accepted work.
Safe Retry Pattern
- Choose how retries stay idempotent. If you send nothing, Orbit generates a request ID, and a retried POST after a lost response can start duplicate work. To make retries safe, create an ID before the first POST and send it as
request_idin the body or as theIdempotency-Keyheader. If you send both, Orbit usesrequest_id. - Persist that ID, and the returned
search_idor Enrichrequest_id, before you poll. - Retry lost responses,
429, and5xxerrors with the same ID and the exact same body. A lost response is a timeout, a refused or reset connection, or a connection that closes before the response arrives; Orbit may have accepted the request. Do not retry other4xxerrors unchanged. - On
429, wait at leastRetry-Afterseconds. Without the header, wait 1 second. On repeated failures, wait the larger ofRetry-Afterand an exponential backoff with jitter, for example 1, 2, 4, then 8 seconds, each varied by up to 20%. - Cap retries, for example at 5 attempts, then surface the error with its
error.code. - Stop polling on every terminal status.
- Keep each
request_idorIdempotency-Keyunique across your whole application. It belongs to the API key that sent it, so when one key serves many users, add a per-user prefix.
Python Example
This standard-library client retries429, 5xx errors, and lost responses with the same Idempotency-Key, and never logs the key. You own the key: create it and save it before the first call, so a later call with the same key can resume the request if every attempt fails.
OSError and http.client.HTTPException, not only URLError and TimeoutError. A connection that closes before the response arrives raises http.client.RemoteDisconnected or ConnectionResetError, and on Python 3.9 a read timeout raises socket.timeout. None of these is a URLError.