Skip to content

Docs / Budgets and limits

Budgets and limits

Per-key monthly budgets, rate limits and model allow-lists, the prepaid balance, and how 402, 403 and 429 responses work.

Get an API key

Four controls decide whether a request runs:

Control Scope When it stops a request Response
Prepaid balance Organisation The balance is empty, or too low for this request 402 insufficient_balance
Monthly budget API key The key’s spend this month has reached its budget, or this request could pass it 402 budget_exceeded
Model allow-list API key The model is not on the key’s list 403 offer_not_permitted
Rate limit API key and organisation Too many requests in the last minute 429 rate_limited

All four are checked before anything is sent to a model. A refused request is not charged.

Prepaid balance

Your organisation has one balance, in USD, CNY or SGD. Every request is paid from it.

  • Empty balance: requests are refused with 402 insufficient_balance.
  • Holds: before a request is sent, its highest possible price (its input plus max_tokens of output) is held from the balance. If what is left after all other running requests’ holds is not enough, the request is refused with 402 insufficient_balance. When the request ends, the hold is released and only the real cost is taken. Requests running at the same time, on any number of servers, can never spend more than your balance.
  • A large max_tokens makes a larger hold. If you get 402 with money still in the balance, lower max_tokens or top up.
  • Cache hits hold nothing and cost nothing.

Avoid running out:

  • Automatic top-up: charge a saved card when the balance falls below a threshold you set. At most one charge at a time, a daily cap (1 to 10 top-ups a day), and it switches off after a declined card.
  • Low-balance alert: by email to administrators and extra addresses, and by signed webhook.

Set both under Billing in the console.

Monthly budget per key

A key can have a monthly budget in your balance currency.

  • A request is refused with 402 budget_exceeded when the key has already spent its budget this month, or when the request’s hold could take it past the budget.
  • Months are calendar months in UTC. Budgets reset at 00:00 UTC on the 1st.
  • Alerts are sent when a key reaches 80 % and 100 % of its budget, once each per month, by email and webhook.
  • The console shows each key’s month-to-date spend and when its budget resets.

Give every agent, CI job and shared tool its own key with a budget. A loop that goes wrong then stops at the budget, not at your balance.

Model allow-list per key

A key can be limited to a list of model IDs (up to 200).

  • A request for any other model is refused with 403 offer_not_permitted.
  • In a fallback chain, a model not on the list is skipped and the next one is tried.
  • GET /v1/models with that key lists only the allowed models.
  • An empty list means every model is allowed.

Rate limits

Limit Default Set by
Per key 120 requests per minute You, when creating the key (1 to 100,000)
Per organisation, across all keys — Yunshu Router
Batch submissions 10 per organisation per minute Yunshu Router

How they work:

  • The limit is a bucket that holds one minute’s worth of requests and refills evenly. A key with 120 per minute can send 120 at once, then about 2 per second.
  • Every request with an API key counts, including GET /v1/models, count_tokens, GET /v1/generation and the batch endpoints.
  • A fallback chain counts as one request, however many models are tried.
  • When you are over a limit you get 429 rate_limited with a Retry-After: 1 header.
  • Limits count requests, not tokens.

There are no X-RateLimit-* headers. Use Retry-After and back off.

import time
import openai
from openai import OpenAI

client = OpenAI(base_url="https://api.yunshurouter.com/v1", api_key="tq-...", max_retries=0)

def ask(messages, attempts=5):
    for attempt in range(attempts):
        try:
            return client.chat.completions.create(model="deepseek-v4-pro", messages=messages)
        except openai.RateLimitError as err:
            wait = float(err.response.headers.get("retry-after", 1))
            time.sleep(wait * (2 ** attempt))
    raise RuntimeError("still rate limited")

The OpenAI and Anthropic SDKs already retry 429 twice by default and read Retry-After. The example turns that off to show the logic.

Other limits

Limit Value
Request body 2 MiB (413 request_too_large)
Messages per request 4,096
Tools per request 512
max_tokens accepted 1 to 1,000,000, then lowered to the model’s maximum output
Fallback models 5 per chain (models: 5, fallbacks: 3)
Batch size 1,000 requests
Combos 100 per organisation, 5 models each

Suspended organisations

A suspended organisation gets 403 account_suspended on every API request. The console stays readable: balances, usage, invoices and batch results.

Zero retention

With zero retention switched on for your organisation, the cache is off for you and POST /v1/batches is refused with 403 permission_denied, because a batch has to store prompts until it runs.

Summary of responses

Status code Anthropic error.type What to do
402 insufficient_balance billing_error Top up, switch on automatic top-up, or lower max_tokens
402 budget_exceeded billing_error Wait for the next month (UTC), or use a key with a higher budget
403 offer_not_permitted permission_error Use an allowed model, or a key that allows this one
403 account_suspended permission_error Contact support
403 permission_denied permission_error Batches with zero retention: send requests one by one, or switch zero retention off
429 rate_limited rate_limit_error Wait for Retry-After, then retry with backoff

All codes: Errors.