> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.beatapi.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.beatapi.io/_mcp/server.

# Why does a chat return 402 insufficient_credits when my balance is still positive?

> BeatAPI estimates required balance from max_tokens before calling a model. Lowering Max Response Length from 32000+ to 2000-4096 resolves false 402 errors in roleplay clients.

BeatAPI estimates the maximum cost of a text request from `max_tokens` before forwarding the request to the model. When a roleplay preset sends a large `max_tokens` value such as `32000`, `65536`, or `128000`, BeatAPI's pre-check can exceed a small positive USD balance and return `402 insufficient_credits` even if the actual reply would be short.

## How to fix it

1. **Lower `max_tokens` (Max Response Length) in your client preset**:
   * Standard roleplay dialogue: set `2000`–`4096`.
   * Reasoning models: set `4096`–`8192`.
   * When your balance is under a few dollars, avoid setting JanitorAI's **Max new tokens** to `0` (unlimited) or maxing out SillyTavern's response slider.
2. **Check the API key's own quota cap**: A `402 insufficient_credits` body containing `This API key's remaining quota is below the price of this request` means that specific key hit its quota limit in [Dashboard → API Keys](https://beatapi.io/dashboard/apikeys), even when total account balance is higher. Raise that key's quota or switch keys.
3. **Verify the selected model ID**: Flagship models charge higher output rates per million tokens, so a `65536`-token pre-check reserves a larger balance than a flash-tier model. Check the active model ID against the [pricing page](https://beatapi.io/pricing).

## Cost benefit of capping `max_tokens`

Output tokens cost three to five times more than input tokens on most text models. Setting `max_tokens` to the reply length you actually need keeps small balances past BeatAPI's pre-check and caps runaway outputs.

## Related

* [Cost optimization](/faq/cost-optimization)
* [Back to AI Models questions](/faq/models)