Skip to content

feat(ai-proxy): support automatic protocol translation from Claude to OpenAI#13048

Draft
moonming wants to merge 1 commit intoapache:masterfrom
moonming:feat/ai-proxy-claude-to-openai
Draft

feat(ai-proxy): support automatic protocol translation from Claude to OpenAI#13048
moonming wants to merge 1 commit intoapache:masterfrom
moonming:feat/ai-proxy-claude-to-openai

Conversation

@moonming
Copy link
Member

@moonming moonming commented Feb 28, 2026

Why this PR?

This PR introduces an Automatic Protocol Translation feature to the ai-proxy plugin. This feature enables the APISIX API Gateway to automatically detect AI requests that are directed to the /v1/messages endpoint (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?

  • Added a new module apisix/plugins/ai-proxy/converter/claude_to_openai.lua containing the core logic to convert JSON requests, JSON responses, and SSE streaming chunks between Claude and OpenAI formats.
  • Updated apisix/plugins/ai-proxy/base.lua to automatically detect requests targeting /v1/messages and set a context flag.
  • Updated apisix/plugins/ai-drivers/openai-base.lua to invoke the converter functions before sending the request and during response processing (for both standard and streaming paths) when the flag is present.
  • Wrote an end-to-end test::nginx test suite in t/plugin/ai-proxy-claude.t, covering:
    • Standard Chat Requests
    • Complex System Prompts (Array format)
    • Streaming SSE Responses
    • Abnormal Requests (e.g. missing messages array)
  • Added documentation for the new feature in docs/en/latest/plugins/ai-proxy.md, including a Mermaid architecture sequence diagram and concrete usage examples.

… 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.
@moonming moonming force-pushed the feat/ai-proxy-claude-to-openai branch from 15e56cd to eeb5559 Compare February 28, 2026 09:38
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.

1 participant