-
Notifications
You must be signed in to change notification settings - Fork 555
Description
Bug Description
When using Batch Processing in conjunction with Structured Outputs, passing the required beta flag structured-outputs-2025-11-13 inside the params object MessageCreateParamsNonStreaming fails to enable the feature and worse, the API returns a confusing:
{
"error": {
"type": "invalid_request_error",
"message": "output_format: Extra inputs are not permitted"
}
}
The feature only works if the beta flag is passed to the top-level client.beta.messages.batches.create() method. However, the type definition for batches.create() does not currently include this specific beta flag in its Literal definition, causing static analysis warnings, while MessageCreateParamsNonStreaming does allow it but causes the runtime failure.
Expected behavior
Based on the Structured Outputs documentation, Structured Outputs should work with Batch Processing. The SDK should either:
- Allow
betasinMessageCreateParamsNonStreamingand properly propagate it to batch request headers - Disallow per-request betas for message batches (maybe raise an explicit error?) and document that betas must be provided at the batch level.
Also, have "structured-outputs-2025-11-13" as type hints for batches.create(betas=)
Code Snippet for Reproduction
import pydantic
from anthropic import Anthropic, transform_schema
from anthropic.types.beta import BetaMessageParam, BetaJSONOutputFormatParam
from anthropic.types.beta.message_create_params import MessageCreateParamsNonStreaming
from anthropic.types.beta.messages import BetaMessageBatch
from anthropic.types.beta.messages.batch_create_params import Request
class ContactInfo(pydantic.BaseModel):
name: str
email: str
plan_interest: str
demo_requested: bool
client = Anthropic(api_key="sk-ant-api...")
def schedule_structured_batch__fails(custom_id: str) -> BetaMessageBatch:
return client.beta.messages.batches.create(
requests=[
Request(
custom_id=custom_id,
params=MessageCreateParamsNonStreaming(
model="claude-sonnet-4-5",
max_tokens=1024,
# Passing beta here results in "Extra inputs" error for output_format
betas=["structured-outputs-2025-11-13"],
messages=[
BetaMessageParam(
role="user",
content="Extract the key information from this email: John Smith (john@example.com) is interested in our Enterprise plan and wants to schedule a demo for next Tuesday at 2pm."
)
],
output_format=BetaJSONOutputFormatParam(
type="json_schema",
schema=transform_schema(ContactInfo)
)
)
)
]
)
def schedule_structured_batch__succeeds(custom_id: str) -> BetaMessageBatch:
return client.beta.messages.batches.create(
betas=["structured-outputs-2025-11-13"],
requests=[
Request(
custom_id=custom_id,
params=MessageCreateParamsNonStreaming(
model="claude-sonnet-4-5",
max_tokens=1024,
messages=[
BetaMessageParam(
role="user",
content="Extract the key information from this email: John Smith (john@example.com) is interested in our Enterprise plan and wants to schedule a demo for next Tuesday at 2pm."
)
],
output_format=BetaJSONOutputFormatParam(
type="json_schema",
schema=transform_schema(ContactInfo)
)
)
)
]
)
Environment
anthropic-sdk-python version: 0.76.0
Python: 3.11.12