You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(anthropic): default max_tokens to the model's output ceiling (#849)
Anthropic's Messages API requires `max_tokens`, so the text adapter must
always send a value. It previously hard-coded `?? 1024` when the caller
didn't pass one, silently truncating any non-trivial generation mid-stream
with `stop_reason: "max_tokens"`.
Now default to the resolved model's real `max_output_tokens` from model-meta
(e.g. 64K Sonnet, 128K Opus), falling back to 64K for unrecognized ids.
`max_tokens` is a ceiling, not a reservation, so this costs nothing extra.
Also log a warning when a response is truncated while using the defaulted
cap, so it isn't silently read as the model "doing nothing"; callers that set
`max_tokens` explicitly are unaffected.
The new id -> max_output_tokens map is kept in lockstep with ANTHROPIC_MODELS
by `scripts/sync-provider-models.ts`, so a freshly-synced model resolves to
its real ceiling rather than the fallback.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: docs/adapters/anthropic.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -136,6 +136,10 @@ const stream = chat({
136
136
137
137
> If you previously passed `temperature` / `topP` / `maxTokens` at the root of `chat()`, see [Moving Sampling Options into modelOptions](../migration/sampling-options-to-model-options).
138
138
139
+
#### `max_tokens` default
140
+
141
+
Anthropic's Messages API _requires_`max_tokens` on every request, so the adapter always sends a value. When you don't set `modelOptions.max_tokens`, it defaults to the selected model's full output ceiling (`max_output_tokens` from the model metadata — e.g. 64K for Sonnet, 128K for Opus), falling back to a safe constant for unrecognized models. `max_tokens` is a ceiling, not a reservation — billing is on tokens actually generated — so this default costs nothing extra and avoids the silent mid-response truncation (`stop_reason: "max_tokens"`) that a low default would cause. Set `max_tokens` explicitly only when you want to _cap_ output below the model ceiling. If a response is truncated while using the default cap, the adapter logs a warning (visible with [debug logging](../advanced/debug-logging) enabled).
142
+
139
143
### Thinking (Extended Thinking)
140
144
141
145
Enable extended thinking with a token budget. This allows Claude to show its reasoning process, which is streamed as `thinking` chunks:
`anthropic response truncated at the default max_tokens (${defaultedMaxTokens}) for model=${model}; pass maxTokens (or modelOptions.max_tokens) to raise the output ceiling`,
0 commit comments