Skip to content

fix(translation): reduce Anthropic token fallback - #282

Merged
nachiketb-nvidia merged 1 commit into
mainfrom
fix/anthropic-max-tokens-fallback
Aug 4, 2026
Merged

fix(translation): reduce Anthropic token fallback#282
nachiketb-nvidia merged 1 commit into
mainfrom
fix/anthropic-max-tokens-fallback

Conversation

@nachiketb-nvidia

@nachiketb-nvidia nachiketb-nvidia commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

What

Reduce the implicit Anthropic max_tokens fallback from 128,000 to 64,000 when an OpenAI-format request omits both max_tokens and max_completion_tokens.

Why

Omitting an output limit is valid for OpenAI clients, while Anthropic Messages requires max_tokens. Switchyard therefore needs to supply a fallback during cross-format translation.

The existing fallback used 128,000, which is the model's absolute output ceiling rather than a conservative default. Anthropic counts both adaptive reasoning and visible response tokens against this limit. Combined with reasoning_effort=max, the implicit 128K budget can allow requests to run beyond the 600-second upstream deadline and return HTTP 500.

64K matches Claude Code's default for recognized modern Opus models and still leaves substantial room for agentic and coding output without automatically granting every uncapped request the maximum possible budget.

Tracks SWITCH-1194.

How

  • Change only the Anthropic fallback from 128K to 64K.
  • Preserve explicit caller-provided token limits unchanged.
  • Align the existing fallback assertions and remove the stale claim that oversizing is harmless.

What to review

  • Whether 64K is the appropriate provider-neutral fallback.
  • That explicitly supplied output limits still bypass the fallback.

Validation

cargo test -p switchyard-translation openai_request_to_anthropic_adds_required_default_max_tokens
cargo test -p switchyard-components anthropic_translates_responses_requests_with_default_max_tokens

Summary by CodeRabbit

  • Behavior Changes
    • Anthropic requests now default to a maximum of 64,000 output tokens when no limit is specified.
    • Updated OpenAI-to-Anthropic translation behavior and expectations to reflect the new default.

Signed-off-by: nachiketb <nachiketb@nvidia.com>
@nachiketb-nvidia
nachiketb-nvidia requested a review from a team as a code owner August 4, 2026 17:29
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 5acd1803-976d-410b-b0ba-e5ca739cf247

📥 Commits

Reviewing files that changed from the base of the PR and between 8928163 and d4d87cb.

📒 Files selected for processing (4)
  • crates/switchyard-components/tests/adversarial_native_backends.rs
  • crates/switchyard-translation/src/codecs/anthropic/buffered.rs
  • crates/switchyard-translation/tests/request_translation.rs
  • tests/test_translation_engine_chaos.py

Walkthrough

Anthropic request encoding now defaults omitted max_tokens to 64,000 instead of 128,000. Rust and Python translation tests now verify the updated value.

Changes

Anthropic request translation

Layer / File(s) Summary
Update Anthropic fallback
crates/switchyard-translation/src/codecs/anthropic/buffered.rs
Anthropic request encoding now emits 64,000 when max_tokens is not specified.
Align translation expectations
crates/switchyard-components/tests/adversarial_native_backends.rs, crates/switchyard-translation/tests/request_translation.rs, tests/test_translation_engine_chaos.py
Rust and Python tests now expect the 64,000 default. The Python test documentation matches the new value.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Poem

A rabbit checks the token gate,
Sixty-four thousand marks the fate.
Old numbers hop away,
New tests cheer today.
The messages translate straight.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: reducing the Anthropic token fallback in translation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Comment @coderabbitai help to get the list of available commands.

@nachiketb-nvidia
nachiketb-nvidia enabled auto-merge (squash) August 4, 2026 17:42
@nachiketb-nvidia
nachiketb-nvidia merged commit a5fefa7 into main Aug 4, 2026
18 checks passed
@nachiketb-nvidia
nachiketb-nvidia deleted the fix/anthropic-max-tokens-fallback branch August 4, 2026 17:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants