Errors and retries
Every exception the SDK raises for an API, connection or configuration
problem subclasses CLIError, importable from cli_sdk. Invalid query or
resource arguments raise ConfigurationError at construction time, before
anything reaches the network; ConfigurationError is also a ValueError,
so existing except ValueError code keeps working.
Exception map
| Exception | Raised when | Retried by default |
|---|---|---|
AuthenticationError | 401: missing, invalid or revoked API key, or the key’s creator left the organization | No |
ValidationError | 422: the request failed validation. .field names the offending field when the server reports one. | No |
InsufficientCalibrationError | A profile is too small or not ready for the requested guarantee, and you opted into strict mode (see below); also a 424 from any non-evaluate endpoint, for example auditing a profile that was never calibrated | No |
RateLimitError | 429 after retries are exhausted. .retry_after holds the server’s retry-after in seconds, if numeric. | Yes |
BackendError | 502: the model backend failed or timed out, or cannot reach the pinned access level. 529: the service or your provider is overloaded. | Yes |
APIConnectionError | The API could not be reached (connection refused, DNS failure, timeout) after the configured retries | Yes |
ConfigurationError | Client-side misconfiguration, raised before any request (also a ValueError): a query missing a required field or with an invalid one (Set with fewer than 2 options, Gate with target outside , Route with guarantee="cost_budget" and no target_cents, …); an invalid calibration_profiles.create method or alpha; an invalid monitor type, missing target or false_alarm_rate; a CalibrationExample with an unknown source; no API key for a non-local base_url; no backend for a query that does not declare its own cascade (Route, or Judge with cascade); an empty queries map or a value that is not a query; a backend dict without "provider"; a hosted backend without model or with an unknown access_hint; VLLMBackend or SGLangBackend without base_url; an unknown CustomBackend.access_level; a response_model that is not an EvaluateResponse subclass | No |
CLIError | Any other HTTP status of 400 or above, as "HTTP <status>: <message>": for example 402 (provider quota), 403 (missing scope), 404 (unknown profile, monitor or job), 409 (profile exists, request in flight), 413, 504 | No |
Not wrapped in CLIError:
| Exception | Raised when |
|---|---|
ValueError | An invalid RetryConfig; an unsupported LocalMonitor type; a declared response_model answer that is missing from the response; invalid arrays passed to cli_sdk.stats functions |
TypeError | A declared response_model answer has the wrong type |
NotImplementedError | A CustomBackend evidence method a query needs is not implemented |
from cli_sdk import (
AuthenticationError, BackendError, CLIClient, CLIError, ConfigurationError,
InsufficientCalibrationError, RateLimitError, ValidationError,
)
try:
result = client.evaluate(context=ticket, backend=backend, queries=queries)
except ValidationError as err:
log.error("bad request field=%s: %s", err.field, err)
except RateLimitError as err:
schedule_retry(after=err.retry_after or 30)
except BackendError:
fall_back_to_human_queue()
except InsufficientCalibrationError:
fall_back_to_human_queue() # strict mode: no heuristic answers
except CLIError as err:
log.exception("evaluate failed: %s", err)
fall_back_to_human_queue()An unknown profile, monitor or job is 404 on its own routes, which the
SDK raises as CLIError (HTTP 404: ...). An evaluate whose query
names a profile that was never created is 422 profile_not_found
(ValidationError, with field set to
queries.<id>.calibration_profile).
Heuristic answers and 424
When a query cannot be answered with a guarantee, the service answers
with HTTP 424 Failed Dependency and a body that still contains an answer
for every query, with the affected answers’ cards labelled heuristic and
a warnings entry saying why:
| Why | What to do |
|---|---|
| The profile has no examples, or fewer than the query needs (below , or underpowered for the requested bound) | Add examples |
| Calibration is running as a background job | Wait for the job, or for profile.status == "serving" |
The profile is stale: a strict profile saw a different backend, a monitor with on_alarm="stale" alarmed, or a zero-retention profile cannot re-score | Use the calibrated backend, or recalibrate |
| A non-strict profile is recalibrating for a new backend | Wait for the job |
By default, evaluate returns that response instead of raising: the
answers are usable, and they say plainly that no formal guarantee backs
them. A heuristic answer takes its safe form: a Set returns every
option, a Gate escalates, a Belief returns , an Interval
every level, a Claim retains nothing, and a Judge or Route goes to
the human queue.
result = client.evaluate(context=ticket, backend=backend, queries=queries)
if result.heuristic_answers: # e.g. ["route"]
for qid in result.heuristic_answers:
print(qid, result.answers[qid].guarantee.describe())
# No guarantee: profile 'support-auto-route-v3' is being calibrated
print(result.warnings)
gate = result.answers["route"]
if gate.approved and not gate.is_heuristic:
auto_route()
else:
send_to_human()The SDK applies the same rule to every response, whatever its status: an
answer whose card is missing, or whose type is not one of the eight
known guarantee types, is treated as heuristic. A Gate decision other
than auto_approve, escalate, or abstain is read as escalate. The
SDK never turns an unrecognized answer into an approval.
strict_guarantees
Pass strict_guarantees=True to refuse heuristic answers outright:
client = CLIClient(strict_guarantees=True)evaluate then raises InsufficientCalibrationError whenever any
answer in the response is heuristic — on a 424, and also on a 200
response that contains a heuristic answer. The message lists the query ids.
Use strict mode in paths where acting on an unguaranteed answer is never
acceptable, and handle the exception by falling back to human review.
Strict mode changes what you receive, not what is guaranteed. A non-heuristic answer is still a marginal or group-conditional guarantee over exchangeable data, never a promise about the one request in front of you.
Error codes
Every error body is {"message", "code", "field"?, "details"?, "request_id"}. Provider error bodies are never echoed: the service
classifies them into the codes below and logs the detail against the
request id.
Authentication and permissions
| Code | Status | Meaning |
|---|---|---|
missing_api_key | 401 | No Authorization: Bearer header |
invalid_api_key | 401 | Unknown key |
revoked_api_key | 401 | The key was revoked |
key_owner_removed | 401 | The key’s creator is no longer in its organization |
insufficient_scope | 403 | The key lacks the scope this route needs; WWW-Authenticate names it |
forbidden_role | 403 | Your role does not allow this action (dashboard routes, zero-retention changes) |
Request shape
| Code | Status | Meaning |
|---|---|---|
invalid_json, body_not_object | 422 | The body is not a JSON object |
unknown_field | 422 | A field the route does not accept; field names it |
validation_error | 422 | Any other invalid value; field names it |
unknown_query_type | 422 | A query type other than the seven primitives |
unknown_provider | 422 | A backend.provider the service does not serve |
unsupported_option | 422 | An option the hosted engine does not implement, for example a Gate loss other than zero_one |
invalid_name | 422 | A profile name with characters outside letters, digits, ., _, - |
payload_too_large | 413 (422 for too many examples in one call) | Over a size limit |
unsupported_media_type | 415 | OTLP ingest with a content type other than protobuf or JSON |
route_not_found, method_not_allowed | 404, 405 | No such route or method |
Idempotency, rate limits, availability
| Code | Status | Meaning |
|---|---|---|
invalid_idempotency_key | 422 | Not 1 to 255 printable ASCII characters |
idempotency_key_reused | 422 | The key was used for a different request |
idempotency_in_flight | 409 | The original request with this key is still running; retry after Retry-After |
rate_limited | 429 | The API key’s request rate |
concurrency_limited | 429 | Too many concurrent writes for the organization or key |
service_overloaded | 529 | The service is saturated |
service_unavailable, accounts_unavailable | 503 | A store is unavailable; retry later |
gateway_timeout | 504 | The hosted proxy waited 300 s |
upstream_unavailable | 502 | The hosted proxy could not reach the service |
internal_error | 500 | An unexpected error; quote the request_id |
Providers and connections
| Code | Status | Meaning |
|---|---|---|
connection_required | 422 | No connection for this provider: add one (Provider connections) |
connection_not_found | 422 | No connection with that name |
connection_unverified | 422 | A vLLM, SGLang, OpenAI-compatible or Azure connection has not passed Test |
connection_mode_mismatch | 422 | provider: "vertex" needs a Gemini connection in Vertex mode |
egress_denied | 422 | The endpoint is not allowed, or base_url does not match the connection’s origin |
provider_auth_failed | 422 | The provider rejected your credential (field: backend.connection) |
provider_model_not_found | 422 | The provider does not know the model or deployment (field: backend.model) |
provider_bad_request | 422 | The provider rejected the request |
context_too_long | 422 | The context exceeds the model’s window |
provider_quota_exhausted | 402 | Your provider account is out of quota or billing |
provider_rate_limited | 429 | Your provider rate-limited your key; its Retry-After is passed through |
provider_overloaded | 529 | Your provider is overloaded |
provider_unavailable, provider_timeout | 502 | A transient provider failure |
backend_error | 502 | The backend could not produce evidence for the query |
access_level_unavailable | 502 | The pinned access level is beyond what this backend reaches; no model call was made |
Profiles, calibration, monitors, jobs
| Code | Status | Meaning |
|---|---|---|
profile_not_found | 404 (422 inside evaluate) | No profile with this name; create it first |
profile_exists | 409 | The name exists with a different configuration; details.differences lists the fields. Use a new name |
query_mismatch | 422 | The profile is bound to a different query; use one profile per query |
profile_not_bound | 422 | The route needs a bound profile (outcomes, calibrate, label-with-judge); evaluate against it first |
profile_empty | 422 | No eligible labelled examples to calibrate with |
profile_full, profile_limit | 422 | 100,000 examples per profile, 1,000 profiles per organization |
profile_busy | 409 | Another operation holds the profile; retry shortly |
contexts_required | 422 | A zero-retention profile cannot do this without the contexts it discarded |
insufficient_calibration | 424 | The profile is not calibrated yet (audits and other non-evaluate routes) |
audit_too_large | 422 | Send "async": true to run the audit as a job |
audit_not_supported | 422 | Belief profiles are not audited; audit a Gate or Set on the same question |
monitor_not_found, monitor_limit | 404, 422 | Unknown monitor; 20 monitors per profile |
job_not_found | 404 | Unknown job |
Telemetry
| Code | Status | Meaning |
|---|---|---|
invalid_filter | 422 | A malformed search; details.errors lists each term |
invalid_cursor, invalid_time_range | 422 | A bad cursor, from or to |
request_not_found | 404 | Unknown request id |
otlp_decode_failed | 422 | The OTLP body does not decode |
The dashboard’s own routes add codes for connections (connection_exists),
alert channels, OTLP destinations, organizations and single sign-on
(sso_*); they appear in the dashboard, not to API keys.
Retries
429, 502 and 529, connection errors and timeouts are retried
automatically; everything else (authentication, validation, insufficient
calibration) is returned immediately, because retrying cannot change the
outcome. Every POST carries an Idempotency-Key header, one value per
logical call reused across its retries, so a retried write (for example
add_examples after a 502 that the server had already committed) is
applied once.
from cli_sdk import CLIClient, RetryConfig
from cli_sdk.client import NO_RETRY
client = CLIClient(retry=RetryConfig(max_attempts=5, base_delay=0.5, max_delay=8.0))
no_retries = CLIClient(retry=NO_RETRY) # RetryConfig(max_attempts=1)RetryConfig field | Default | Meaning |
|---|---|---|
max_attempts | 4 | Total attempts, including the first. Must be at least 1. |
base_delay | 0.5 | Seconds; the backoff ceiling for the first retry. |
max_delay | 8.0 | Seconds; cap on a backoff wait. |
max_retry_after | 60.0 | Seconds; the longest server retry-after the client waits for. A longer one stops retrying and raises (RateLimitError carries .retry_after). |
retry_connection_errors | True | Retry connection errors and timeouts; after the last attempt they raise APIConnectionError. |
retry_statuses | frozenset({429, 502, 529}) | Statuses that trigger a retry. |
Before retry (the wait after failed attempt ), the client sleeps:
- the server’s
retry-aftervalue in full, if it is numeric (and at mostmax_retry_after); otherwise - a uniform random time in (full-jitter exponential backoff).
When the last attempt still fails, the matching exception is raised
(RateLimitError for 429, BackendError for 502 and 529,
APIConnectionError for a connection error or timeout).
What to do with the codes the SDK does not retry:
| Situation | Action |
|---|---|
402 provider_quota_exhausted | Fix billing or quota on the provider account; retrying will not help |
409 idempotency_in_flight, 409 profile_busy | Wait the Retry-After and retry; add 409 to retry_statuses if your workload hits it often |
504 gateway_timeout | The work may still be finishing. Over HTTP, resending the same Idempotency-Key returns the stored result once it completes (the SDK uses a new key per call). Better, move long work to a job ("async": true for audits, smaller example batches) |
422 provider_auth_failed, connection_required, connection_unverified | Fix the connection in the dashboard |
422 query_mismatch, 409 profile_exists | Use a new profile name for the new query or configuration |
424 on a non-evaluate route | Calibrate the profile first (evaluate binds it) |
A few consequences worth knowing:
- Size
timeoutfor L0 backends, which make one model call per sample, and for synchronous audits:CLIClient(timeout=300). A client timeout is retried with the same key; while the first attempt is still running, the service answers the retry with409 idempotency_in_flight. - With a
CustomBackend, evidence is computed once, before the first attempt; retries resend the same evidence and do not call your model again. RetryConfigis a frozen dataclass. Share one instance across clients.
Request ids
Every response carries a request id (result.request_id, from the
x-request-id header; every JSON body also has "request_id"). Log it
next to any decision you act on: it opens the request’s full trace in the
dashboard and in GET /v1/requests/{id}, and together with the guarantee
card’s calibration_profile, profile_version and last_audited it
traces a decision back to the exact calibration that backed it. Quote it
when you report a problem.