Skip to navigation

Errors

View as Markdown

OpenModels uses OpenAI-compatible JSON errors through the Alephant gateway. Use the HTTP status code for broad handling and use error.code when the response includes a stable machine-readable code.

Error response format

OpenModels account, billing, and usage errors can include request_id and retryable fields:

{
"error": {
"message": "KeyMarket account has insufficient available balance",
"type": "key_market_error",
"param": null,
"code": "key_market_insufficient_balance",
"request_id": "km_0123456789abcdef",
"retryable": false
}
}

Some gateway or upstream errors use the standard OpenAI-compatible shape and may not include request_id or retryable:

{
"error": {
"message": "Invalid credentials",
"type": "invalid_request_error",
"param": null,
"code": "invalid_api_key"
}
}

Fields:

FieldDescription
error.messageHuman-readable explanation of the failure
error.typeError family, such as key_market_error, invalid_request_error, or server_error
error.paramRequest parameter related to the error, or null
error.codeMachine-readable error code when available
error.request_idRequest identifier for debugging and support when available
error.retryableWhether the gateway considers the failure safe to retry when available

For routed model requests, if you send an x-request-id header, the gateway can echo it in error.request_id. Otherwise, the gateway may generate a km_... request id. Early authentication, account, or upstream errors may not include a request id, so keep your own request id in client logs.

Error codes

Handle these responses today:

HTTP statusError codeMeaningWhat to do
401invalid_api_keyThe API key is missing, malformed, invalid, revoked, or no longer active.Check the Authorization: Bearer ... header, create or rotate the API key, and retry with a valid key.
402key_market_insufficient_balanceThe account does not have enough available credits to reserve or complete the request.Add credits, confirm the balance is active, then retry.
503key_market_usage_unavailableUsage or spend data is temporarily unavailable, so the gateway cannot safely verify limits.Retry later with backoff. Do not assume usage was counted as zero.
400none or generic gateway codeThe request is invalid, the model is unsupported, or the model route is not available.Check the request body, endpoint, and model ID against the Models page.
502, 503, 504none, upstream body, or gateway codeThe upstream provider or route failed, was unavailable, or timed out.Retry with backoff when the status is transient, or switch to another supported model.

OpenModels-specific Key Market codes may appear in gateway responses. When present, handle them as follows:

HTTP statusError codeMeaningWhat to do
401key_market_key_invalidThe OpenModels API key is missing, malformed, invalid, revoked, or no longer active.Check the Authorization: Bearer ... header, create or rotate the API key, and retry with a valid key.
402key_market_insufficient_balanceThe account does not have enough available credits to reserve or complete the request.Add credits, confirm the balance is active, then retry.
403key_market_spend_limit_exceededThe API key has reached its monthly spend limit.Increase the key’s monthly limit, use another active key, or wait for the monthly usage window to reset.
400key_market_model_not_availableThe requested model is not available through OpenModels.Check the Models page and send the request with a supported model ID.
400key_market_image_price_not_availableThe requested image model, size, quality, or image pricing combination is not available.Use a supported image pricing option or choose another model.
503key_market_no_upstream_availableThe model exists, but no upstream route is currently available.Retry later with backoff or switch to another supported model.
503key_market_usage_unavailableUsage or spend data is temporarily unavailable, so the gateway cannot safely verify limits.Retry later with backoff. Do not assume usage was counted as zero.
502key_market_upstream_not_supportedThe selected upstream does not support the requested endpoint or model.Check the model and endpoint combination, then switch model or endpoint.
502key_market_upstream_errorThe upstream provider returned an error or failed during the request.Retry only when error.retryable is true; otherwise inspect the request or switch models.
504key_market_upstream_timeoutThe upstream provider did not respond before the gateway timeout.Retry with exponential backoff, reduce request size, or switch to another model.

Retry guidance

Use error.retryable as the primary retry signal when it is present. If error.retryable is missing, fall back to the HTTP status code and your own idempotency rules.

Do not automatically retry these errors until the user or system changes something:

  • invalid_api_key
  • key_market_key_invalid
  • key_market_insufficient_balance
  • key_market_spend_limit_exceeded
  • key_market_model_not_available
  • key_market_image_price_not_available
  • key_market_upstream_not_supported

These errors may be transient. Retry them with backoff when error.retryable is true, or when your HTTP status and idempotency rules allow it:

  • key_market_no_upstream_available
  • key_market_usage_unavailable
  • key_market_upstream_error
  • key_market_upstream_timeout

HTTP 429, 502, 503, and 504 responses without a Key Market code may also be transient. For retries, use exponential backoff and a small maximum retry count. For production workloads, log your client request id, error.request_id when present, error.code, model ID, endpoint, and whether the request was streaming.

Common fixes

ErrorCommon fix
Invalid keyCreate a new API key, update the environment variable, and make sure the request uses Authorization: Bearer <OM_API_KEY>.
Insufficient balanceAdd credits in the OpenModels dashboard. Credits are shared across supported models and API keys.
Spend limit exceededIncrease the monthly spend limit for that key or route traffic through another active key.
Model not availableCopy a model ID from the Models page and update the model field.
No upstream availableRetry later or choose another model with active availability.
Upstream timeoutReduce prompt size, lower max_tokens, or retry with backoff.

Example handling

async function callOpenModels(request) {
const response = await fetch("https://api.getopenmodels.com/v1/chat/completions", request);
if (response.ok) {
return response.json();
}
const body = await response.json().catch(() => null);
const error = body?.error;
const code = error?.code;
if (response.status === 401 || code === "invalid_api_key" || code === "key_market_key_invalid") {
throw new Error("OpenModels API key is invalid. Create or rotate the key before retrying.");
}
if (code === "key_market_insufficient_balance") {
throw new Error("OpenModels credits are insufficient. Add credits before retrying.");
}
if (code === "key_market_spend_limit_exceeded") {
throw new Error("OpenModels monthly spend limit has been reached for this key.");
}
const retryable =
error?.retryable === true || [429, 502, 503, 504].includes(response.status);
if (retryable) {
throw new Error(`Retryable OpenModels error: ${code || response.status}`);
}
throw new Error(error?.message || `OpenModels request failed with ${response.status}`);
}

Support

When reporting an error, include:

  • Your client request id
  • error.request_id, if present
  • error.code, if present
  • HTTP status
  • Model ID
  • Endpoint
  • Whether the request was streaming
  • Timestamp