# How to cut your LLM API bill: tiers, max_tokens and budgets

> Cut your LLM API bill in half by routing routine tasks to cheaper model tiers, restricting max_tokens, and setting project and user spend caps.

**You can cut your LLM API bill in half by routing routine tasks to cheaper model tiers, capping max_tokens on every call, and enforcing hard daily budgets.** Most API spend is wasted when applications default to expensive flagship models for simple classification, omit output token ceilings, or run background jobs without hard spend limits. Splitting workloads across model tiers and enforcing caps stops runaway spending without lowering output quality.

Here is how to audit your token usage, restructure model routing, and enforce hard budgets using thelastapi.

## Route tasks across model tiers instead of using one model for everything

The fastest way to cut your bill is to stop calling top-tier models for every step in your pipeline. If your app sends classification, entity extraction, data transformation, or agent tool selection to a flagship model, you pay twenty to forty times more per token than necessary.

With [the AI gateway](https://thelastapi.dev/docs/ai), thelastapi provides stable model tiers named for what they do, as well as direct access to over 400 lab models. You can see how lab prices compare in [GPT vs Claude vs Gemini API pricing per million tokens](https://thelastapi.dev/blog/gpt-claude-gemini-api-pricing).

| thelastapi model | Underlying lab model | Best use case | Price per million tokens (in / out) |
| --- | --- | --- | --- |
| `vibiz/fast` | GPT-6 Luna (OpenAI) | chat, tool calls, JSON extraction | $0.10 / $0.50 |
| `vibiz/lite` | DeepSeek V4.1 Flash (DeepSeek) | cheap chat, 1M context | $0.14 / $0.42 |
| `vibiz/smart-mini` | Claude Haiku 5.5 (Anthropic) | fast writing and coding | $0.10 / $0.50 |
| `vibiz/balanced` | Gemini 3.8 Flash (Google) | balanced price and capability, 1M context | $0.825 / $4.125 |
| `vibiz/reasoning` | GPT-6.1 Terra (OpenAI) | math, logic, step-by-step planning | $1.00 / $5.00 |
| `vibiz/smart` | Claude Sonnet 5.5 (Anthropic) | coding, hard writing, agents | $2.00 / $10.00 |
| `vibiz/pro` | Claude Opus 5.5 (Anthropic) | complex agent tasks, hardest chat | $4.00 / $20.00 |

If your pipeline runs three classification steps before drafting a final response, run those initial steps on `vibiz/fast` or `vibiz/smart-mini` at $0.10 per million input tokens. Reserve `vibiz/smart` ($2.00 per million input tokens) only for the final output. That reduces token costs for the earlier pipeline stages by 95 percent.

Because the gateway is OpenAI-compatible, you can use the same SDK client to switch models on a per-call basis. See [One API key for GPT, Claude and Gemini: how a unified AI API works](https://thelastapi.dev/blog/one-api-key-gpt-claude-gemini) for client configuration details.

```ts
import OpenAI from 'openai';

const openai = new OpenAI({
  baseURL: process.env.VIBIZ_AI_BASE_URL,
  apiKey: process.env.VIBIZ_AI_API_KEY,
});

// Step 1: Cheap classification using vibiz/fast ($0.10 / $0.50 per M tokens)
const routing = await openai.chat.completions.create({
  model: 'vibiz/fast',
  messages: [
    { role: 'system', content: 'Classify the inquiry into: billing, technical, or sales. Return only the category.' },
    { role: 'user', content: 'Where do I update my credit card details?' },
  ],
  max_tokens: 10,
});

// Step 2: Complex reasoning only when needed
const response = await openai.chat.completions.create({
  model: 'vibiz/smart',
  messages: [
    { role: 'system', content: 'Draft a precise answer using our account policy docs.' },
    { role: 'user', content: 'Explain our billing retry schedule and grace period.' },
  ],
  max_tokens: 300,
});
```

## Set max_tokens on every generation

Output tokens cost three to five times more than input tokens across every major lab. On `vibiz/smart`, input tokens cost $2.00 per million while output tokens cost $10.00 per million. On `vibiz/pro`, output tokens cost $20.00 per million.

When you do not set `max_tokens` explicitly, the API defaults to 1,024 tokens and permits up to 16,384 tokens. If a prompt triggers an unexpected repetition loop or verbose explanations, you pay for hundreds of unwanted tokens.

Always clamp `max_tokens` to the maximum size your user interface or downstream process expects:

```ts
const summary = await openai.chat.completions.create({
  model: 'vibiz/fast',
  messages: [{ role: 'user', content: 'Summarize this ticket in one sentence.' }],
  max_tokens: 60,
});
```

Setting `max_tokens` also protects against balance reservation rejections. thelastapi operates on prepaid credits, as detailed in [Billing and credits](https://thelastapi.dev/docs/billing). Before executing an AI request, the system checks whether the call's worst-case cost (the full `max_tokens` limit evaluated at model list price) fits within your credit balance plus a $0.50 margin. If the worst case exceeds that margin, the gateway returns a `402 payment_required` error:

```json
{
  "error": {
    "code": "payment_required",
    "message": "This account is out of credits. Add credits to keep using paid calls."
  }
}
```

Keeping `max_tokens` tight prevents large balance reservations and lets low-balance accounts continue processing short requests reliably.

## Enforce daily spend ceilings and project budgets

Runaway background tasks, agent loops, or sudden traffic spikes can drain an account balance quickly if you do not set caps. thelastapi provides multi-tiered budget controls at the account, project, and end-user levels. You can read more about tracking caps in [Usage and limits](https://thelastapi.dev/docs/usage).

### Account daily safety cap

Every account starts with an automatic daily cap across AI and actions of $5 per UTC day. When total spend reaches this cap, calls are rejected with status `429 rate_limited` and `details.reason: "daily_spend"`.

To check or update this ceiling using the CLI:

```bash
vibiz billing limit          # prints current ceiling
vibiz billing limit 25       # sets daily spend limit to $25
```

Account owners can also update this limit via `PATCH /v1/billing`:

```bash
curl -X PATCH https://thelastapi.dev/v1/billing \
  -H "Authorization: Bearer $VIBIZ_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"daily_spend_limit_usd": 25}'
```

### Project AI budgets

You can isolate risks between staging, internal bots, and customer apps by applying individual project budgets. Each project defaults to a $1 daily AI budget per UTC day.

Check or adjust this budget with the CLI:

```bash
vibiz ai budget 10 --project prj_123
```

Or configure it over HTTP:

```bash
curl -X PATCH https://thelastapi.dev/v1/projects/prj_123/ai \
  -H "Authorization: Bearer $VIBIZ_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"daily_budget_usd": 10}'
```

When a project crosses its limit, it answers `429` with `details.reason: "project_budget"`. Limit alert emails are automatically sent to account owners at 80% and 100% of the daily spend ceiling and project budgets.

### End-user budgets

A single user repeatedly sending massive prompts can consume your entire API margin. thelastapi allows you to set an individual spend ceiling per user by passing their user ID on requests. See [Per-user AI budgets: stop one user from burning your AI bill](https://thelastapi.dev/blog/per-user-ai-budgets) for complete setup instructions.

Pass a pseudonymous user identifier using the `user` field in your completion request, or attach the `X-Vibiz-User` header. If your app uses `@vibiz/app`, use `vibiz.user(id)`:

```ts
import { vibiz } from '@vibiz/app';
import OpenAI from 'openai';

// Binds downstream calls to this end user
const openai = new OpenAI(vibiz.user('usr_abc123').ai);

const res = await openai.chat.completions.create({
  model: 'vibiz/fast',
  messages: [{ role: 'user', content: 'Help me draft an email.' }],
});
```

You can set a per-user daily budget on the project via `PATCH /v1/projects/:id/ai`:

```bash
curl -X PATCH https://thelastapi.dev/v1/projects/prj_123/ai \
  -H "Authorization: Bearer $VIBIZ_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"end_user_daily_budget_usd": 0.50}'
```

When an individual user exceeds $0.50 in a day, their requests fail with a `429` error carrying `details.reason: "end_user_budget"`, leaving your remaining users unaffected.

## Avoid long-context pricing thresholds

Certain chat models introduce higher token prices once an input prompt crosses a long-context boundary. 

On thelastapi, Claude Haiku 5.5 input tokens are charged higher rates past 100,000 input tokens, and GPT-6 models charge higher rates past 272,000 input tokens. If your application blindly appends complete chat histories, conversation turns can quietly slip over these thresholds, triggering higher pricing on every subsequent prompt.

To avoid this:
1. Truncate conversation history to keep only the recent turns required for context.
2. Summarize older conversation turns using `vibiz/fast`.
3. Check `cost_micro_usd` on every JSON response to catch unexpected context inflation.

```bash
curl https://thelastapi.dev/v1/ai/chat/completions \
  -H "Authorization: Bearer $VIBIZ_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"vibiz/fast","messages":[{"role":"user","content":"Hello"}]}'
```

The response includes the exact cost incurred:

```json
{
  "id": "chatcmpl_123",
  "object": "chat.completion",
  "model": "vibiz/fast",
  "served_model": "gpt-6-luna",
  "cost_micro_usd": 12,
  "choices": [{ "message": { "role": "assistant", "content": "Hello! How can I help you today?" } }]
}
```

## Monitor spend breakdown across models and keys

You cannot optimize what you do not measure. Inspect your spend regularly by model, tool, or API key using the CLI:

```bash
vibiz usage --period 7d --by model
vibiz usage --period 24h --by api_key
vibiz usage --by end_user --project prj_123
```

Or query the usage API endpoint directly:

```bash
curl "https://thelastapi.dev/v1/usage?period=7d&group_by=model" \
  -H "Authorization: Bearer $VIBIZ_API_KEY"
```

This returns total spend and token counts grouped by model name, showing you exactly which model tier drives the majority of your bill.

Next: audit your current model distribution with `vibiz usage --by model`, set explicit `max_tokens` on your largest completions, and configure your project budget with `vibiz ai budget`.

## Frequently asked questions

### What happens if an API call exceeds my account daily spend limit?

The gateway rejects the call with an HTTP 429 status code and returns `details.reason: "daily_spend"`. Daily spend limits reset automatically at midnight UTC.

### What is the default max_tokens limit if I do not specify one?

When `max_tokens` is omitted, the API defaults to 1,024 tokens, and it accepts values up to 16,384 tokens depending on the model.

### How can I tell how much an individual completion call cost?

Every JSON completion response returned by the AI gateway contains the `cost_micro_usd` field, which reports the exact cost of that request in micro-dollars.

### Can I use my own provider credentials to lower costs further?

Yes. You can add your own Gemini API key using `vibiz ai keys set google`, and Google models will run directly on your Google account at zero cost on thelastapi.

---

Published 2026-11-15 · https://thelastapi.dev/blog/cut-llm-api-bill
