{"slug": "how-to-set-max-output-tokens-for-llm-calls-without-cutting-answers-off", "title": "How to Set Max Output Tokens for LLM Calls Without Cutting Answers Off", "summary": "Teams that set a fixed max_tokens cap of 1,024 or 4,096 as a first-week cost guard can silently ship truncated answers and broken JSON, because a cap is a ceiling rather than a charge and no error fires when a response is cut off, according to a Startup Fortune guide on sizing LLM output limits. The guide advises logging output token counts and stop reasons per route — Anthropic reports stop_reason max_tokens, OpenAI reports finish_reason length and Google's Gemini API reports MAX_TOKENS — then setting each endpoint's limit at roughly the 99th percentile of logged output lengths plus 20 to 50 percent headroom. It warns that reasoning models spend the same budget on hidden thinking, so a cap that worked on a plain model can return an empty answer, and that truncated JSON should be retried or failed loudly rather than repaired and passed downstream.", "body_md": "*A token cap set to save money can quietly ship half-finished answers and broken JSON, and no error ever fires. Fixing it takes a week of logs, one extra check and a few lines of code.*\n\n- A max_tokens limit is a ceiling, not a charge, so a higher cap costs you nothing on answers that finish early.\n- Anthropic reports a cut-off reply as stop_reason max_tokens, OpenAI as finish_reason length and Google's Gemini API as MAX_TOKENS, and your code has to read that field on every call.\n- Size the limit from your own logged output lengths: roughly the 99th percentile plus 20 to 50 percent headroom, set per endpoint instead of one global number.\n- Reasoning models spend the same budget on hidden thinking, so a cap that worked on a plain model can return an empty answer on a reasoning one.\n- Truncated JSON should be retried or failed loudly, never repaired and passed downstream.\n\nIf you want to know how to set max output tokens for LLM calls, start with a number most dashboards never show you: the share of responses that ended because they hit the cap. Request counts, latency and spend all look healthy when a model stops mid-sentence. The call succeeds, the status code is 200, and the customer reads half an answer.\n\nThat is the whole problem. Most teams pick a cap once, usually 1,024 or 4,096, as a cost guard during the first week of a build, and never look at it again. Then the prompts grow, someone adds a reasoning model, a summary route starts getting longer documents, and a slice of answers begins to get chopped off. Nobody pages anyone, because nothing failed.\n\nEvery major provider tells you when it cut a response short. You just have to look. In Anthropic's Messages API the response carries a stop_reason field, and the value max_tokens means the model hit your limit, not that it finished. OpenAI's chat completions return finish_reason, and the value length means the same thing. Google's Gemini API reports a finish reason of MAX_TOKENS. Three vendors, three spellings, one meaning: the answer you got is not the answer the model was writing.\n\nAnthropic's documentation is blunt that max_tokens is a hard stop and that the model may be cut off mid-word or mid-sentence. It is also a required parameter on the Messages API, which means every Claude integration has someone's guess baked into it. If you stream, the stop reason arrives late, in the message_delta event near the end, so a streaming UI will happily paint half an answer before your code ever learns it was cut.\n\n[How to Request LLM API Rate Limit Increase Before Your Launch Day](https://startupfortune.com/how-to-request-llm-api-rate-limit-increase-before-your-launch-day/)\n\nA launch-day forecast of 20,000 signups can mean roughly 5.4 million tokens per minute at the worst minute, plus a spend cap that a single busy hour can empty. Here is the formula, the four-line request and the schedule to work back from launch. - [request LLM API rate limit increase](https://startupfortune.com/how-to-request-llm-api-rate-limit-increase-before-your-launch-day/) - [prepare API capacity before launch day](https://startupfortune.com/how-to-request-llm-api-rate-limit-increase-before-your-launch-day/)\n\nPlain prose truncation is bad. Structured output truncation is worse. A JSON object cut off after the third field does not parse, and if your pipeline swallows the parse error and moves on, you lose the record without a trace. A string that ends mid-sentence in a customer email draft is just as bad, and harder to catch because nothing downstream will throw.\n\n## How to set max output tokens for LLM routes from real percentiles\n\nStop guessing and measure. Every response includes a usage block with the number of output tokens it generated, called output_tokens on Anthropic and completion_tokens on OpenAI. Log that number with a route name, a model name and the stop reason. If you already log latency, this is one more column.\n\nAfter a week of real traffic, pull the distribution per route, not for the whole app. A classification endpoint that returns one label and a document summarizer have nothing in common, and a single global cap will be wrong for at least one of them. For each route, look at the median, the 95th percentile, the 99th and the maximum. The median tells you what normal looks like. The tail tells you where the cap belongs.\n\nA workable rule: set the limit at the 99th percentile of observed output length, then add 20 to 50 percent headroom on top. Pick the larger end of that range if the route returns structured data or long-form text, because a cut-off there does more damage. Pick the smaller end for short, tightly constrained outputs like labels and yes-or-no decisions, where anything long is already a sign the model went off script.\n\nSay a support-reply route logs a median of 180 tokens, a 95th percentile of 420, a 99th of 610 and a maximum of 1,900. A cap of 1,024 looks generous next to the median, yet the 99th percentile plus 50 percent is about 915, so 1,024 sits right where you would put it. The single 1,900-token outlier is the one that matters most. Open it. It is usually a runaway repetition loop or a user who pasted something strange, and that is exactly the kind of response you want a cap to stop.\n\nTwo things trip people up when they set the number. First, counts are model-specific. Tokenizers differ between vendors and between model generations, and code, tables and non-English text usually burn far more tokens than the same word count in plain English. When you switch models, your percentiles are stale. Pull them again.\n\nSecond, the cap and the prompt are linked. If you tell the model to answer in under 150 words and then set a cap of 100 tokens, you have built a collision. Pick the length you want in the prompt, then set the cap well above it, so the instruction does the shaping and the cap only catches failures.\n\n[Build an LLM model deprecation migration plan before the cutoff week](https://startupfortune.com/build-an-llm-model-deprecation-migration-plan-before-the-cutoff-week/)\n\nAn LLM model deprecation migration plan fits in one runbook: pinned snapshot IDs, a 150 to 300 case golden set, a week of shadow traffic, a cost check on real token counts, and a rollback flag kept live for two weeks after cutover. - [how to plan an LLM model migration](https://startupfortune.com/build-an-llm-model-deprecation-migration-plan-before-the-cutoff-week/) - [LLM deprecation migration plan before cutoff](https://startupfortune.com/build-an-llm-model-deprecation-migration-plan-before-the-cutoff-week/)\n\n## Reasoning models spend your budget before you see a word\n\nThe most common new way to get this wrong involves thinking. On reasoning models, the hidden chain of thought is billed as output and counts against the same limit. OpenAI's documentation says reasoning tokens count toward max_completion_tokens, and warns that a low cap can be used up on reasoning, leaving you with an empty visible answer and a finish reason of length. Anthropic's extended thinking has a similar structure: you set a thinking budget, and that budget has to sit below max_tokens, with the answer drawn from whatever is left. Google's Gemini thinking models share their output cap with thinking in the same way.\n\nSo the cap that worked fine on your old model can break on its reasoning successor without a single line of code changing. If a route got slower and began returning blank or clipped answers after a model upgrade, check the reasoning budget first. The usual fix is to raise the cap so it covers the thinking budget plus the answer you want, then lower the thinking effort if the bill climbs.\n\n## Stop_reason max_tokens handling in code you can ship this week\n\nThe minimum viable version is one branch. After every call, read the stop reason. If it says the model hit the limit, do not treat the text as a finished answer. Route it to a handler. That handler can do one of three things: continue, retry or fail. Which one you pick depends on what the output is for.\n\nWrap this in a single function that every call in your codebase passes through. If each team calls the vendor SDK directly, every one of them will forget the check in a different place. One wrapper that returns the text plus a boolean for truncation gives you one place to fix, one place to log, and one place to add a metric.\n\nThat metric is the whole point. Emit a counter every time a response comes back truncated, tagged with route and model. Then alert on the rate. A healthy route should sit at or very near zero. If you see 0.5 percent or more of a route's calls ending at the cap, either the limit is too tight or the prompt is inviting long answers, and both are worth knowing about this week and not after a customer complains.\n\n## Recovering: continue, retry or fail loudly\n\nFor prose, continuing is often the cheapest recovery. Append the partial answer as an assistant turn and ask the model to carry on from exactly where it stopped, then stitch the two pieces together. It works well for long summaries and drafts. Watch for seams, because the model can repeat the last sentence or restart a list, and keep a hard limit on how many continuations you allow so a runaway loop can't stack up cost.\n\nFor structured output, do not continue and do not try to repair. Closing the missing brackets yourself produces JSON that parses and is wrong, which is worse than an error. Retry the call with a higher cap, once, and if that is also cut off, fail loudly. Raise an exception, send the item to a review queue and count it. A visible failure is something a team can fix. A silently half-complete record is something that shows up three weeks later in a finance reconciliation.\n\nProvider features help here, though they are not a substitute for the check. Structured output modes constrain the model to a schema, which cuts the rate of malformed JSON from sloppy generation. They cannot stop a hard cut at the token limit, and a schema-constrained response that hits the cap is still incomplete. Read the stop reason either way.\n\nOne more small habit pays off: put the important content first. If you ask for an answer followed by a long explanation, a cut-off clips the explanation and leaves the answer intact. If the explanation comes first, a cut-off removes the answer. Order the output so that losing the tail costs you the least.\n\n## LLM output token limit cost control without the truncation tax\n\nHere is the part that surprises people: a higher cap does not cost more by itself. You pay for the tokens the model generates, not for the ceiling you set. A response that needs 200 tokens costs the same with a cap of 500 or a cap of 8,000. The cap only changes the bill when the model would have kept going.\n\nThat reframes the job. The cap is not your cost control for normal traffic. It is insurance against the abnormal cases: the repetition loop, the prompt injection that asks for a novel, the user who uploads a 300-page file. For those, the cap bounds the worst case per call. At an illustrative $15 per million output tokens, a 4,096-token cap limits a single runaway call to about six cents. Multiply by your request volume to see the ceiling on a bad day, and decide whether that number is acceptable.\n\nIf that ceiling is too high, the answer is a smarter route-level cap, not a stingy global one. Give the classification route a cap of 50 and the document route a cap of 2,000. Per-route limits are where real savings live, because each cap can sit just above that route's own tail. Add a spend alert at the account or project level as a second guard, since a token cap protects one call and does nothing about a loop that fires a million of them.\n\nOutput tokens are also priced above input tokens on the major APIs, typically by a multiple, so trimming verbose answers saves more than trimming long prompts. The cheapest lever is the prompt. Ask for terse output, a fixed format and no preamble, and the median drops without any cap involved. Then the cap stays where it belongs, catching only the cases that go wrong.\n\nA short audit you can run in an afternoon: pull the last seven days of calls, group by route, count how many ended with the max-tokens stop reason, and sort by that rate. The routes at the top are shipping broken answers right now. Raise their caps, add the wrapper, and rerun the same query next Friday. If every route reads zero, you have lost nothing but an hour.\n\n**Also read:** [How Much Should I Budget for AI Agent Evals Before Test Runs Eat Your Margin](https://startupfortune.com/how-much-should-i-budget-for-ai-agent-evals-before-test-runs-eat-your-margin/) • [How to Request LLM API Rate Limit Increase Before Your Launch Day](https://startupfortune.com/how-to-request-llm-api-rate-limit-increase-before-your-launch-day/) • [How to Cap AI Agent Structured Output Validation Retry Before JSON Breaks](https://startupfortune.com/how-to-cap-ai-agent-structured-output-validation-retry-before-json-breaks/)\n\n*This article is posted in [AI News](https://startupfortune.com/category/ai/), check it out for more related stories.*\n\n## Join the discussion\n\n[Open in the community →](https://startupfortune.com/community/)\n\nAlmost there. Sign in and your reply posts straight away.", "url": "https://wpnews.pro/news/how-to-set-max-output-tokens-for-llm-calls-without-cutting-answers-off", "canonical_source": "https://startupfortune.com/how-to-set-max-output-tokens-for-llm-calls-without-cutting-answers-off/", "published_at": "2026-12-04 15:08:01+00:00", "updated_at": "2026-12-04 15:16:04.226595+00:00", "lang": "en", "topics": ["large-language-models", "ai-tools", "developer-tools", "ai-agents"], "entities": ["Anthropic", "OpenAI", "Google", "Gemini API", "Claude", "Startup Fortune"], "also_reported_by": [], "takeaway": "Set max_tokens per endpoint at roughly the 99th percentile of logged output_tokens plus 20–50 percent headroom, and check stop_reason/finish_reason on every call, since a higher cap costs nothing on answers that finish early.", "recommendation": {"advice": "Log output token counts and stop reasons per route for a week, then set each endpoint's max_tokens at the 99th percentile plus 20–50 percent headroom and retry or fail loudly on truncated JSON.", "playbook": "llm-cost", "playbook_url": "https://wpnews.pro/playbooks/llm-cost"}, "alternates": {"html": "https://wpnews.pro/news/how-to-set-max-output-tokens-for-llm-calls-without-cutting-answers-off", "markdown": "https://wpnews.pro/news/how-to-set-max-output-tokens-for-llm-calls-without-cutting-answers-off.md", "text": "https://wpnews.pro/news/how-to-set-max-output-tokens-for-llm-calls-without-cutting-answers-off.txt", "jsonld": "https://wpnews.pro/news/how-to-set-max-output-tokens-for-llm-calls-without-cutting-answers-off.jsonld"}}