Browse all docs & guides
On this page
REFERENCE

Errors & Recovery

OpenGen returns structured JSON error envelopes with Cache-Control no-store on every non-2xx response, exposes RateLimit, RateLimit-Policy, and Retry-After headers for backpressure, and attaches typed structuredError objects to jobs. On network timeouts or submission-unknown states, recover read-only via GET /v1/generations/lookup or MCP job_get without blind paid retries.

Reviewed 2026-12-02
AGENT PROMPT · PASTE INTO YOUR AGENT OR AUTO-READ
Handle OpenGen API errors and timeouts safely using https://opengen.dev/docs/errors:
1. Never invent a new Idempotency-Key after a timeout, 5xx, or dropped connection on POST https://opengen.dev/v1/generations — call read-only GET https://opengen.dev/v1/generations/lookup?idempotencyKey=... or MCP job_get({ idempotencyKey }) first.
2. Never treat a 404 lookup on an in-flight request as proof of rejection, and NEVER submit a replacement job when status is submission-unknown or structuredError.recovery is "operator".
3. Inspect RateLimit, RateLimit-Policy, and Retry-After headers on 429 responses before backing off; only retry read/status polls automatically, or replay POST with the exact persisted Idempotency-Key and byte-identical payload.
4. On 400 invalid_generation, read error.issues[] and inspect GET https://opengen.dev/v1/models/{provider}/{model} (or get_model) to correct unsupported arguments before asking the user to re-confirm budget.
View raw .md ↗

Standard error envelopes

Every HTTP error response is served with Cache-Control: no-store and returns a consistent JSON object. Schema validation failures on canonical generation requests (400 invalid_generation) also attach an issues[] array pinpointing each offending field:

JSON
{
  "error": {
    "code": "invalid_generation",
    "message": "input.duration: Duration is outside this model capability.",
    "issues": [
      {
        "code": "unsupported_duration",
        "field": "input.duration",
        "message": "Duration is outside this model capability.",
        "limit": "4–12",
        "received": 30
      }
    ]
  }
}

Over Streamable HTTP MCP (/mcp and /mcp/readonly), tool failures set isError: true and carry the same { "error": { "code", "message" } } object in structuredContent and text content.

HTTP status codes and API error codes

StatusVerified error.code ValuesCause & Recommended Action
400invalid_generation, invalid_input, idempotency_key_required, idempotency_required, invalid_prefer_header, invalid_status_wait, invalid_upload, invalid_asset_query, invalid_activity_query, invalid_input_url, invalid_input_media, invalid_base64Request failed schema, header, or container validation. Inspect error.issues[] or GET /v1/models/{provider}/{model} and fix the request before retrying
401unauthorizedMissing, expired, malformed, or revoked Bearer token, session cookie, or audience-mismatched OAuth token. Refresh OAuth token or rotate API key
402insufficient_balance, budget_exceededWorkspace availableMicros is below the required reservation, or the route estimate exceeds maxCostMicros. Top up at /billing or adjust maxCostMicros with explicit user approval
403insufficient_scope, policy_denied, origin_deniedToken lacks read/generate scope, request violates a governance routing policy or spend cap, or a cookie-bearing request failed CSRF Origin validation
404not_found, collection_not_found, generation_schema_not_found, asset_not_found, workspace_not_foundOwned job, asset, model, or collection does not exist in this workspace. Note: 404 on /v1/generations/lookup is not proof that a still-in-flight submission failed
405method_not_allowedUnsupported HTTP verb (for example GET /mcp returns 405 with Allow: POST, OPTIONS)
406Not Acceptable (JSON-RPC -32000)MCP caller sent an Accept header explicitly rejecting application/json (such as application/json;q=0, text/event-stream)
408input_download_timeoutPublic HTTPS URL import exceeded the 30-second fetch deadline
409idempotency_conflict, billing_hold, asset_not_ready, asset_write_in_progress, job_not_terminal, output_purge_pending_settlement, output_delivery_in_progress, workspace_changedState conflict: reusing an Idempotency-Key with a modified body (including webhookUrl/webhookEvents), active billing hold, unready asset, or attempting to purge outputs before terminal settlement
410_(expired /media capability)_Signed first-party /media/v1.... output link expired or job outputs were purged. Call GET /v1/generations/{id} (or MCP job_get) to mint a fresh link while retained
413upload_too_largeDirect upload exceeded 4 MiB (multipart/form-data), 3 MiB (REST JSON base64), or 64 KiB (MCP upload_asset base64). Switch to presigned single-PUT (<= 100 MiB)
415invalid_uploadMissing multipart/form-data boundary or unsupported Content-Type
422no_executable_route, invalid_generation_input, unsupported_operation, execution_scope_deniedValid canonical request, but no candidate route matches your routing constraints, BYOK credentials, or server execution scope. Inspect POST /v1/pricing/estimate candidates[].reason
429rate_limited, slow_downRate limit or dispatch backpressure exceeded. Honor Retry-After and RateLimit / RateLimit-Policy headers before retrying reads or idempotent lookups
503database_not_configured, storage_not_configured, authentication_not_configured, vault_not_configured, webhook_signing_not_configuredOptional installation subsystem is unconfigured on a self-hosted gateway

Job structuredError taxonomy

When an admitted generation encounters an execution, policy, or delivery issue, GET /v1/generations/{id} and GET /v1/generations/{id}/status populate structuredError ({ code, category, message, retryable, recovery, field?, providerCode? }).

structuredError.codeCategoryretryablerecoveryMeaning
invalid_inputinvalid_inputfalseedit_requestRequest contained an invalid or unsupported parameter
provider_invalid_inputinvalid_inputfalseedit_requestUpstream provider rejected an input parameter
policy_rejectedpolicyfalseedit_requestRejected by applicable governance or safety policy
provider_policy_rejectedpolicyfalseedit_requestUpstream provider rejected the request under its content policy
submission_rejectedunknownfalseedit_requestUpstream provider explicitly rejected submission before execution
submission_unknownunknownfalseoperatorUpstream acceptance could not be confirmed; hold stays active pending reconciliation
provider_outcome_unknownunknownfalseoperatorUpstream execution outcome is unresolved; keep job for reconciliation
provider_failedtechnicalfalseoperatorUpstream execution failed; settlement may require reconciliation
status_unavailabletechnicaltruesame_jobUpstream status check temporarily unavailable; keep polling the same job
capacity_fulltechnicaltruesame_jobDispatch pool at capacity; existing queued job waits for a slot
input_preparation_unavailabletechnicaltruesame_jobAccepted input package not yet ready for dispatch; keep existing job
delivery_unavailabletechnicaltruesame_jobOutput capture temporarily unavailable; resume reading the same job
delivery_failedtechnicalfalseoperatorPrivate output delivery failed; inspect with operator support, do not resubmit
delivery_expiredtechnicalfalseoperatorUpstream output expired before capture; inspect with operator support
credentials_unavailabletechnicalfalseoperatorOriginal provider connection changed or unavailable for this job
start_deadline_exceededtechnicalfalsenoneLocal queueStartDeadlineAt passed before upstream submission

Rate limiting & backpressure headers

REST responses under /v1/* emit standard IETF draft **RateLimit and RateLimit-Policy** headers so automated clients and agents can self-throttle before hitting 429:

  • RateLimit-Policy: declares the active quota policy and window duration in seconds (for example "public-read";q=300;w=60 on public catalog reads, "public-estimate";q=120;w=60 on POST /v1/pricing/estimate, "v1-read";q=120;w=60 on authenticated workspace reads, and "v1-write";q=60;w=60 on authenticated mutations).
  • RateLimit: reports the active policy's remaining quota and reset countdown in seconds (for example "public-read";r=299;t=60 or "v1-write";r=59;t=60).
  • Retry-After: included on 429 responses with an integer delay in seconds (for example Retry-After: 3600 on OAuth slow_down, or bounded seconds on API rate limits).

When you receive 429, wait at least Retry-After seconds (adding small jitter) before retrying read/poll calls. Never loop tightly against GET /v1/generations/{id} — prefer GET /v1/generations/{id}/events (SSE), GET /v1/generations/{id}/status?waitMs=25000, or webhooks.

Safe recovery playbook (timeouts & submission-unknown)

Follow these strict rules whenever a network error or timeout interrupts a generation:

  1. Persist before submitting: Store your generated Idempotency-Key and exact canonical JSON body before calling POST /v1/generations.
  2. Recover read-only first: If the client disconnects before receiving the 202/200 response, call GET /v1/generations/lookup?idempotencyKey=<key> (or MCP job_get({ idempotencyKey }) / opengen job recover --idempotency-key <key>).
  3. Never mint a replacement key blindly: If lookup finds the job, persist its id and resume polling. If the job is in status: "submission-unknown", reserved funds remain held until reconciliation confirms whether the provider accepted the task — do not submit a second job.
  4. Never mutate a replayed payload: Re-sending the same Idempotency-Key with a different prompt, model, routing, maxCostMicros, webhookUrl, or webhookEvents fails with 409 idempotency_conflict.
# Read-only lost-submit recovery using the exact persisted Idempotency-Key
curl --fail-with-body \
  "$OPENGEN_API_URL/v1/generations/lookup?idempotencyKey=$(printf '%s' "$OPENGEN_IDEMPOTENCY_KEY" | jq -sRr @uri)" \
  -H "Authorization: Bearer $OPENGEN_API_KEY"