Skip to content

Conversation

@Ashutosh0x
Copy link

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 betas are stripped from individual request parameters in both synchronous and asynchronous batch creation.

It also adds the missing "structured-outputs-2025-11-13" string to the AnthropicBetaParam literal to provide correct type hints for structured outputs.

Problem

Fixes #1118

When a user provides betas inside a batch request:

client.beta.messages.batches.create(
    requests=[
        Request(
            params=MessageCreateParamsNonStreaming(
                # ...
                betas=["structured-outputs-2025-11-13"]
            )
        )
    ]
)

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

  • Updated src/anthropic/types/anthropic_beta_param.py to include "structured-outputs-2025-11-13".
  • Updated src/anthropic/resources/beta/messages/batches.py to strip the betas key from each request's params before transformation and submission.

Verification

Verified with a reproduction script that mocks the internal _post method and checks the transmitted body. The anthropic-beta field is now correctly removed from individual batch requests.

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
@Ashutosh0x Ashutosh0x requested a review from a team as a code owner January 21, 2026 19:37
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.

[Bug: Batch + Structured Outputs] betas parameter in MessageCreateParamsNonStreaming causes batch requests to fail

1 participant