Skip to content

feat(genkit_anthropic): add beta/stable API selection and native structured outputs - #402

Open
adesinah wants to merge 1 commit into
mainfrom
fix/api_version_and_structure_output
Open

feat(genkit_anthropic): add beta/stable API selection and native structured outputs#402
adesinah wants to merge 1 commit into
mainfrom
fix/api_version_and_structure_output

Conversation

@adesinah

Copy link
Copy Markdown
Contributor

The plugin always called stable messages.create, so no beta-gated feature was reachable, and structured output was faked with a synthetic return_output tool forced via tool_choice - which Anthropic rejects alongside extended thinking.

The PR adds apiVersion ('stable' | 'beta') on both the plugin and per-request config, with the request winning and stable as the default, plus a betas override for features the curated list does not know yet. Beta requests send the anthropic-beta header on the unary and streaming paths alike. Models on Anthropic's Structured Outputs list now send the schema natively via output_config.format, so structured output composes with manual thinking. Other models keep the forced-tool fallback, which now reports INVALID_ARGUMENT when combined with manual thinking rather than letting the API reject the request.

Also fixes a caller-supplied toolChoice silently unforcing return_output.

Closes #356

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for Anthropic's stable and beta APIs, allowing users to opt into beta-gated features via apiVersion and betas options. It also implements native structured output support for capable models by mapping schemas directly to the output_config.format parameter, while maintaining a forced-tool fallback for older or uncurated models. The reviewer suggested an improvement to _toAnthropicSchema to automatically inject 'type': 'object' when properties or required are present but type is omitted, ensuring better robustness and consistency with the fallback path.

Comment thread packages/genkit_anthropic/lib/src/plugin_impl.dart
@adesinah
adesinah force-pushed the fix/api_version_and_structure_output branch from 0a98efe to 9c7d196 Compare August 27, 2026 14:55
@adesinah
adesinah force-pushed the fix/api_version_and_structure_output branch from 9c7d196 to 194e39f Compare August 27, 2026 15:10
@adesinah
adesinah requested review from cabljac and pavelgj August 27, 2026 15:14
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.

feat(genkit_anthropic): beta/stable API selection and native structured outputs

1 participant