Skip to content

Anthropic Structured Output Issue #151

Closed

Description

@johnhooks

Problem

When using ->asJsonResponse($schema) with the Anthropic provider, the API returns errors:

Bad Request (400) - response_format.json_schema.name: Field required
# Added `name` field to schema wrapper, then got:

Bad Request (400) - response_format.json_schema.strict: Field required
# Added `strict: true` to schema wrapper, then got:

Bad Request (400) - output_config: Extra inputs are not permitted
# Anthropic doesn't recognize `response_format` at all—it's an OpenAI parameter

The library sends OpenAI's response_format parameter to Anthropic's API, which now rejects it. This appears to have started around December 4, 2025 when Anthropic launched their structured outputs feature—prior to this, the parameter was likely ignored.

Proposed Solution

Anthropic's structured outputs use a different format than OpenAI:

OpenAI Anthropic
Parameter response_format output_format
Beta header None anthropic-beta: structured-outputs-2025-11-13

The Anthropic provider should override prepareGenerateTextParams() to:

  1. Use output_format instead of response_format
  2. Add the required beta header

References

Activity

  1. johnhooks commented on Dec 20, 2025

    @johnhooks
    ContributorAuthor

    Moving to the native Anthropic API (#107) would probably be the correct way to resolve this.

  2. johnhooks commented on Dec 20, 2025

    @johnhooks
    ContributorAuthor

    I've working on a solution and having something functional, if there is interest I can open a PR. https://github.com/johnhooks/php-ai-client/tree/fix/issue-151

  3. JasonTheAdams commented on Jan 5, 2026

    @JasonTheAdams
    Member

    Thanks, @johnhooks! Can you please confirm if this is resolved in #156?

  4. johnhooks commented on Jan 5, 2026

    @johnhooks
    ContributorAuthor

    @JasonTheAdams I tested this out and JSON generation is still broken on trunk. PR #156 sends the output_format param but the API rejects it with "Extra inputs are not permitted."

    Structured outputs is still in beta on Anthropic's side, so you need to include the anthropic-beta: structured-outputs-2025-11-13 header. Without it, the API just doesn't recognize the parameter.

    I added the header locally and it works perfectly after that.

    https://platform.claude.com/docs/en/build-with-claude/structured-outputs

  5. JasonTheAdams commented on Jan 5, 2026

    @JasonTheAdams
    Member

    Got it! Would you be willing to open a PR with the fix, @johnhooks? Ideally this week. If you can't, just let me know and I'll try to knock it out. 😄

  6. added this to the 0.4.0 milestone on Jan 8, 2026
  7. added
    [Type] BugAn existing feature does not function as intended
    on Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Type] BugAn existing feature does not function as intended

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions