moonming opened a new pull request, #13048:
URL: https://github.com/apache/apisix/pull/13048
## 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.
## Checklist
- [x] I have read the [API Design
Guidelines](https://github.com/apache/apisix/blob/master/docs/en/latest/design-style.md)
- [x] I have added test cases
- [x] I have added English documentation
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]