Skip to content

feat(ai-proxy-multi): add anthropic-native provider for native Anthropic Messages API#13050

Open
iakuf wants to merge 1 commit intoapache:masterfrom
iakuf:feat/ai-proxy-multi-anthropic-native
Open

feat(ai-proxy-multi): add anthropic-native provider for native Anthropic Messages API#13050
iakuf wants to merge 1 commit intoapache:masterfrom
iakuf:feat/ai-proxy-multi-anthropic-native

Conversation

@iakuf
Copy link

@iakuf iakuf commented Feb 28, 2026

Summary

Add a new anthropic-native driver that speaks the native Anthropic Messages API protocol (/v1/messages) directly.

The existing anthropic provider uses the OpenAI-compatible driver, which works for basic use cases but cannot handle Anthropic-specific protocol details. The new anthropic-native provider addresses this.

Key differences from openai-base driver

  • SSE event types: handles message_start, content_block_delta, message_delta, message_stop (no [DONE] sentinel)
  • Token usage fields: reads input_tokens/output_tokens instead of prompt_tokens/completion_tokens
  • Request format: removes stream_options (not supported by Anthropic), injects anthropic-version header automatically
  • Response format: extracts text from content[].text array instead of choices[].message.content
  • System prompt: accepts top-level system field and flexible content types (string or array of content blocks)

Changes

  • apisix/plugins/ai-drivers/anthropic-native.lua: new driver implementation
  • apisix/plugins/ai-drivers/schema.lua: register anthropic-native provider with its own request schema
  • t/assets/anthropic-native-response.json: mock response fixture for tests
  • t/plugin/ai-proxy-multi.anthropic-native.t: 26 test cases covering non-streaming, streaming, token usage, TTFT, error handling, and schema validation
  • docs/en/latest/plugins/ai-proxy-multi.md: document the new provider with a usage example

Testing

All 26 tests pass:

…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.
@dosubot dosubot bot added size:XXL This PR changes 1000+ lines, ignoring generated files. enhancement New feature or request labels Feb 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant