Why do long roleplay replies time out or cut off mid-sentence?
A roleplay reply that stops mid-sentence comes from one of two causes: a network timeout (the connection closed before the model finished) or an output token cap (the model reached max_tokens and stopped). Identifying which cause occurred points directly to the right setting.
1. Fix network timeouts, Failed to fetch, and No response from bot
When a client displays a timeout, 502/504, A network error occurred / Failed to fetch (unk), PROXY ERROR: No response from bot, or an empty bubble after waiting over a minute, the connection dropped before completion.
- Use
https://direct.beatapi.io/v1for text chat:https://api.beatapi.ioruns behind Cloudflare and inherits Cloudflare’s 100-second wait limit on non-streaming responses.https://direct.beatapi.io/v1uses the same key, models, and prices without the 100-second ceiling. - Use
https://api-asia.beatapi.io/v1in East and Southeast Asia: Ifdirect.beatapi.iodrops packets on mobile or residential networks in Asia, switch tohttps://api-asia.beatapi.io/v1, which also bypasses the 100-second limit. - Enable streaming (
stream: true): Streaming sends tokens over server-sent events as soon as generation starts, keeping the HTTP connection active during long story turns.
2. Fix max_tokens truncation
When the reply ends cleanly mid-sentence with no network error and the raw response reports finish_reason: "length" (or stop_reason: "max_tokens" on Claude), the model hit your configured output cap.
- Set
max_tokensto2000–4096for standard roleplay dialogue. - Set
max_tokensto4096–8192for reasoning models: Reasoning tokens count towardmax_tokens. Evenhy4-flash-freespends roughly 230 reasoning tokens on a one-sentence reply, so reasoning models needmax_tokensof at least2000. - Keep
max_tokensbelow32000on small balances: Oversized caps can trigger402 insufficient_creditsduring BeatAPI’s balance pre-check; see 402 error from oversized max_tokens.

