feat(ai-proxy): support automatic protocol translation from Claude to OpenAI#13048
Draft
moonming wants to merge 1 commit intoapache:masterfrom
Draft
feat(ai-proxy): support automatic protocol translation from Claude to OpenAI#13048moonming wants to merge 1 commit intoapache:masterfrom
moonming wants to merge 1 commit intoapache:masterfrom
Conversation
… OpenAI This feature enables the `ai-proxy` plugin to automatically detect requests directed to `/v1/messages` (the Claude API format), translate them into the OpenAI API format (`/v1/chat/completions`), forward them to an OpenAI-compatible upstream, and translate the response (including SSE streams) back into the Claude API format. Added a new module `claude_to_openai.lua` for the core translation logic, integrated it into `ai-proxy/base.lua` and `ai-drivers/openai-base.lua`, and added a comprehensive test suite `t/plugin/ai-proxy-claude.t`. Also updated the documentation with usage examples and an architecture diagram.
15e56cd to
eeb5559
Compare
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.
Why this PR?
This PR introduces an Automatic Protocol Translation feature to the
ai-proxyplugin. This feature enables the APISIX API Gateway to automatically detect AI requests that are directed to the/v1/messagesendpoint (which is the standard Claude API format), translate the request into the OpenAI format (/v1/chat/completions), forward the request to an OpenAI-compatible upstream provider, and lastly translate the response back into the Claude API format.This allows AI clients, extensions, and tooling that strictly rely on the Claude API format to seamlessly work with any backend models exposed through OpenAI-compatible APIs behind APISIX, expanding integration possibilities without requiring changes on the client side.
What this PR does?
apisix/plugins/ai-proxy/converter/claude_to_openai.luacontaining the core logic to convert JSON requests, JSON responses, and SSE streaming chunks between Claude and OpenAI formats.apisix/plugins/ai-proxy/base.luato automatically detect requests targeting/v1/messagesand set a context flag.apisix/plugins/ai-drivers/openai-base.luato invoke the converter functions before sending the request and during response processing (for both standard and streaming paths) when the flag is present.test::nginxtest suite int/plugin/ai-proxy-claude.t, covering:docs/en/latest/plugins/ai-proxy.md, including a Mermaid architecture sequence diagram and concrete usage examples.