Skip to main content

Spend limits for memtrunk keys

Learn the spend and token limits of a memtrunk key. See how the pool cap is resolved, what counts against a limit, who sets limits, and the 429 response.

Last updated

A memtrunk key can carry spend limits. The gateway checks the limits before it forwards a request. When a key has reached a limit, the gateway stops the paid legs of the request. If no leg of your own can serve it, the gateway returns a 429 and does not call the provider.

A request on a personal address uses no key. See Requests on a personal address below.

The three limits#

LimitConsole fieldUnitWindow
Daily spendDaily limit (USD)USDOne UTC day
Monthly spendMonthly limit (USD)USDOne month
Monthly tokensMonthly token limitInput plus output tokensOne month

You set these limits in the Create key and Edit key dialogs on the API keys page. Read Credentials.

The Budget window field is Monthly or Daily. A new key starts as Monthly. The daily limit applies when the Budget window is Daily. The token limit applies with either window.

The gateway checks the daily limit first, then the monthly spend limit, then the token limit. The 429 names the first limit that the key has reached.

The limit of an own key and a pool key#

The Source of a key decides how the monthly limit works. The Source is Own provider key or Shared pool.

  • An Own provider key uses the Monthly limit (USD) of the key. The key can have no monthly limit. An instance can require a limit. Then the console shows an error and does not save the key when you leave the field empty.
  • A Shared pool key always has a monthly limit. The limit is the Monthly limit (USD) of the key, or an instance default when the key has none. At request time, the gateway clamps the limit to the pool cap.

When you save a Shared pool key, the console checks the Monthly limit (USD) against the pool cap override of the owner. If the owner has no override, the console checks it against the instance setting. If the limit is above that value, the console shows an error and does not save the key. This check does not use the team limit.

The team limit still applies later. A key can be above the team limit and still save. The gateway then clamps the key to the pool cap at request time.

Pool cap#

The gateway resolves the pool cap of a user in this order:

  1. The pool cap override that is set for the user.
  2. The monthly limit of the team of the user. This applies only when the organization has teams on and the team access of the user is on.
  3. The instance setting.

The first value that exists wins. The gateway does not combine them.

What counts against a limit#

Each request records usage against the memtrunk key that sent it. The record holds an estimated cost and the input and output tokens.

  • The estimated cost comes from the cost data that memtrunk holds for each model. A model with no cost data adds 0 USD. Its tokens still count.
  • A request that a subscription account serves counts in the same way as a request that a provider key serves.
  • The token limit adds the input tokens and the output tokens.

The gateway checks usage before it forwards a request. A request that starts under a limit can end above it. The next request then gets the 429.

What a reached limit blocks#

A reached limit does not stop every request. The gateway serves the subscription accounts that you own and the private provider keys that you own. It blocks the shared pool accounts of other people, the shared provider keys and the paid fallback. A request that only lists models or counts tokens is not blocked.

If an account or key of your own fails with a short-lived error, such as a cooldown, you get that error and its own Retry-After header. The limit 429 comes only when no leg of your own was available. The request log records a refused request with status 429.

Who sets limits#

  • The owner of a key sets the limits of the key when they create or edit it.
  • An org admin sets the Monthly limit (USD) of a team in the same organization. The field is in the team form on the Teams page.

Requests on a personal address#

A personal address holds your proxy token in the URL path. Claude Code, Codex CLI and Antigravity CLI connect through it. No key takes part, so per-key limits do not apply.

A monthly USD limit that your admin sets can still apply. It counts paid spend, draws on accounts that other people own, and draws with no account owner. It does not count draws on your own subscription accounts. It does not count spend on your own private provider keys, which have their own monthly limit. The sum is the larger of two totals. One is the monthly total of the user. The other is the usage history, which keeps only the newest 2,000 rows for all users together. The month is a UTC calendar month.

When that limit is reached, your own subscription accounts and private provider keys still serve requests. If none can serve a request, the reply is 429 with a Retry-After header. The message starts with Monthly spend limit reached.

Requests on a personal address appear in your usage under your account. They carry no API key. Read Credentials.

The 429 response#

A key that reached a limit gets a 429 with an Anthropic-style error body. The gateway uses this body on the routes that check a memtrunk key. This includes the OpenAI-style routes.

The message states the limit, your value and the reset time. It starts with Daily spend limit reached, Monthly spend limit reached or Monthly token limit reached. The body repeats the values as fields. The spend limits give limit_usd and spend_usd. The token limit gives limit_tokens and used_tokens. Every limit gives resets_at and retry_after.

Every limit adds a Retry-After header. The value is the number of seconds until the limit resets. The daily limit resets at the next UTC midnight. The monthly limits reset at the start of the next UTC month.

bash
curl -i https://<your-memtrunk-address>/v1/messages \
  -H "x-api-key: <your-memtrunk-key>" \
  -H "content-type: application/json" \
  -d '{"model": "<model-name>", "max_tokens": 16, "messages": [{"role": "user", "content": "Hello"}]}'

The response for a key that reached its daily limit looks like this. The numbers are examples.

http
HTTP/1.1 429 Too Many Requests
Retry-After: 41230
Content-Type: application/json

{
  "type": "error",
  "error": {
    "type": "rate_limit_error",
    "message": "Daily spend limit reached. You spent $12.00 of your $10.00 limit today. The limit resets at <next UTC midnight, ISO 8601>.",
    "limit_usd": 10.0,
    "spend_usd": 12.0,
    "resets_at": "<next UTC midnight, ISO 8601>",
    "retry_after": 41230
  }
}

A provider key at its own monthly limit has a separate 429. Read Provider keys.

Next steps#