On this page
API REFERENCE/docs/en/api/errors/

Error Codes, Streaming, Caching & Billing — Twelver API

OpenAI-compatible error envelopes (400, 401, 402, 404, 429, 502/503), in-band SSE stream errors, token reservation & settlement, and prompt caching.

/llms-full.txt

HTTP Status Codes & OpenAI Error Envelopes#

All pre-stream errors return the standard OpenAI { error: { message, type, code, param } } envelope so official SDKs distinguish quota exhaustion (402), invalid parameters (400/404), and retryable upstream faults (429/502/503).

HTTPerror.typeerror.codeRetryableWhen it happensClient action
400invalid_request_errorinvalid_requestNoInvalid JSON body, unsupported reasoning_effort value, or custom temperature without reasoning_effort="none" on Responses-bridged series.Fix request parameters before retrying; hold is not charged.
400invalid_request_errorcontent_filterNoUpstream provider rejected the prompt via safety inspection (e.g. data_inspection_failed).Rephrase input; token reservation is refunded in full.
401invalid_request_errorunauthorizedNoMissing Authorization: Bearer sk-… header, revoked key, or config-id owned by a different user.Verify the Authorization header and confirm the API key and config-id belong to the same account.
402insufficient_quotainsufficient_quotaNoToken balance is below the pre-request estimate.Do not retry with backoff; top up at the /upgrade URL returned in error.message.
404invalid_request_errormodel_not_foundNoUnknown model string (such as a raw vendor checkpoint instead of a series key).Call GET/:configId/v1/models and pass a public series key (auto, qwen, qwen-max, zai, grok, deepseek, gpt, etc.).
429upstream_errorrate_limit_exceededYesTransient upstream provider rate limit.Retry with exponential backoff; failed pre-stream calls refund their hold.
502upstream_errorupstream_unavailableYesUpstream model provider gateway failure before output started.Retry after a short delay; token hold is refunded.
503upstream_errorupstream_unavailableYesUpstream provider temporarily overloaded.Retry with backoff or fall back to another series.
Example 402 insufficient_quota responsejson
{
  "error": {
    "message": "Twelver: out of tokens. Top up at https://twelver.app/upgrade to keep using this key.",
    "type": "insufficient_quota",
    "code": "insufficient_quota",
    "param": null
  }
}

In-Band SSE Errors, Token Settlement & Prompt Caching#

New accounts start with 0.25M starter tokens; monthly plans on this domain: Basic: $13 (10.4M) · Pro: $20 (16M) · Premium: $49 (39.2M).

  • Reservation & settlement: billedText places a pre-flight hold sized from the message payload (including image token estimates) and settles against exact provider usage on completion. Any request rejected before streaming begins refunds the hold in full.
  • Mid-stream errors (stream: true): if an upstream failure occurs after HTTP 200 SSE headers are flushed, the proxy emits data: {"error":{...}} followed by data: [DONE]. Inspect parsed chunks for top-level error objects.
  • Prompt caching: tokens reported under prompt_tokens_details.cached_tokens automatically bill at each model’s discounted cache-hit rate (e.g. 5% of input on Qwen4-Max, 20% on Qwen3.7-Plus, 10% on DeepSeek V4). Keep system prompts and tool definitions byte-stable at the start of messages to maximize cache hits.

Frequently Asked Questions

Which HTTP error codes should my client retry automatically?

Retry only 429 (rate_limit_exceeded) and 502/503 (upstream_unavailable) with exponential backoff. Do not retry 400, 401, 402 (insufficient_quota), or 404 without fixing the request or topping up.

How are errors surfaced mid-stream when stream: true is enabled?

Once HTTP 200 SSE headers are flushed, mid-stream upstream faults arrive as an in-band event data: {"error": {...}} right before data: [DONE]. Always check parsed SSE chunks for an error object.

Are reserved tokens refunded on upstream failure, and how does prompt caching bill?

Any request rejected before streaming begins refunds the pre-flight hold in full, and completed calls settle to exact provider usage. Tokens reported in prompt_tokens_details.cached_tokens automatically bill at each series’ discounted cache rate.

Inspect raw Markdown (LLM / @Docs source)
# Error Codes, Streaming, Caching & Billing — Twelver API

