Add anthropic-beta header for structured outputs.#163
Add anthropic-beta header for structured outputs.#163felixarntz merged 1 commit intoWordPress:trunkfrom
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
@JasonTheAdams I was going to add a test or two, but at the moment there aren't any tests for |
|
Thanks, @johnhooks! You're right. There aren't currently any tests. I'll let @felixarntz decide if he'd like to add tests in this PR since he built out #156. I'm also adding him as a reviewer. |
|
I had tests in my implementation, before #156 was created AnthropicTextGenerationModelTest.php. I could attempt to port it over and add tests for all of UPDATE: I updated the test for the current implementation, and intended to stack the PRs, but I don't think I can since the incoming branch is from my fork. But I can either do separate PR, or merge into this one. https://github.com/johnhooks/php-ai-client/blob/cbaf7dc4f634bc7e6bd8676a393d600eb05034bc/tests/unit/ProviderImplementations/Anthropic/AnthropicTextGenerationModelTest.php |
felixarntz
left a comment
There was a problem hiding this comment.
@johnhooks I think this is good to go. While we should probably have tests for these, I think this is its own task to do, and this change is simple enough to not require being blocked to add tests.
Great catch, thank you for fixing this!
When requesting structured JSON output from the Anthropic API using the
output_formatparameter with a JSON schema, the API requires theanthropic-beta: structured-outputs-2025-11-13header to be present in the request. Without this header, Anthropic rejects the request because structured outputs is currently a beta feature that must be explicitly opted into. This fix detects when JSON schema output is configured viagetOutputMimeType()andgetOutputSchema()and automatically adds the required beta header, allowing structured output requests to succeed.See Claude Docs: Structured outputs
Fixes #151.