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

# Configure token limits

> Set global and per-model context and output token limits that apply to every Cake Agents session in your organization.

Token limits cap the context window and output size, in tokens, that sessions use for each model. Administrators set them once, and every new session applies them automatically.

Use token limits when you want to:

* Constrain context growth to control cost per session.
* Keep sessions within the context window a proxy or upstream provider actually supports.
* Give specific models a larger or smaller budget than the rest.

## How limits are resolved

When a session starts, Cake resolves the context and output limits for its model in this order:

1. A per-session override, if the user set one when creating the session.
2. A per-model override from the Token Limits settings.
3. The global limit from the Token Limits settings.

If none of these are set, the model runs without a configured limit. Cake passes the resolved values into the OpenCode model configuration as `limit.context` and `limit.output`.

## Set limits in the UI

1. Sign in to Cake Agents as an administrator.
2. Open `Settings → Organization → Providers`.
3. Scroll to the `Token Limits` section.
4. Enter a global `Context Limit` and `Output Limit`.
5. Optionally add per-model overrides for models that need different values.
6. Save the settings.

## Rules and validation

* Limits are integers between 1 and 10,000,000 tokens.
* If you set a context limit, you must also set an output limit.
* A global limit must be defined before you can add per-model overrides.
* Each model can have at most one override. An override can set context, output, or both; any value it omits falls back to the global limit.

<Warning>
  Setting a context limit that exceeds what a model can actually handle can result in unpredictable behavior. Check the model's documented context window before raising limits.
</Warning>

## API

You can read and replace the organization's token limits programmatically:

```http theme={null}
PUT /api/settings/token-limits
Content-Type: application/json

{
  "global": {
    "context": 200000,
    "output": 32000
  },
  "models": [
    {
      "modelId": "anthropic/claude-sonnet-4-6",
      "context": 400000,
      "output": 64000
    }
  ]
}
```

`GET /api/settings/token-limits` returns the current setting in the same shape. `PUT` replaces the whole setting and returns `400` with a validation message if any value is invalid, a model ID is unknown, or a model appears twice.

## Related pages

* [Configure Model Providers](/admin/model-providers) covers the provider and model definitions these limits apply to.
* [Override token limits for a session](/user/session-token-limits) covers how users adjust limits for a single session.


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