Skip to content

Switchyard lets LLM applications route traffic across models and providers while preserving native OpenAI and Anthropic API compatibility - enabling flexible model selection, benchmarking, and cost/performance optimization.

Rust

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

nachiketb-nvidiaa5fefa7f5802
diff --git a/crates/switchyard-components/tests/adversarial_native_backends.rs b/crates/switchyard-components/tests/adversarial_native_backends.rs
index d455654ee..3cc581389 100644
--- a/crates/switchyard-components/tests/adversarial_native_backends.rs
+++ b/crates/switchyard-components/tests/adversarial_native_backends.rs
@@ -892,7 +892,7 @@ async fn anthropic_translates_responses_requests_with_default_max_tokens() -> Re
assert_eq!(ctx.inbound_format, Some(ChatRequestType::OpenAiResponses));
assert_eq!(request.body["model"], "target-claude");
- assert_eq!(request.body["max_tokens"], 128000);
+ assert_eq!(request.body["max_tokens"], 64000);
assert_eq!(request.body["messages"][0]["role"], "user");
assert_eq!(request.body["messages"][0]["content"], "translate me");
Ok(())
diff --git a/crates/switchyard-translation/src/codecs/anthropic/buffered.rs b/crates/switchyard-translation/src/codecs/anthropic/buffered.rs
index 5217ce987..b45902a51 100644
--- a/crates/switchyard-translation/src/codecs/anthropic/buffered.rs
+++ b/crates/switchyard-translation/src/codecs/anthropic/buffered.rs
@@ -204,7 +204,7 @@ impl FormatCodec for AnthropicMessagesCodec {
if let Some(max_tokens) = request.output.max_output_tokens {
body.insert("max_tokens".to_string(), json!(max_tokens));
} else {
- body.insert("max_tokens".to_string(), json!(128_000));
+ body.insert("max_tokens".to_string(), json!(64_000));
}
if let Some(value) = request.sampling.temperature {
body.insert("temperature".to_string(), json!(value));
diff --git a/crates/switchyard-translation/tests/request_translation.rs b/crates/switchyard-translation/tests/request_translation.rs
index dafcc26ff..37d9fd8ec 100644
--- a/crates/switchyard-translation/tests/request_translation.rs
+++ b/crates/switchyard-translation/tests/request_translation.rs
@@ -994,7 +994,7 @@ fn openai_request_to_anthropic_adds_required_default_max_tokens() -> TestResult
)?
.body;
- assert_eq!(output["max_tokens"], 128_000);
+ assert_eq!(output["max_tokens"], 64_000);
Ok(())
}
diff --git a/tests/test_translation_engine_chaos.py b/tests/test_translation_engine_chaos.py
index c6706fefa..dfd133a36 100644
--- a/tests/test_translation_engine_chaos.py
+++ b/tests/test_translation_engine_chaos.py
@@ -979,11 +979,9 @@ class TestRequestEngineEdgeCases:
def test_openai_to_anthropic_default_max_tokens(self, req_engine):
"""When ``max_tokens`` is omitted, Anthropic requires a default.
- The translation layer injects ``128_000`` (generous on purpose —
- see ``convert_openai_request_to_anthropic``'s docstring). Anthropic
- clamps this to the model's real output ceiling server-side, so
- oversizing is harmless and a small default would silently
- truncate long coding outputs.
+ The translation layer injects ``64_000`` to provide room for long
+ coding outputs without defaulting every request to the model's
+ absolute output ceiling.
"""
body = {
"model": "gpt-4o",
@@ -991,7 +989,7 @@ class TestRequestEngineEdgeCases:
}
req = ChatRequest.openai_chat(body)
result = req_engine.request_to(ChatRequestType.ANTHROPIC, req)
- assert result.body["max_tokens"] == 128_000
+ assert result.body["max_tokens"] == 64_000
def test_openai_to_anthropic_system_extraction(self, req_engine):
"""System messages should be extracted into the Anthropic system param."""