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

# Limit the price of a request

> Keep a request on providers at a model's base price, or cap what it pays per token, second or image, so it never costs more than you choose.

Some models are sold in a price range: most of their providers charge the base price, and a few charge more. By default, NagaAI sends a request to a dearer provider when the cheaper ones can't serve it. To make sure a request never costs more than you choose, set a price limit.

## Before you begin

Check whether your model has a price range. In [`GET /v1/models`](https://docs.naga.ac/api-reference/models/list-models), a row of the model's `pricing` that has a `max_price` next to its `price` is a range. For example, `openai/gpt-6.1-sol` costs between 0.0000025 and 0.000005 credits per output token:

```json theme={"theme":{"light":"github-light-default","dark":"github-dark-dimmed"}}
{"meter": "output_token", "unit": "token", "price": "0.0000025", "max_price": "0.000005"}
```

A model without `max_price` costs the same on every provider, so a limit changes nothing for it.

## Choose how to limit the price

NagaAI offers two ways to limit the price. Use one of them:

| Option | What it does | Endpoints |
| - | - | - |
| [`service_tier: "flex"`](https://docs.naga.ac/api-reference/responses/create-a-response#body-service-tier) | Uses only providers at the base `price` | Responses, Chat Completions |
| [`routing.max_price`](https://docs.naga.ac/api-reference/routing-object#attributes) | Uses only providers at or below your cap for each meter you name | Every endpoint |

A limit removes providers. When none of the model's providers fits, NagaAI tries your [fallback models](https://docs.naga.ac/build/routing.md#fallback-models); without them, the request fails. See [Troubleshooting](#troubleshooting).

## Use only base-price providers

1. Add `service_tier: "flex"` to a Responses or Chat Completions request.
2. Send the request:

   ```python Python theme={"theme":{"light":"github-light-default","dark":"github-dark-dimmed"}}
   import os

   from openai import OpenAI

   client = OpenAI(base_url="https://api.naga.ac/v1", api_key=os.environ["NAGA_API_KEY"])

   response = client.responses.create(
       model="openai/gpt-6.1-sol",
       input="Suggest a name for a Python library that parses invoices.",
       service_tier="flex",
   )

   print(response.output_text)
   ```

   ```javascript Node.js theme={"theme":{"light":"github-light-default","dark":"github-dark-dimmed"}}
   import OpenAI from "openai";

   const client = new OpenAI({ baseURL: "https://api.naga.ac/v1", apiKey: process.env.NAGA_API_KEY });

   const response = await client.responses.create({
     model: "openai/gpt-6.1-sol",
     input: "Suggest a name for a Python library that parses invoices.",
     service_tier: "flex",
   });

   console.log(response.output_text);
   ```

   ```bash cURL theme={"theme":{"light":"github-light-default","dark":"github-dark-dimmed"}}
   curl https://api.naga.ac/v1/responses \
     -H "Authorization: Bearer $NAGA_API_KEY" \
     -H "Content-Type: application/json" \
     -d '{
       "model": "openai/gpt-6.1-sol",
       "input": "Suggest a name for a Python library that parses invoices.",
       "service_tier": "flex"
     }'
   ```

The response is a normal answer, and `output_text` holds the model's text. The request is billed at the base price. Any other `service_tier` value, or none, lets every provider serve the request.

## Set a price cap

1. In the model's `pricing`, find the meter to cap, such as `output_token`. [The routing object](https://docs.naga.ac/api-reference/routing-object.md#meters) lists every meter.
2. Add `routing.max_price` with the meter and the most one unit may cost, in credits, as a decimal string.
3. Send the request:

> [tab] Responses
>
> ```python Python theme={"theme":{"light":"github-light-default","dark":"github-dark-dimmed"}}
> import os
>
> from openai import OpenAI
>
> client = OpenAI(base_url="https://api.naga.ac/v1", api_key=os.environ["NAGA_API_KEY"])
>
> response = client.responses.create(
>     model="openai/gpt-6.1-sol",
>     input="Suggest a name for a Python library that parses invoices.",
>     extra_body={"routing": {"max_price": {"output_token": "0.0000025"}}},
> )
>
> print(response.output_text)
> ```
>
> ```javascript Node.js theme={"theme":{"light":"github-light-default","dark":"github-dark-dimmed"}}
> import OpenAI from "openai";
>
> const client = new OpenAI({ baseURL: "https://api.naga.ac/v1", apiKey: process.env.NAGA_API_KEY });
>
> const response = await client.responses.create({
>   model: "openai/gpt-6.1-sol",
>   input: "Suggest a name for a Python library that parses invoices.",
>   routing: { max_price: { output_token: "0.0000025" } },
> });
>
> console.log(response.output_text);
> ```
>
> ```bash cURL theme={"theme":{"light":"github-light-default","dark":"github-dark-dimmed"}}
> curl https://api.naga.ac/v1/responses \
>   -H "Authorization: Bearer $NAGA_API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{
>     "model": "openai/gpt-6.1-sol",
>     "input": "Suggest a name for a Python library that parses invoices.",
>     "routing": {"max_price": {"output_token": "0.0000025"}}
>   }'
> ```

> [tab] Chat Completions
>
> ```python Python theme={"theme":{"light":"github-light-default","dark":"github-dark-dimmed"}}
> import os
>
> from openai import OpenAI
>
> client = OpenAI(base_url="https://api.naga.ac/v1", api_key=os.environ["NAGA_API_KEY"])
>
> completion = client.chat.completions.create(
>     model="openai/gpt-6.1-sol",
>     messages=[{"role": "user", "content": "Suggest a name for a Python library that parses invoices."}],
>     extra_body={"routing": {"max_price": {"output_token": "0.0000025"}}},
> )
>
> print(completion.choices[0].message.content)
> ```
>
> ```javascript Node.js theme={"theme":{"light":"github-light-default","dark":"github-dark-dimmed"}}
> import OpenAI from "openai";
>
> const client = new OpenAI({ baseURL: "https://api.naga.ac/v1", apiKey: process.env.NAGA_API_KEY });
>
> const completion = await client.chat.completions.create({
>   model: "openai/gpt-6.1-sol",
>   messages: [{ role: "user", content: "Suggest a name for a Python library that parses invoices." }],
>   routing: { max_price: { output_token: "0.0000025" } },
> });
>
> console.log(completion.choices[0].message.content);
> ```
>
> ```bash cURL theme={"theme":{"light":"github-light-default","dark":"github-dark-dimmed"}}
> curl https://api.naga.ac/v1/chat/completions \
>   -H "Authorization: Bearer $NAGA_API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{
>     "model": "openai/gpt-6.1-sol",
>     "messages": [{"role": "user", "content": "Suggest a name for a Python library that parses invoices."}],
>     "routing": {"max_price": {"output_token": "0.0000025"}}
>   }'
> ```

> [tab] Messages
>
> ```python Python theme={"theme":{"light":"github-light-default","dark":"github-dark-dimmed"}}
> import os
>
> from anthropic import Anthropic
>
> client = Anthropic(base_url="https://api.naga.ac", api_key=os.environ["NAGA_API_KEY"])
>
> message = client.messages.create(
>     model="openai/gpt-6.1-sol",
>     max_tokens=512,
>     messages=[{"role": "user", "content": "Suggest a name for a Python library that parses invoices."}],
>     extra_body={"routing": {"max_price": {"output_token": "0.0000025"}}},
> )
>
> print(next(block.text for block in message.content if block.type == "text"))
> ```
>
> ```typescript TypeScript theme={"theme":{"light":"github-light-default","dark":"github-dark-dimmed"}}
> import Anthropic from "@anthropic-ai/sdk";
>
> const client = new Anthropic({ baseURL: "https://api.naga.ac", apiKey: process.env.NAGA_API_KEY });
>
> const message = await client.messages.create({
>   model: "openai/gpt-6.1-sol",
>   max_tokens: 512,
>   messages: [{ role: "user", content: "Suggest a name for a Python library that parses invoices." }],
>   // @ts-expect-error routing is a NagaAI field the SDK types don't know
>   routing: { max_price: { output_token: "0.0000025" } },
> });
>
> const text = message.content.find((block) => block.type === "text");
> console.log(text?.type === "text" ? text.text : "");
> ```
>
> ```bash cURL theme={"theme":{"light":"github-light-default","dark":"github-dark-dimmed"}}
> curl https://api.naga.ac/v1/messages \
>   -H "x-api-key: $NAGA_API_KEY" \
>   -H "anthropic-version: 2023-06-01" \
>   -H "Content-Type: application/json" \
>   -d '{
>     "model": "openai/gpt-6.1-sol",
>     "max_tokens": 512,
>     "messages": [{"role": "user", "content": "Suggest a name for a Python library that parses invoices."}],
>     "routing": {"max_price": {"output_token": "0.0000025"}}
>   }'
> ```

NagaAI uses only providers that charge at most 0.0000025 credits per output token. The OpenAI Python SDK sends `routing` through `extra_body`, because `routing` is a NagaAI field.

A meter the model doesn't price is skipped, so one cap can serve several models.

## Cap the price of an image, video, or audio request

Image, video, speech, transcription, embeddings, moderation, and rerank requests take `routing.max_price` the same way. Cap the meter that the model's `pricing` names, such as `output_image_token` for an image model:

```python Python theme={"theme":{"light":"github-light-default","dark":"github-dark-dimmed"}}
import os

from openai import OpenAI

client = OpenAI(base_url="https://api.naga.ac/v1", api_key=os.environ["NAGA_API_KEY"])

result = client.images.generate(
    model="openai/gpt-image-2.5-sunburst-2026-09-08",
    prompt="A red paper boat on a calm lake, flat illustration for a blog header",
    extra_body={"routing": {"max_price": {"output_image_token": "0.000015"}}},
)

print(result.data[0].url)
```

```javascript Node.js theme={"theme":{"light":"github-light-default","dark":"github-dark-dimmed"}}
import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://api.naga.ac/v1", apiKey: process.env.NAGA_API_KEY });

const result = await client.images.generate({
  model: "openai/gpt-image-2.5-sunburst-2026-09-08",
  prompt: "A red paper boat on a calm lake, flat illustration for a blog header",
  routing: { max_price: { output_image_token: "0.000015" } },
});

console.log(result.data[0].url);
```

```bash cURL theme={"theme":{"light":"github-light-default","dark":"github-dark-dimmed"}}
curl https://api.naga.ac/v1/images/generations \
  -H "Authorization: Bearer $NAGA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-image-2.5-sunburst-2026-09-08",
    "prompt": "A red paper boat on a calm lake, flat illustration for a blog header",
    "routing": {"max_price": {"output_image_token": "0.000015"}}
  }'
```

The response holds the image URL. A video cap on `output_video_second` is checked against the price of the clip you asked for before anything is spent. Image edits and audio uploads are forms; the OpenAI SDKs send `extra_body` there as parts such as `routing[max_price][input_audio_hour]`.

## Troubleshooting

### `400`: no provider serves this request within its price limit

None of the model's providers, and none of your fallback models, is within the limit. The message names the model:

```text theme={"theme":{"light":"github-light-default","dark":"github-dark-dimmed"}}
No provider of the 'openai/gpt-6.1-sol' model serves this request within its price limit.
```

Raise `routing.max_price` to the model's `max_price`, drop `service_tier: "flex"`, or add a [fallback model](https://docs.naga.ac/build/routing.md#fallback-models) in your price.

### `400`: unknown meter

The cap names a meter that NagaAI doesn't know, such as `output_widget`. Use a meter from the model's `pricing`; [The routing object](https://docs.naga.ac/api-reference/routing-object.md#errors) lists every error of `routing` with its message.

### The request cost more than the base price

The model has a range, and the request had no limit. Check that the request sends `service_tier: "flex"` or `routing.max_price`. In the OpenAI Python SDK, `routing` goes in `extra_body`.

## See also

* [The routing object](https://docs.naga.ac/api-reference/routing-object.md): every field and meter of `routing`.
* [Routing](https://docs.naga.ac/build/routing.md): how NagaAI orders providers and falls back to other models.
* [Billing](https://docs.naga.ac/build/billing.md): what a request costs and when you're charged.


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