Skip to content

Commit 5a8258c

Browse files
committed
fix(antigravity): reject requests exceeding Claude's 64K max_tokens limit
Instead of silently capping max_tokens, raise a ValueError so Claude Code sees the error and can adjust its request. Fixes 400 INVALID_ARGUMENT errors when clients send max_tokens > 64000 for Claude models.
1 parent dc19691 commit 5a8258c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/rotator_library/providers/antigravity_provider.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ def _env_int(key: str, default: int) -> int:
132132
# See: https://ai.google.dev/gemini-api/docs/models
133133
GEMINI_MAX_OUTPUT_TOKENS = 16384
134134

135+
# Claude max output tokens cap - Claude models have a 64K output limit
136+
# See: https://docs.anthropic.com/en/docs/about-claude/models
137+
CLAUDE_MAX_OUTPUT_TOKENS = 64000
138+
135139
# Empty response retry configuration
136140
# When Antigravity returns an empty response (no content, no tool calls),
137141
# automatically retry up to this many attempts before giving up (minimum 1)
@@ -4073,6 +4077,16 @@ def _transform_to_antigravity_format(
40734077
)
40744078
gen_config["maxOutputTokens"] = GEMINI_MAX_OUTPUT_TOKENS
40754079

4080+
# Reject requests that exceed Claude's max_tokens limit (64K)
4081+
# Let the client see the error so it can adjust its request
4082+
if is_claude and gen_config.get("maxOutputTokens"):
4083+
current_max = gen_config["maxOutputTokens"]
4084+
if current_max > CLAUDE_MAX_OUTPUT_TOKENS:
4085+
raise ValueError(
4086+
f"max_tokens: {current_max} > {CLAUDE_MAX_OUTPUT_TOKENS}, "
4087+
f"which is the maximum allowed number of output tokens for {model}"
4088+
)
4089+
40764090
antigravity_payload["request"]["generationConfig"] = gen_config
40774091

40784092
# Set toolConfig based on tool_choice parameter

0 commit comments

Comments
 (0)