> OpenAI-compatible error envelopes (400, 401, 402, 404, 429, 502/503), in-band SSE stream errors, token reservation & settlement, and prompt caching.

Canonical URL: https://twelver.app/docs/en/api/errors/

## HTTP Status Codes & OpenAI Error Envelopes

All pre-stream errors return the standard OpenAI { error: { message, type, code, param } } envelope so official SDKs distinguish quota exhaustion (402), invalid parameters (400/404), and retryable upstream faults (429/502/503).

| HTTP | error.type | error.code | Retryable | When it happens | Client action |
| --- | --- | --- | --- | --- | --- |
| 400 | invalid_request_error | invalid_request | No | Invalid JSON body, unsupported reasoning_effort value, or custom temperature without reasoning_effort="none" on Responses-bridged series. | Fix request parameters before retrying; hold is not charged. |
| 400 | invalid_request_error | content_filter | No | Upstream provider rejected the prompt via safety inspection (e.g. data_inspection_failed). | Rephrase input; token reservation is refunded in full. |
| 401 | invalid_request_error | unauthorized | No | Missing Authorization: Bearer sk-… header, revoked key, or config-id owned by a different user. | Verify the Authorization header and confirm the API key and config-id belong to the same account. |
| 402 | insufficient_quota | insufficient_quota | No | Token balance is below the pre-request estimate. | Do not retry with backoff; top up at the /upgrade URL returned in error.message. |
| 404 | invalid_request_error | model_not_found | No | Unknown model string (such as a raw vendor checkpoint instead of a series key). | Call GET /:configId/v1/models and pass a public series key (auto, qwen, qwen-max, zai, grok, deepseek, gpt, etc.). |
| 429 | upstream_error | rate_limit_exceeded | Yes | Transient upstream provider rate limit. | Retry with exponential backoff; failed pre-stream calls refund their hold. |
| 502 | upstream_error | upstream_unavailable | Yes | Upstream model provider gateway failure before output started. | Retry after a short delay; token hold is refunded. |
| 503 | upstream_error | upstream_unavailable | Yes | Upstream provider temporarily overloaded. | Retry with backoff or fall back to another series. |

**Example 402 insufficient_quota response**

```json
{
  "error": {
    "message": "Twelver: out of tokens. Top up at https://twelver.app/upgrade to keep using this key.",
    "type": "insufficient_quota",
    "code": "insufficient_quota",
    "param": null
  }
}
```

## In-Band SSE Errors, Token Settlement & Prompt Caching

New accounts start with 0.25M starter tokens; monthly plans on this domain: Basic: $13 (10.4M) · Pro: $20 (16M) · Premium: $49 (39.2M).

- Reservation & settlement: billedText places a pre-flight hold sized from the message payload (including image token estimates) and settles against exact provider usage on completion. Any request rejected before streaming begins refunds the hold in full.
- Mid-stream errors (stream: true): if an upstream failure occurs after HTTP 200 SSE headers are flushed, the proxy emits data: {"error":{...}} followed by data: [DONE]. Inspect parsed chunks for top-level error objects.
- Prompt caching: tokens reported under prompt_tokens_details.cached_tokens automatically bill at each model’s discounted cache-hit rate (e.g. 5% of input on Qwen4-Max, 20% on Qwen3.7-Plus, 10% on DeepSeek V4). Keep system prompts and tool definitions byte-stable at the start of messages to maximize cache hits.

## Frequently Asked Questions

### Which HTTP error codes should my client retry automatically?

Retry only 429 (rate_limit_exceeded) and 502/503 (upstream_unavailable) with exponential backoff. Do not retry 400, 401, 402 (insufficient_quota), or 404 without fixing the request or topping up.

### How are errors surfaced mid-stream when stream: true is enabled?

Once HTTP 200 SSE headers are flushed, mid-stream upstream faults arrive as an in-band event data: {"error": {...}} right before data: [DONE]. Always check parsed SSE chunks for an error object.

### Are reserved tokens refunded on upstream failure, and how does prompt caching bill?

Any request rejected before streaming begins refunds the pre-flight hold in full, and completed calls settle to exact provider usage. Tokens reported in prompt_tokens_details.cached_tokens automatically bill at each series’ discounted cache rate.