fishaudio/fish-speech · warning · HTTPException
Text is too long, max length is {app_state.max_text_length}
Error message
Text is too long, max length is {app_state.max_text_length} What it means
Raised by the TTS endpoint when the submitted text exceeds the server-configured max_text_length limit. It is an HTTP 400 BAD_REQUEST returned before any model inference runs. The limit exists to bound GPU memory usage and generation time.
Source
Thrown at tools/server/views.py:160
HTTPStatus.INTERNAL_SERVER_ERROR, content="Failed to decode tokens to audio"
)
@routes.http.post("/v1/tts")
async def tts(req: Annotated[ServeTTSRequest, Body(exclusive=True)]):
"""
Generate speech from text using TTS model.
"""
try:
# Get the model from the app
app_state = request.app.state
model_manager: ModelManager = app_state.model_manager
engine = model_manager.tts_inference_engine
sample_rate = engine.decoder_model.sample_rate
# Check if the text is too long
if app_state.max_text_length > 0 and len(req.text) > app_state.max_text_length:
raise HTTPException(
HTTPStatus.BAD_REQUEST,
content=f"Text is too long, max length is {app_state.max_text_length}",
)
# Check if streaming is enabled
if req.streaming and req.format != "wav":
raise HTTPException(
HTTPStatus.BAD_REQUEST,
content="Streaming only supports WAV format",
)
# Perform TTS
if req.streaming:
return StreamResponse(
iterable=inference_async(req, engine),
headers={
"Content-Disposition": f"attachment; filename=audio.{req.format}",
},View on GitHub (pinned to befe400174)
Solutions
- Split the text into chunks under max_text_length and synthesize each separately, concatenating the WAV/PCM output.
- Increase max_text_length in the server configuration (e.g. config file or KOKORO_TTS_MAX_TEXT_LENGTH env var) if your hardware allows longer generations.
- Set max_text_length to 0 to disable the limit entirely (only if you accept unbounded generation cost).
Example fix
# before
resp = requests.post(url, json={"text": long_article})
# after
for chunk in chunks(long_article, max_len - 1):
resp = requests.post(url, json={"text": chunk})
... Defensive patterns
Strategy: validation
Validate before calling
max_len = get_server_config().max_text_length
text = "..."
assert max_len == 0 or len(text) <= max_len, f"text {len(text)} > {max_len}" Prevention
- Fetch or mirror max_text_length in the client config
- Chunk long documents to just under the limit and concatenate WAV output
When it happens
Trigger: POST /v1/tts (or OpenAI-compatible /v1/audio/speech) with req.text longer than app_state.max_text_length (when max_text_length > 0). Long documents, unsubtitled full articles, or clients not splitting text trigger it.
Common situations: Default max_text_length too low for batch narration workloads; clients pasting entire articles; changing max_text_length config but not restarting; misunderstanding that the limit counts characters, not tokens.
Related errors
- Streaming only supports WAV format
- Number of prompt text ({len(prompt_text)}) and prompt audio
- Directory {path} does not exist.
- No audio generated, please check the input text.
AI-assisted analysis of fishaudio/fish-speech@befe400174 (2026-08-27).
Data as JSON: /api/errors/4c9e02809bb76255.
Report an issue: GitHub.