Safeguard
Developer Tools•

Does the max output setting count toward your AI rate limit?

It depends on the provider. One counts the larger of max tokens and an estimate; another counts only tokens actually generated. How to set it safely.

Safeguard Security Team
8 min read

It depends on the provider. OpenAI's guide says your usage counts against the larger of the max tokens value and an estimate based on request length, so set it near your expected response. Anthropic's documentation says its max tokens setting does not factor into output token rate limit calculations.

Two documented behaviors

Read these side by side, because they lead to opposite habits.

Provider documentationBehavior
OpenAI rate limits guideUsage counts against the larger of max tokens and an estimate from request length. Set it close to your expected response size.
Anthropic rate limits pageOutput token limits are evaluated as tokens are produced, counting only actual tokens generated. Max tokens does not factor in, so a higher value has no rate limit downside.

So the same habit, setting a very high ceiling to be safe, hurts you on one and is harmless on the other for limits.

Limits are not the only reason to set it

Even where the rate limit ignores the ceiling, other reasons remain:

  1. Cost control. A ceiling bounds the worst case for a single request, such as a runaway generation. Generation is billed by what is produced, so a ceiling is a cap on damage.
  2. Latency. Long outputs take longer. OpenAI's latency guide says generating tokens is almost always the highest latency step.
  3. Context room. Input plus the ceiling interacts with the window. The Anthropic context documentation says that on newer models, if input plus the ceiling exceeds the window, the request is still accepted and generation stops with a specific stop reason when it reaches the limit.
  4. Reasoning. With thinking enabled, thinking tokens are a subset of the max tokens value and bill as output, per the Anthropic documentation, so a ceiling that is too low can cut an answer short.

How to choose a value

  1. Measure real outputs for the task over a few hundred requests.
  2. Look at a high percentile, not the average.
  3. Set the ceiling a little above that, with room for reasoning if you use it.
  4. Handle the stop reason that signals truncation, so a cut-off answer is not treated as finished.
  5. Revisit it after any prompt or model change, since output length shifts.

A worked example in words

Suppose a task usually produces a few hundred tokens, and the longest you have seen is about a thousand. On a provider that counts the larger of the ceiling and an estimate, a ceiling of several thousand reserves limit capacity you never use, which lowers your effective throughput. A ceiling just above a thousand is tighter. On a provider that counts only generated tokens, the throughput effect disappears, but the tighter ceiling still limits the worst case.

For agent loops

A looping agent can produce many long outputs. A reasonable ceiling per call, plus a cap on iterations and a spend limit, gives three layers. See how agent bills balloon and what is an AI API rate limit.

Worked example: choosing a ceiling from data

The numbers are illustrative. A team samples 500 production responses for a drafting feature and finds a median of 350 output tokens, a 95th percentile of 900 and a maximum of 1,400. They also use reasoning, which adds a variable amount.

Candidate ceilingConsequence
500Cuts off many answers, a quality bug
1,000Covers p95, truncates a few long ones
2,000Covers everything, leaves room for reasoning
16,000Bounds nothing in practice, and on a provider that counts the larger of ceiling and estimate, reserves limit capacity

They choose 2,000 plus the reasoning allowance, handle the truncation stop reason, and review monthly. On a provider that counts only generated tokens, the ceiling has no throughput effect, but it still bounds a runaway.

Handling truncation

  1. Read the stop reason on every response.
  2. If it signals the ceiling was reached, mark the answer incomplete.
  3. Either request a continuation, retry with a higher ceiling, or show the user a notice.
  4. Alert if truncations exceed a small share of requests, since that suggests the ceiling is too low or a prompt change made answers longer.

Per environment settings

Set a lower ceiling in tests and evaluation runs to save cost, and a tuned one in production. Keep the values in configuration, not hard coded, and log the ceiling used per request so you can explain odd bills later.

Reasoning models and the ceiling

When a model reasons before answering, the reasoning counts as output on the provider documented here, and it comes out of the same ceiling. A ceiling that was fine for a short answer can be too low once reasoning is switched on, producing empty or cut-off replies. Whenever you change reasoning settings, rerun your length sample and raise the ceiling if truncations rise. Keep the sample as a regression test so the next change is caught the same way.

Testing the behavior on your account

Do not rely on documentation alone for a setting that affects throughput. Run a small test in a throwaway workspace. Send a batch of identical short requests with a low ceiling and note how many succeed per minute before throttling. Repeat with a very high ceiling. If the counts differ, your provider reserves capacity from the ceiling. If they match, it does not. Record the result and the date.

Repeat after a model change or after the provider updates its rate limit documentation, since such rules can change. A ten minute test is cheaper than a launch day surprise.

What this means for you

If you set the output ceiling without thinking, you might be reserving capacity you never use, or you might be cutting answers short. Both are avoidable with a small amount of data. Look at how long your real answers are, pick a ceiling just above the long end, and handle the case where an answer hits it.

On a provider that counts the ceiling toward your limit, a lower setting gives you more throughput. On a provider that does not, the ceiling is mostly a cost and latency guard. Either way, a sensible number is better than an arbitrary large one.

Common mistakes

The first mistake is copying a very large ceiling from an example without asking what it does. The second is setting it so low that answers are truncated, then treating the truncated text as a complete result. The third is forgetting that reasoning shares the ceiling on some setups, so an answer can come back empty when the reasoning used it all. The fourth is never revisiting the number after a prompt change that makes answers longer. The fifth is assuming that what one provider documents holds for another.

A step by step way to choose

  1. Sample a few hundred real responses for the task.
  2. Record the median, the 95th percentile and the maximum.
  3. Add room for reasoning if you use it.
  4. Set the ceiling a little above the 95th percentile.
  5. Add code that reads the stop reason and flags truncated answers.
  6. Alert if truncations rise above a small share of requests.
  7. Re-sample after every prompt or model change.

This takes an hour and avoids both the wasted capacity and the cut-off answers.

Try it yourself

Click through it at your own pace, or open it full screen. It shows a rule that stops a change when a threshold is crossed. A max output setting is a similar guard: a ceiling agreed in advance that bounds the worst case.

Quick check

Should I always set the highest max tokens value?

No. On some providers it can reserve limit capacity, and everywhere a lower ceiling bounds the worst case for cost and latency.

What happens if the ceiling is too low?

The answer can be cut off. Check the stop reason in the response and treat truncation as an error condition.

Does thinking count toward the ceiling?

On the provider documented here, yes. Thinking tokens are a subset of max tokens and bill as output.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.