fix(beta): strip betas from per-request batch params #1132
+15
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fix(beta): strip betas from per-request batch params
Summary
The Message Batches API only supports beta flags at the top level (sent as a header for the batch create request). Including them in the JSON body for individual requests inside the batch causes API errors like
output_format: Extra inputs are not permitted.This PR ensures that
betasare stripped from individual request parameters in both synchronous and asynchronous batch creation.It also adds the missing
"structured-outputs-2025-11-13"string to theAnthropicBetaParamliteral to provide correct type hints for structured outputs.Problem
Fixes #1118
When a user provides
betasinside a batch request:The SDK was including
"anthropic-beta": ["structured-outputs-2025-11-13"]in the serialized JSON body for that specific request, which the API does not allow for batch members.Changes
src/anthropic/types/anthropic_beta_param.pyto include"structured-outputs-2025-11-13".src/anthropic/resources/beta/messages/batches.pyto strip thebetaskey from each request'sparamsbefore transformation and submission.Verification
Verified with a reproduction script that mocks the internal
_postmethod and checks the transmitted body. Theanthropic-betafield is now correctly removed from individual batch requests.