> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nano-gpt.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Provider Selection

> Choose the upstream provider for supported open-source models

# Provider Selection

Provider selection chooses the upstream provider for a supported model. It does not change the model ID. For example, to use Kimi K2.6 through Inceptron, keep the model as `moonshotai/kimi-k2.6`, or another supported alias for that model, and send the provider separately with `X-Provider`.

Provider selection is optional; if you do nothing, the platform picks the provider. `X-Provider`, a body `provider` string, or a body `provider` object can select or constrain providers for a request. Explicit provider selection is always pay-as-you-go and is charged at the selected provider's price, including provider-selection markup. For subscription users, sending an explicit provider selection bypasses subscription coverage for that request.

`X-Billing-Mode: paygo` is only needed when forcing pay-as-you-go billing without an explicit provider, or when saved provider preferences should apply to subscription-included traffic. See [Pay-As-You-Go Billing Override](https://docs.nano-gpt.com/api-reference/miscellaneous/billing-override.md).

This page intentionally documents only public provider IDs returned by the provider-discovery endpoints. Internal routing/provider names are never part of the public API contract.

## Choose Your Routing Goal

| Goal | Use | What to expect |
| - | - | - |
| Lowest estimated cost for each request | `provider.sort: "price"` | Recalculates the ranking each request; may switch providers and reduce cache reuse. |
| Stay with one provider | `provider.only: ["provider-id"]` and `allow_fallbacks: false` | Fails if that provider cannot serve the request. |
| Reuse a prompt cache when possible | `caching: true` | Prefers a usable provider from previous matching requests, with fallback allowed by default. |

See [examples and precedence](#price-caps-and-cache-reuse) before combining these controls. Cache contents are provider-local; changing providers does not transfer a warm cache.

## When Provider Selection Applies

* Provider selection only applies when a model reports `supportsProviderSelection: true`.
* Use `GET /api/models/:canonicalId/providers` to discover eligible models and provider IDs.
* `supportsProviderSelection` is exposed on the model-specific provider endpoint. Do not rely on `/api/v1/models` or `/api/v1/models?detailed=true` to determine provider-selection support.
* If a model does not support provider selection, it runs on a fixed route, and ranking preferences such as a soft `order` or `sort` have no effect. Hard limits still apply: `only`, `ignore` and `order` with `allow_fallbacks: false`. If the route can't meet them, the request returns `no_allowed_provider_for_model`.
* You cannot currently force a provider and have that same request count as subscription-included usage.

## Google Vertex and Google AI Studio

Gemini models can be served by two separate Google services, and each is its own provider:

| Provider | ID | Also accepted | Zero data retention |
| - | - | - | - |
| Google Vertex | `google-vertex` | `google` | Only on routes marked zero data retention |
| Google AI Studio | `google-ai-studio` | `googlenative` | No |

* `google` means Google Vertex in `provider.only`, `provider.order` and `X-Provider`. Nobody is moved to AI Studio without choosing it.
* `provider.ignore: ["google"]` removes both services. Use `google-vertex` or `google-ai-studio` to remove just one.
* Vertex no longer serves the Gemini 2.5 text models. A request that allows only Vertex for one of them gets an error naming Google AI Studio instead of being moved there.

## Discover Providers and Pricing

Use this endpoint to list available providers and the pricing you will pay when selecting one.

```
GET /api/models/:canonicalId/providers
```

Provider rows may also include `distillationPolicy`, which indicates whether that specific hosted provider route is allowed for output-based model training or distillation under NanoGPT's recorded provider-terms and model-license rules. See [Distillation Policy](https://docs.nano-gpt.com/api-reference/miscellaneous/distillation-policy.md).

This endpoint is not under `/api/v1`. If your base URL is `https://api.nano-gpt.com/api/v1`, do not append this path to that base URL. Use:

```http theme={null}
GET https://api.nano-gpt.com/api/models/moonshotai%2Fkimi-k2.6/providers
```

URL-encode `/` in the model ID as `%2F`, as shown above. The unencoded slash is treated as a path separator:

```http theme={null}
GET https://api.nano-gpt.com/api/models/moonshotai/kimi-k2.6/providers
```

Here `:canonicalId` means the model ID or one of its supported aliases.

Example response:

```json theme={null}
{
  "canonicalId": "moonshotai/kimi-k2.6",
  "displayName": "Kimi K2.6",
  "supportsProviderSelection": true,
  "defaultPrice": {
    "inputPer1kTokens": 0.0005,
    "outputPer1kTokens": 0.0026
  },
  "providers": [
    {
      "provider": "moonshot",
      "available": true
    },
    {
      "provider": "inceptron",
      "available": true,
      "maxInputTokens": 262144,
      "maxOutputTokens": 65536,
      "quantization": "int4",
      "features": {
        "toolCalling": true,
        "structuredOutput": true,
        "imageInput": true,
        "promptCaching": true
      },
      "distillationPolicy": {
        "status": "disallowed",
        "label": "Provider terms restrict distillation",
        "basis": "provider-output-use-restriction",
        "sourceUrl": "https://www.inceptron.io/termsofservice",
        "note": "Inceptron terms allow lawful output use but restrict using outputs to build competing foundation models."
      }
    },
    {
      "provider": "deepinfra",
      "available": true
    },
    {
      "provider": "parasail",
      "available": true
    }
  ]
}
```

Notes:

* `defaultPrice` is used when you do not select a provider.
* `providers[].pricing` includes provider-selection markup. Fields ending in `Per1kTokens` are **USD per 1,000 tokens**; multiply by 1,000 to compare with `max_price`, which is **USD per 1 million tokens**.
* When present, `providers[].effectivePricing.effective_price` describes the effective rates used for routing, including current discounts and markup. Prices and availability can change between discovery and the request.
* Use the exact value from `providers[].provider` in the `X-Provider` header.
* Provider-specific `distillationPolicy` can differ from the model-level policy. Explicit provider restrictions override model-level allowances.
* If a model is unsupported, the response includes `supportsProviderSelection: false`.

### Provider row fields

Optional fields are omitted when NanoGPT has no reliable value for that provider.

| Field | Meaning |
| - | - |
| `maxInputTokens` | Context window on this provider, in tokens. |
| `maxOutputTokens` | Largest output budget this provider accepts. A request whose `max_tokens` is larger skips this provider; see [output limits](#output-limits). |
| `quantization` | Weight precision served by this provider, such as `fp8` or `bf16`. |
| `tps` | Recent average output speed, in tokens per second. |
| `ttftMs` | Recent average time to first token, in milliseconds. |
| `features` | What a request can use through this provider: `toolCalling`, `structuredOutput`, `imageInput` and `promptCaching` booleans, `reasoningEfforts` (accepted `reasoning_effort` levels), and `reasoningAlwaysOn` (thinking cannot be turned off). A feature the model does not support is omitted. |
| `uptime` | Recent success rate of requests on this model through this provider. `hourly` has one value per hour, oldest first, covering `windowHours` hours that end with the hour starting at `lastHourStart`. Each value is the percentage of attempts that succeeded, or `null` when the hour had too few requests to rate. `uptimePct` covers the whole window and is omitted when there were too few requests. Client errors, cancellations and requests NanoGPT stopped before contacting the provider do not count as failures. |
| `verification` | NanoGPT's own checks of what this provider serves, for the most-used models that can be pinned to at least three providers. At random times NanoGPT sends every provider of the model the same text and compares the prompt token counts they report. `tokenizer.status` is `passed` (the latest check matched), `failed` (two or more checks in a row counted differently, which usually means a different model), `rechecking` (the latest check did not match and is being repeated) or `unchecked` (no check with a result in the last `windowDays` days). `checks` and `matches` count the checks with a result in that window, and `lastCheckedAt` is the latest one. An unavailable provider keeps the results from when it was available, over 30 days. Omitted for models NanoGPT does not check. |

## Per-Request Provider Override

For a single request, send the provider ID in the `X-Provider` header.

```bash theme={null}
curl https://api.nano-gpt.com/api/v1/chat/completions \
  -H "Authorization: Bearer $NANOGPT_API_KEY" \
  -H "Content-Type: application/json" \
  -H "X-Provider: inceptron" \
  -d '{
    "model": "kimi-k2.6",
    "messages": [
      { "role": "user", "content": "Hello" }
    ]
  }'
```

Notes:

* `X-Provider` is case-insensitive (`x-provider` also works).
* The provider ID must be one of the values returned by the providers endpoint.
* The body `provider` field also accepts the same provider ID as a string on `POST /api/v1/chat/completions`, `POST /api/v1/completions`, and `POST /api/talk-to-gpt`.
* Recommended: use `X-Provider` or body `provider` for explicit provider overrides. The API also accepts a trailing provider suffix for user-selectable providers, such as `model-id:cerebras`, but request fields are clearer and easier to validate against provider-discovery responses.
* To avoid Moonshot for Kimi K2.6, select any available non-Moonshot provider ID returned by the provider-discovery endpoint, such as `inceptron`, `deepinfra` or `parasail`, when listed as available.
* If the request would otherwise be subscription-covered, explicit provider selection still bypasses subscription coverage and bills the request as pay-as-you-go. You do not need to also send `billing_mode: "paygo"` or `X-Billing-Mode: paygo`.
* If **Enable paid models on API** is off and the request doesn't force pay-as-you-go with `billing_mode: "paygo"` or `X-Billing-Mode: paygo`, a provider pick returns an error and nothing is charged. `X-Provider` or a `provider` string returns `403 provider_selected`. `provider.only`, `provider.ignore` or `provider.allow_fallbacks: false` returns `400 provider_selection_not_available`. Other `provider` object fields, such as `order` and `sort`, are ignored for that subscription.

## Provider Routing Object

`POST /api/v1/chat/completions`, `POST /api/v1/responses`, `POST /api/v1/messages`, `POST /api/v1/completions`, and `POST /api/talk-to-gpt` also accept a structured `provider` object for per-request routing controls. See [Provider controls on Responses and Messages](#provider-controls-on-responses-and-messages) for how those two routes apply them.

```json theme={null}
{
  "model": "model-id",
  "provider": {
    "order": ["provider-a", "provider-b"],
    "only": ["provider-b"],
    "ignore": ["provider-c"],
    "sort": "throughput",
    "quantizations": ["fp8", "fp16"],
    "min_quantization": "fp8",
    "max_price": {
      "prompt": 0.5,
      "completion": 2
    },
    "allow_fallbacks": false,
    "require_parameters": true
  },
  "messages": [
    { "role": "user", "content": "Hello" }
  ]
}
```

Provider entries can use public NanoGPT provider IDs or accepted display names/aliases. Use `GET /api/models/:canonicalId/providers` to discover public provider IDs for a model. Do not rely on internal provider names that are not returned by public provider-discovery responses.

| Field | Type | Behavior |
| - | - | - |
| `provider.order` | string\[] | Soft preference order. NanoGPT tries these providers first when possible, but may route elsewhere. Unknown providers are ignored. With `provider.allow_fallbacks: false`, it's a hard list instead, enforced like `only`. |
| `provider.only` | string\[] | Hard provider pin. NanoGPT restricts routing to these providers and fails instead of routing outside the list. Unknown providers return `400` with `error.code: "provider_unknown_provider"`. |
| `provider.ignore` | string\[] | Excludes providers from routing. Unknown providers are ignored. |
| `provider.sort` | string or object | Routing preference. Supported values are `speed`, `throughput`, `latency`, `price`, `auto`, `none`, and `default`. `auto`, `none`, and `default` suppress stored/default routing preferences without requesting a sort. The object form is `{"by": "price", "partition": "model"}`. `partition` is `model` (the default) or `none`. See [Model fallbacks](#model-fallbacks) for how it applies to `models`. |
| `provider.preferred_max_latency` | number or object | Preferred maximum time to first token, in seconds. A number applies to p50. An object sets any of `p50`, `p75`, `p90`, `p99`. See [Performance cutoffs](#performance-cutoffs). |
| `provider.preferred_min_throughput` | number or object | Preferred minimum output speed, in tokens per second. A number applies to p50. An object sets any of `p50`, `p75`, `p90`, `p99`. See [Performance cutoffs](#performance-cutoffs). |
| `provider.quantizations` | string\[] | Hard allowlist of model weight quantization levels. Supported values are `int4`, `fp4`, `fp6`, `int8`, `fp8`, `fp16`, `bf16`, `fp32`, and `unknown`. |
| `provider.min_quantization` | string | Minimum precision floor. Supported values are `int4`, `fp4`, `fp6`, `int8`, `fp8`, `fp16`, `bf16`, and `fp32`. `unknown` is not allowed because it cannot be compared to a precision floor. |
| `provider.max_price` | object | Optional `prompt` and/or `completion` caps on provider input/output rates, including selection markup, in USD per 1 million tokens. See [price-cap limits](#price-cap-limits). |
| `provider.allow_fallbacks` | boolean | When `false`, disables cross-provider fallback for this request, and `provider.order` becomes the full list of allowed providers. |
| `provider.require_parameters` | boolean | When `true`, requires the selected provider to support the requested parameters on routes that support parameter-level capability checks. |

### Minimum quantization per API key

In an API key's settings, **Minimum quantization** sets an optional precision floor for text requests made with that key. The default is off. The supported levels are `int4`, `fp4`, `fp6`, `int8`, `fp8`, `fp16`, `bf16`, and `fp32`. Levels compare by bit width: `int4` and `fp4` share a floor, as do `int8` and `fp8`, and `fp16` and `bf16`.

A request can raise the key's floor with `provider.min_quantization`, but cannot lower it. A request's `provider.quantizations` allowlist must also satisfy the key's floor. Providers with unknown or unpublished quantization are excluded when a minimum is set, just as they are with a request-level minimum. A floor is a constraint on reported weight precision, not a guarantee of answer quality.

This can also exclude native text routes and requests using your own provider credentials when NanoGPT cannot verify the serving endpoint's precision.

The minimum applies alongside provider restrictions and other routing constraints. If no route qualifies, the request fails rather than using a provider below the key's minimum. A stricter floor can reduce availability and change which provider serves a request.

A key minimum is billed like a request-level quantization filter: text requests made with a key that has a minimum are billed pay-as-you-go with the usual provider-selection pricing, also with a subscription, and do not count toward included subscription usage. If your subscription has **Enable paid models on API** turned off, these requests are refused with `api_key_min_quantization_paygo`; turn that setting on, or remove the key's minimum to use your subscription. Per-request payments (x402 and L402) are not available with a key that has a minimum; these requests are paid from the account balance.

Examples:

```json theme={null}
{
  "provider": {
    "order": ["provider-a", "provider-b"]
  }
}
```

```json theme={null}
{
  "provider": {
    "only": ["provider-b"]
  }
}
```

```json theme={null}
{
  "provider": {
    "ignore": ["provider-c"]
  }
}
```

```json theme={null}
{
  "provider": {
    "quantizations": ["fp8"]
  }
}
```

```json theme={null}
{
  "provider": {
    "min_quantization": "fp8"
  }
}
```

```json theme={null}
{
  "provider": {
    "max_price": {
      "prompt": 0.5,
      "completion": 2
    }
  }
}
```

```json theme={null}
{
  "provider": {
    "require_parameters": true
  }
}
```

```json theme={null}
{
  "provider": {
    "order": ["provider-b"],
    "allow_fallbacks": false
  }
}
```

### Routing Semantics

* `order` is soft unless `allow_fallbacks` is `false`, which makes it a hard list. Use `only`, or `order` with `allow_fallbacks: false`, when the request must fail instead of using any provider outside the list.
* `only` is hard. It restricts routing to the listed providers and disables internal fallback outside the pinned set.
* `ignore` and `max_price` can resolve to a concrete provider. For direct provider routing, NanoGPT cannot represent "any provider except X" as a multi-provider pool. If filters like `ignore` or `max_price` are provided without `order` or `only`, NanoGPT resolves to one cheapest concrete provider that satisfies those filters. That is treated as explicit provider selection for billing and routing because the request changed the provider candidate set.
* If `max_price` is provided without `order` or an explicit `sort`, NanoGPT treats it as a request for price-aware routing among providers that satisfy the cap. `only` does not prevent this inference; an `order` does.
* The request's output budget (`max_tokens`, `max_completion_tokens` or `max_output_tokens`) is a hard routing constraint too; see [output limits](#output-limits).
* Quantization filters are hard routing constraints. If no available provider satisfies the requested quantization, provider list, price, fallback, caching, and parameter constraints, the request may fail with a provider-availability error.
* Per-request controls can change routing order, but saved hard restrictions still apply. Saved provider allowlists are intersected with request allowlists, exclusions remain excluded, and a saved fallback restriction is preserved. A request cannot broaden a saved allowlist by sending `order`, `only`, or `allow_fallbacks: true`.

### Quantization Filters

Use quantization filters when you need to avoid lower-precision provider routes for a model.

Choose a model with provider selection and published quantization metadata, such as `deepseek/deepseek-v4.1-flash-1017` in the examples below.

`provider.quantizations` is an exact allowlist. It must be a non-empty array:

```json theme={null}
{
  "model": "deepseek/deepseek-v4.1-flash-1017",
  "messages": [
    { "role": "user", "content": "Hello" }
  ],
  "provider": {
    "quantizations": ["fp8"]
  }
}
```

When an exact quantization filter is supplied, providers without matching known metadata are excluded. To allow providers whose quantization metadata is not known, include `unknown` explicitly:

```json theme={null}
{
  "provider": {
    "quantizations": ["fp8", "unknown"]
  }
}
```

`provider.min_quantization` sets a minimum precision floor:

```json theme={null}
{
  "model": "deepseek/deepseek-v4.1-flash-1017",
  "messages": [
    { "role": "user", "content": "Hello" }
  ],
  "provider": {
    "min_quantization": "fp8"
  }
}
```

Minimum quantization is ordered by bit width. For example, `min_quantization: "fp8"` allows `int8`, `fp8`, `fp16`, `bf16`, and `fp32`. Integer and floating-point formats with the same bit width are treated as equivalent for minimum filtering.

You may combine exact and minimum filters. NanoGPT uses the overlap:

```json theme={null}
{
  "provider": {
    "quantizations": ["fp8", "fp16"],
    "min_quantization": "fp8"
  }
}
```

If the filters do not overlap, the request is rejected as invalid. For example, `quantizations: ["fp4"]` with `min_quantization: "fp8"` is invalid because `fp4` is below the requested minimum.

Use NanoGPT's canonical quantization values in API requests. Provider metadata may use different internal labels, but request parameters must use the supported canonical values listed above.

### Performance cutoffs

`preferred_max_latency` and `preferred_min_throughput` move providers that miss a cutoff to the end of the ranking. They never exclude a provider and never make a request fail: if no provider meets the cutoffs, or NanoGPT has no recent data, the ranking stays as it was.

```json theme={null}
{
  "model": "model-id",
  "provider": {
    "sort": { "by": "price" },
    "preferred_max_latency": { "p90": 3 },
    "preferred_min_throughput": 50
  },
  "messages": [
    { "role": "user", "content": "Hello" }
  ]
}
```

This ranks providers by price, but tries those meeting both cutoffs first.

* **What a percentile means.** `p90: 3` on latency means 90% of recent requests got their first token within 3 seconds. `p90: 50` on throughput means 90% of recent requests ran at 50 tokens per second or faster. Setting several cutoffs requires all of them.
* **They need a ranking to reorder.** Cutoffs apply when `provider.sort`, or a `provider.max_price` that implies price routing, ranks several providers in the same `provider` object. A provider list or filter that resolves to a single provider has nothing to reorder.
* **On their own, they do nothing.** Sent without any other control that chooses among providers, cutoffs leave automatic routing and your bill as they were. Add `provider.sort` to use them, which bills the request as [explicit provider selection](#billing-and-markup).
* **They can't widen a restriction.** They only reorder the providers your request, API key, team policy, zero data retention and EU inference settings already allow.
* **How the numbers are measured.** They cover about the last hour of requests and are estimated from fixed ranges, not exact samples. A provider needs at least 10 recent requests on that model to count as meeting a cutoff, so one with less traffic is treated as missing it.

Latency here means time to first token. On `POST /api/v1/completions` and `POST /api/talk-to-gpt`, cutoffs are accepted and have no effect.

### Model fallbacks

Send `models` to list other models to try if one fails. It works on `POST /api/v1/chat/completions`, `POST /api/v1/responses` and `POST /api/v1/messages`. A list that comes down to one model, once duplicates are removed, is a normal request for that model. Everything below about trying several models applies to two or more different models.

```json theme={null}
{
  "model": "model-a",
  "models": ["model-b", "model-c"],
  "messages": [
    { "role": "user", "content": "Hello" }
  ]
}
```

* **Order.** `model` goes first, then `models`. You can leave out `model` and send only `models`. Duplicates are removed. `models` can list at most 4 IDs, and a request can try at most 4 models in total.
* **What moves to the next model.** A provider failure (a 5xx, or a provider's 429) and a prompt too long for that model, once NanoGPT's own routing for that model has run out of options.
* **What doesn't.** Authentication, permission, balance and invalid-request errors, moderation refusals, and NanoGPT's own rate limits, concurrency limits and budgets. The request ends with that error.
* **Streaming.** Fallback happens only before a response starts. Once NanoGPT returns a `200`, including a stream, the request stays on that model, even if the stream later fails.
* **The final error.** If every model fails, you get the last model's error.
* **What you see.** The response's `model` is the model that answered. `x_nanogpt_pricing.requestId` identifies that attempt, and it's the ID to use for a [request billing lookup](https://docs.nano-gpt.com/api-reference/endpoint/request-billing.md). `X-Request-ID` keeps the first attempt's ID. Which provider was used isn't revealed.
* **Billing.** Each attempt is billed as if you had requested that model alone, including whether a subscription covers it. The model that answered is billed at its own price. A failed attempt is free unless its provider charged for it, for example for output generated before the failure or an empty answer the provider billed. Such an attempt is billed under its own request ID, as it would be without `models`.
* **Limits and policies.** Each attempt passes the same checks as a request for that model alone, including your API key's model and provider allowlists, team policy, zero data retention, EU inference and balance. `provider` settings apply to every model in the list. A model those rules refuse ends the request with that error. On `/v1/responses` and `/v1/messages`, each attempt also counts toward your rate limits. Attempts run one at a time, and a failed attempt's concurrency slot is freed before the next one starts.
* **`provider.sort.partition`.** Models are always tried in order, which is what `model` means. `none`, which would rank across models, isn't supported with `models` and returns `400` `provider_sort_partition_not_supported`.

These can't be combined with two or more different models, and return `400`:

| Combination | `error.code` |
| - | - |
| No API key | `models_requires_api_key` |
| x402 payment | `models_x402_not_supported` |
| Auto Model in the list | `models_auto_model_not_supported` |
| A model preset (`presets/<name>`) in the list | `models_preset_not_supported` |
| A TEE model in the list | `models_tee_not_supported` |
| A Decisions model in the list | `models_decisions_not_supported` |
| Fusion | `models_fusion_not_supported` |
| Advisor | `models_advisor_not_supported` |
| `character_id` | `models_character_not_supported` |
| `background: true` | `models_background_not_supported` |
| Inline moderation | `models_moderation_not_supported` |
| PII redaction requested on the request or a model suffix | `models_redaction_not_supported` |
| The web search add-on (a search suffix such as `:online`, or search options in the request body), Context Memory, URL scraping or transcript add-ons | `models_addon_not_supported` |

A malformed list returns `models_invalid`, and more than 4 entries in `models`, or more than 4 models in total, returns `models_too_many`. These two apply to any `models` list, however many models it names. A `web_search` tool on `/v1/responses` isn't the add-on, and can be used with `models`.

### Provider controls on Responses and Messages

Both routes accept the same `provider` object as Chat Completions, with the same errors, and `/v1/messages` applies it the same way.

Most `/v1/responses` requests also run through the same routing. Some can only run on a native route, for example those using built-in tools or computer use. A native route doesn't rank providers, so:

| Control | On a native route |
| - | - |
| `only`, `ignore` | Enforced. If they leave the route no provider, the request returns `403` `no_allowed_provider_for_model`. |
| `order`, `sort`, `preferred_max_latency`, `preferred_min_throughput` | Accepted, with no effect, because nothing is ranked. With `allow_fallbacks: false`, `order` is enforced like `only`. |
| `allow_fallbacks` | Accepted, but it doesn't pin the request to one provider: `false` skips some of the route's alternative attempts, not all of them. |
| `max_price`, `quantizations`, `min_quantization` | Returns `400` `provider_control_not_supported`, because the route can't apply them. Remove the control, or the feature that needs the native route. |

### Output limits

Providers can accept different maximum output budgets for the same model. A provider whose `maxOutputTokens` is lower than the request's `max_tokens`, `max_completion_tokens` or `max_output_tokens` is skipped, including under `sort: "price"` and `max_price` routing. NanoGPT does not lower your budget to fit a provider.

For example, with `max_tokens: 131072`, a provider whose `maxOutputTokens` is `128000` is never chosen, even when it is the cheapest. To keep a provider eligible, send a budget at or below its `maxOutputTokens`, or omit `max_tokens`. Check `providers[].maxOutputTokens` from the [discovery endpoint](#discover-providers-and-pricing) before sending large budgets.

### Validation

Invalid object shapes return a structured `400` error:

* `provider.order`, `provider.only`, and `provider.ignore` must be arrays of strings.
* `provider.quantizations` must be a non-empty array of supported quantization strings.
* `provider.min_quantization` must be a supported comparable quantization string. `unknown` is only valid in `provider.quantizations`.
* If `provider.quantizations` and `provider.min_quantization` have no overlap, the request is invalid.
* Unknown providers in `only` return `provider_unknown_provider`.
* Unknown providers in `order` and `ignore` are ignored. The exception is `provider.allow_fallbacks: false`, which makes `order` the full list, enforced like `only`. If `order` names no usable provider, the request returns `provider_unknown_provider`. If it shares none with `only`, the request returns `provider_order_only_conflict`. If **Enable paid models on API** is off for a subscription, it returns `provider_selection_not_available`.
* `provider.data_collection` must be `allow` or `deny`. `deny` returns `provider_data_collection_unsupported`, unless the request also sends `provider.zdr: true`. To require zero data retention, send `provider.zdr: true`.
* `provider.max_price.prompt` and `provider.max_price.completion` must be non-negative numbers.
* `provider.allow_fallbacks` and `provider.require_parameters` must be booleans.
* `provider.sort` must be a string or an object with `by` and an optional `partition`. Invalid values return `provider_sort_invalid`.
* `provider.preferred_max_latency` and `provider.preferred_min_throughput` must be a non-negative number or an object with non-negative `p50`, `p75`, `p90` or `p99` values. Invalid values return `provider_field_invalid`.

Example error:

```json theme={null}
{
  "error": {
    "message": "Unknown or unavailable provider id in provider.only: not-a-provider",
    "type": "invalid_request_error",
    "param": "provider.only",
    "code": "provider_unknown_provider"
  }
}
```

## Consecutive Prompts and Prompt Caching

When you explicitly select a provider with `X-Provider` or body `provider`, NanoGPT routes that request to the selected provider. For consecutive prompts, using the same provider helps keep routing stable, which is the setup you want for provider-side prompt-cache reuse when that provider and model support caching.

For capability-based routing, use top-level `caching: true` or the `:caching` model suffix instead of choosing a specific provider. NanoGPT will route to any available provider that supports prompt/input caching for the requested provider-selection model, and later matching requests prefer the same eligible provider through soft affinity.

General automatic routing may use cache-affinity routing for eligible cache-capable providers, but it does not require a cache-capable provider and may still choose different upstream providers when request shape, provider availability, or routing constraints change. For cache-sensitive workflows, either consistently send the same `X-Provider` value or use `caching: true` / `:caching` when any cache-capable provider is acceptable.

## Cache-Capable Provider Routing

Set `caching: true` when you want NanoGPT to route a chat completion request to any available provider that supports prompt/input caching. This is capability-based provider selection, not explicit provider selection and not prompt-cache annotation. It does not add Anthropic-style `cache_control` markers or configure cache TTLs.

```json theme={null}
{
  "model": "model-id",
  "caching": true,
  "messages": [
    { "role": "user", "content": "Hello" }
  ]
}
```

If no usable cache-capable provider exists for the model, the request fails instead of falling back to a non-cache-capable provider.

`caching: true` prefers the provider from your previous matching request (soft affinity). `stickyProvider` defaults to `false`; set it to `true` to disable cross-provider fallback. Neither setting guarantees a cache hit.

To prevent cross-provider fallback when preserving the cache route matters more than availability:

```json theme={null}
{
  "model": "model-id",
  "caching": true,
  "stickyprovider": true,
  "messages": [
    { "role": "user", "content": "Hello" }
  ]
}
```

Top-level `stickyProvider` is accepted as a camelCase alias for `stickyprovider`. Setting it to `true` disables cross-provider fallback for the caching request. Leaving it `false` allows fallback; it does **not** disable the soft affinity established by explicit caching.

Affinity expires after about one hour without a successful matching request. This is a routing preference lifetime, separate from the provider's cache TTL. Availability, exclusions, price caps, and request compatibility still apply.

The model suffixes `:caching`, `:cache`, and `:cached` request the same cache-capable provider routing:

```json theme={null}
{
  "model": "moonshotai/kimi-k2.6:thinking:caching",
  "messages": [
    { "role": "user", "content": "Hello" }
  ]
}
```

Routing order for `caching: true`:

1. Filter to providers that are available, not excluded by preferences, and marked as prompt-caching capable.
2. Prefer the previously recorded provider for the same cache-relevant request shape when still usable.
3. Try eligible per-model and global provider preferences.
4. Otherwise use provider prices and recent aggregate cache-read observations to choose a route. A provider with better observed cache reuse may be preferred within a bounded price range.

The model page's cache-hit figures are historical aggregates across requests, not a prediction of your hit rate. Cache reuse also depends on prompt-prefix stability, provider requirements, and cache TTL.

## Price Caps and Cache Reuse

Use public provider IDs from the discovery endpoint and choose caps suitable for that model. The prices below are illustrative.

### Lowest estimated cost with caps

```json theme={null}
{
  "model": "model-id",
  "provider": {
    "sort": "price",
    "max_price": { "prompt": 0.5, "completion": 2 }
  },
  "messages": [{ "role": "user", "content": "Hello" }]
}
```

The ranking uses estimated input tokens and the output budget when available, with defaults of 3,000 input and 1,000 output tokens for missing estimates. Known cache-write costs may be included, but chat routing does not assume a future cache hit or subtract a predicted cache-read discount. This is an estimate, not a guarantee of the cheapest final bill.

### One provider with caps

```json theme={null}
{
  "model": "model-id",
  "provider": {
    "only": ["provider-id"],
    "allow_fallbacks": false,
    "max_price": { "prompt": 0.5, "completion": 2 }
  },
  "messages": [{ "role": "user", "content": "Hello" }]
}
```

Price ranking is inferred here, but `only` leaves a single candidate. This request fails if the provider is unavailable, incompatible, or over the cap. Keeping the provider fixed helps cache reuse, but does not guarantee a cache hit.

### Cache reuse with automatic provider choice

```json theme={null}
{
  "model": "model-id",
  "caching": true,
  "messages": [{ "role": "user", "content": "Hello" }]
}
```

This prefers the previous eligible cache provider. Use the [prompt-caching helper](https://docs.nano-gpt.com/api-reference/miscellaneous/prompt-caching.md) when the provider also needs explicit cache markers or a TTL.

### Combining controls

| Controls | Routing behavior |
| - | - |
| `caching: true` alone | Cache-capable selection with soft affinity. |
| `caching: true` with `stickyProvider: true` | Cache-capable selection with cross-provider fallback disabled. |
| `max_price` without `order` or an explicit sort override | Infers price ranking, which takes precedence over cache-affinity selection. |
| `caching: true` with `sort: "price"` | Price ranking takes precedence; this does not mean “cheapest once, then stay there.” |
| `caching: true` with `order` and `max_price`, without a routing sort | `order` prevents inferred price ranking; caching selection still applies the cap and saved restrictions. |

An ordered provider list is evaluated for each request. It is not a sticky failover session: failure on one request does not permanently advance the list to the next provider. In caching mode, an eligible provider recorded by affinity can take priority over the order.

### Price-cap limits

For requests with a verified provider-selection price, `max_price` restricts retries to routes whose billed base rate NanoGPT can verify against your cap. If the selected provider fails and no such route is available, the request fails instead of being billed at an unverified rate. On models without provider selection, `max_price` only filters routes; billing uses the model's price. An explicitly selected gateway without a verifiable provider price rejects the cap.

`max_price` compares effective provider input/output rates **after provider-selection markup**, so a provider with a raw input rate of $0.06/M and 5% markup requires a prompt cap of at least $0.063/M. The selection markup is already included in provider-discovery prices; do not add it again.

These are token-rate filters, not a total request budget. They do not separately cap cache-read prices, cache-write prices, search fees, or other add-ons. Local comparisons use the provider's base input/output tier, so inspect higher-context tiers separately. Unknown prices cannot be verified locally; gateway routes also pass a price constraint upstream, while direct fallback routes with unknown prices are excluded. For a predictable choice, select a provider with published pricing and disable fallback.

## Per-Request Routing Preference

For provider-selection-capable models, you can append a routing preference suffix to the model ID:

* `:speed` / `:fast`: best estimated completion time using TTFT plus TPS.
* `:throughput`: highest tokens per second.
* `:latency`: lowest time to first token.
* `:price` / `:cheap`: lowest estimated cost for the request’s input and expected output, including selection markup. Opt-in providers that are otherwise used only when selected explicitly are included; when Auto routing is no more expensive, the request stays on Auto and is billed at the Auto price.
* `:floor`: alias for `:price`.
* `:nitro`: alias for `:throughput`.
* `:tools`: route to a tools-capable provider path when the model supports tools provider selection.

Example:

```json theme={null}
{
  "model": "zai-org/glm-5:fast",
  "messages": [{ "role": "user", "content": "Hello" }]
}
```

Notes:

* Routing preference suffixes are billed like explicit provider-selection requests.
* They cannot be combined with `X-Provider`, body `provider`, or provider model suffixes.
* `:tools` cannot be combined with routing preference suffixes or `caching: true`.
* If the model does not support provider selection, the request returns an invalid request error for these suffixes.

See [Model Suffixes](https://docs.nano-gpt.com/api-reference/miscellaneous/model-suffixes.md) for the complete suffix reference and composition rules.

## Persistent Provider Preferences

These endpoints let a user save provider preferences in their session metadata.

```
GET /api/user/provider-preferences
PATCH /api/user/provider-preferences
DELETE /api/user/provider-preferences
```

These endpoints require a logged-in web session. API-key-only requests should use per-request provider selection with `X-Provider`, unless preferences were already saved on the associated user session.

Saved provider preferences apply to pay-as-you-go traffic. For subscription-included traffic, send `X-Billing-Mode: paygo` or `billing_mode: "paygo"` when you want saved provider preferences to apply.

Example `GET` response (placeholders):

```json theme={null}
{
  "preferredProviders": ["provider-a", "provider-b"],
  "excludedProviders": ["provider-c"],
  "enableFallback": true,
  "modelOverrides": {
    "model-id": {
      "preferredProviders": ["provider-b"],
      "enableFallback": false
    }
  },
  "availableProviders": ["provider-a", "provider-b", "provider-c"]
}
```

Example `PATCH` payload:

```json theme={null}
{
  "preferredProviders": ["provider-a", "provider-b"],
  "excludedProviders": ["provider-c"],
  "enableFallback": false,
  "modelOverrides": {
    "model-id": {
      "preferredProviders": ["provider-b"],
      "enableFallback": true
    }
  }
}
```

Field details:

* `preferredProviders`: ordered list of allowed providers; the system tries each in order.
* `excludedProviders`: providers that should never be used.
* `enableFallback`: when `true` (default), permits retries among eligible providers. A configured `preferredProviders` list remains a hard allowlist; fallback does not escape it to the platform default.
* `modelOverrides`: optional per-model overrides for the fields above.
* `availableProviders`: full set of provider IDs available to your account for the model.

## Resolution Order

When `caching: true` is set without a routing preference, use the routing order in [Cache-Capable Provider Routing](#cache-capable-provider-routing). Otherwise, when multiple selections exist, the system resolves providers in this order:

1. Per-request explicit provider selection (`X-Provider`, body `provider` string/object, or provider suffix)
2. Per-request routing preference suffix (`:fast`, `:cheap`, etc.)
3. Per-model `preferredProviders`
4. Global `preferredProviders`
5. Platform default when no binding provider allowlist or request constraint selects a route

## Billing and Markup

* If you explicitly select or constrain providers with `X-Provider` or body `provider`, billing uses the resolved provider-specific price plus the applicable provider-selection markup (normally 5%) and the request is treated as pay-as-you-go.
* If saved preferences select a provider on pay-as-you-go traffic, billing uses the provider-specific price plus the applicable provider-selection markup (normally 5%).
* If you do not select a provider, billing uses the model's default price.
* `provider.preferred_max_latency` and `provider.preferred_min_throughput` don't change billing by themselves.

## Which Provider Served My Request?

The [Usage page](https://nano-gpt.com/usage) shows a label such as **Via Cerebras** under the model name, and a Provider row in request details, when public attribution is available. This can include explicit selections, supported BYOK routes, or a public provider used as a fallback. Some automatic requests have no provider label.

Chat responses and the [request billing endpoint](https://docs.nano-gpt.com/api-reference/endpoint/request-billing.md) do not expose the upstream provider. Do not rely on an undocumented response header or infer a provider from timing or price.

## Error Behavior

* `400` with `error.code: "provider_max_price_unverifiable"` means an explicitly selected gateway has no verifiable provider price for the model. Choose a provider with published pricing, or remove the cap to use normal gateway billing.

* If `enableFallback` is `false` and no preferred provider is available, `/api/v1/chat/completions` returns `400` with `error.code: "no_fallback_available"`.

* Invalid body `provider` objects return `400` with `error.type: "invalid_request_error"`.

* `PATCH /api/user/provider-preferences` validates provider IDs and returns:
  * `422 INVALID_INPUT` for malformed payloads.
  * `400 INVALID_EXCLUSIONS` if exclusions would leave a model with no usable provider.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.