fix(beta): strip betas from per-request batch params#1132
Open
Ashutosh0x wants to merge 1 commit intoanthropics:mainfrom
Open
fix(beta): strip betas from per-request batch params#1132Ashutosh0x wants to merge 1 commit intoanthropics:mainfrom
Ashutosh0x wants to merge 1 commit intoanthropics:mainfrom
Conversation
The Batch API only supports beta flags at the top level (sent as a header). Including them in the JSON body for individual requests causes API errors (e.g., "output_format: Extra inputs are not permitted"). This change strips 'betas' from individual request parameters in both `Batches.create` and `AsyncBatches.create`. Also adds "structured-outputs-2025-11-13" to `AnthropicBetaParam` to support type hints for the new beta. Fixes anthropics#1118
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.