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:
- A per-session override, if the user set one when creating the session.
- A per-model override from the Token Limits settings.
- 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
- Sign in to Cake Agents as an administrator.
- Open
Settings → Organization → Providers.
- Scroll to the
Token Limits section.
- Enter a global
Context Limit and Output Limit.
- Optionally add per-model overrides for models that need different values.
- 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.
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.
API
You can read and replace the organization’s token limits programmatically:
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