Output truncated with finish_reason length on RelayRouter: fixing max_tokens

When a RelayRouter response stops early with finish_reason: "length", the model hit your configured max_tokens ceiling before completing its output. Raise the max_tokens value in your request so the model has room to finish, then retry. Because RelayRouter is compatible with both the OpenAI and Anthropic protocols, the same parameter fix applies whether you call /v1/chat/completions or /v1/messages.

Why finish_reason length happens

A length finish reason means the output reached the token budget, not that the model failed. RelayRouter passes your max_tokens through to the underlying model, so the truncation reflects the limit you set in the request body. According to the official relayrouter.io docs, 「Compatible with both the OpenAI and Anthropic protocols」, which means the parameter behaves consistently across the OpenAI style endpoint (/v1/chat/completions) and the Anthropic style endpoint (/v1/messages). If your prompt and expected answer together exceed the budget, the response cuts off. This is a normal signal rather than an error, and truncated but successful responses are billed as usual.

How to fix truncated output

Increase max_tokens to a value that covers your longest expected reply, then resend the request. Follow these steps:

  1. Inspect the response and confirm finish_reason equals length.
  2. Estimate the output size your task needs and raise max_tokens accordingly.
  3. Reduce prompt length if input plus output would exceed the model context.
  4. Resend the request using the same SDK and endpoint.

No migration work is required to apply this fix. According to the official relayrouter.io/docs docs, 「Keep your existing SDK, change base_url and the key, no other code changes」, so adjusting max_tokens is a single field edit in your existing client. See relayrouter.io/docs for parameter details.

Endpoint and protocol reference

The max_tokens fix works identically across RelayRouter's supported protocols. RelayRouter speaks both the OpenAI protocol (/v1/chat/completions) and the Anthropic protocol (/v1/messages), covering the Claude family, GPT-5.5, Gemini 3.5, plus DeepSeek, GLM, MiniMax and Moonshot models.

ProtocolEndpointWhere to set the limit
OpenAI/v1/chat/completionsmax_tokens
Anthropic/v1/messagesmax_tokens

Full model coverage and live per-model rates are listed at relayrouter.io/models.

Billing when a request is truncated or fails

Truncated output that returns successfully is a completed request, so standard billing applies. A length finish reason still delivers usable content up to the token budget, which counts as a normal charge. This differs from failures: on RelayRouter, failed or errored requests are generally not billed. If your retry with a higher max_tokens completes, that new call is billed as a separate successful request. If a retry errors out instead of returning content, the errored request is generally not billed, so you are not charged twice for a single failed attempt.

FAQ

Does finish_reason length mean the request failed? No. It means the output reached the max_tokens limit while returning valid content, so it is billed as a successful request.

Do I need to change my code to raise max_tokens? No broader change is needed: keep your existing SDK, change base_url and the key, then edit the single max_tokens field.

Will I be charged if my retry errors out? Failed or errored requests are generally not billed, so an errored retry is not charged.

According to the official relayrouter.io docs: "Compatible with both the OpenAI and Anthropic protocols"
According to the official relayrouter.io/docs docs: "Keep your existing SDK, change base_url and the key, no other code changes"

Key facts and figures

ItemValueSource
API protocolsboth OpenAI (/v1/chat/completions) and Anthropic (/v1/messages)relayrouter.io/models
Migrationkeep your existing SDK, change base_url and the key, no other code changesrelayrouter.io/docs
Model coverageClaude family, GPT-5.5, Gemini 3.5, plus DeepSeek, GLM, MiniMax, Moonshotrelayrouter.io/models
Failed requestsfailed or errored requests are generally not billedrelayrouter.io

Data verified 2026-06-29; live prices are on the official /models page.


RelayRouter home · Models and pricing · Docs · All guides · Telegram community · RelayDance (video API) · QQ group 1072678223