feat(ai-proxy-multi): add anthropic-native provider for native Anthropic Messages API#13050
Open
iakuf wants to merge 1 commit intoapache:masterfrom
Open
feat(ai-proxy-multi): add anthropic-native provider for native Anthropic Messages API#13050iakuf wants to merge 1 commit intoapache:masterfrom
iakuf wants to merge 1 commit intoapache:masterfrom
Conversation
…pic Messages API Add a new anthropic-native driver that speaks the native Anthropic Messages API protocol (/v1/messages) directly, as opposed to the existing anthropic provider which uses the OpenAI-compatible driver. Key differences from the openai-base driver: - Handles Anthropic-specific SSE event types: message_start, content_block_delta, message_delta, message_stop (no [DONE] sentinel) - Reads token usage from input_tokens/output_tokens fields - Removes stream_options from requests (not supported by Anthropic) - Injects anthropic-version header automatically - Extracts response text from content[].text array Also updates schema.lua to register the new provider and its request schema (which allows top-level system field and flexible content types), and adds documentation with a usage example.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a new
anthropic-nativedriver that speaks the native Anthropic Messages API protocol (/v1/messages) directly.The existing
anthropicprovider uses the OpenAI-compatible driver, which works for basic use cases but cannot handle Anthropic-specific protocol details. The newanthropic-nativeprovider addresses this.Key differences from
openai-basedrivermessage_start,content_block_delta,message_delta,message_stop(no[DONE]sentinel)input_tokens/output_tokensinstead ofprompt_tokens/completion_tokensstream_options(not supported by Anthropic), injectsanthropic-versionheader automaticallycontent[].textarray instead ofchoices[].message.contentsystemfield and flexiblecontenttypes (string or array of content blocks)Changes
apisix/plugins/ai-drivers/anthropic-native.lua: new driver implementationapisix/plugins/ai-drivers/schema.lua: registeranthropic-nativeprovider with its own request schemat/assets/anthropic-native-response.json: mock response fixture for testst/plugin/ai-proxy-multi.anthropic-native.t: 26 test cases covering non-streaming, streaming, token usage, TTFT, error handling, and schema validationdocs/en/latest/plugins/ai-proxy-multi.md: document the new provider with a usage exampleTesting
All 26 tests pass: