-
Notifications
You must be signed in to change notification settings - Fork 320
feat: anthropic endpoint support and translation for openai backend #1878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nacx
merged 12 commits into
envoyproxy:main
from
changminbark:anthropic-support-for-openai
Mar 2, 2026
Merged
Changes from 2 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
50907fb
feat: anthropic endpoint compatible openai backend support
changminbark e1fe7a0
feat: anthropic native to openai translator
changminbark e2b9c10
test: added unit tests for code coverage
changminbark fb724c3
Merge branch 'main' into anthropic-support-for-openai
nacx 48593d3
fix: irrelevant OpenAI SSE no longer passed; test: added e2e test
changminbark dd9b9a9
fix: removed openai prefix anthropic messages route and test
changminbark c5f6682
Merge branch 'main' into anthropic-support-for-openai
changminbark ed7ec70
fix: updated Anthropic ToolUnion and ToolChoice schema translation
changminbark f67d92e
Merge branch 'main' into anthropic-support-for-openai
nacx c672bac
test: added expectedRequestBody to upstream test; chore: updated anth…
changminbark e911f4a
Merge branch 'main' into anthropic-support-for-openai
nacx 1be9091
Merge branch 'main' into anthropic-support-for-openai
nacx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| # Copyright Envoy AI Gateway Authors | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # The full text of the Apache license is available in the LICENSE file at | ||
| # the root of the repo. | ||
|
|
||
| # This example routes /v1/messages (Anthropic Messages API) requests to a | ||
| # local vLLM backend. | ||
| # The AIServiceBackend schema is set to OpenAI so the gateway passes through | ||
| # the Anthropic request format with translation. | ||
|
|
||
| apiVersion: gateway.networking.k8s.io/v1 | ||
|
changminbark marked this conversation as resolved.
Outdated
|
||
| kind: GatewayClass | ||
| metadata: | ||
| name: envoy-ai-gateway-basic | ||
| spec: | ||
| controllerName: gateway.envoyproxy.io/gatewayclass-controller | ||
| --- | ||
| apiVersion: gateway.envoyproxy.io/v1alpha1 | ||
| kind: EnvoyProxy | ||
| metadata: | ||
| name: envoy-ai-gateway-basic | ||
| namespace: default | ||
| spec: | ||
| provider: | ||
| type: Kubernetes | ||
| kubernetes: | ||
| envoyDeployment: | ||
| container: | ||
| resources: {} | ||
| --- | ||
| apiVersion: gateway.networking.k8s.io/v1 | ||
| kind: Gateway | ||
| metadata: | ||
| name: envoy-ai-gateway-basic | ||
| namespace: default | ||
| spec: | ||
| gatewayClassName: envoy-ai-gateway-basic | ||
| listeners: | ||
| - name: http | ||
| protocol: HTTP | ||
| port: 80 | ||
| infrastructure: | ||
| parametersRef: | ||
| group: gateway.envoyproxy.io | ||
| kind: EnvoyProxy | ||
| name: envoy-ai-gateway-basic | ||
| --- | ||
| # By default, Envoy Gateway sets the buffer limit to 32kiB which is not sufficient for AI workloads. | ||
| # This ClientTrafficPolicy sets the buffer limit to 50MiB as an example. | ||
| apiVersion: gateway.envoyproxy.io/v1alpha1 | ||
| kind: ClientTrafficPolicy | ||
| metadata: | ||
| name: client-buffer-limit | ||
| namespace: default | ||
| spec: | ||
| targetRefs: | ||
| - group: gateway.networking.k8s.io | ||
| kind: Gateway | ||
| name: envoy-ai-gateway-basic | ||
| connection: | ||
| bufferLimit: 50Mi | ||
| --- | ||
| apiVersion: aigateway.envoyproxy.io/v1alpha1 | ||
| kind: AIGatewayRoute | ||
| metadata: | ||
| name: envoy-ai-gateway-basic-openai | ||
|
changminbark marked this conversation as resolved.
Outdated
|
||
| namespace: default | ||
| spec: | ||
| parentRefs: | ||
| - name: envoy-ai-gateway-basic | ||
| kind: Gateway | ||
| group: gateway.networking.k8s.io | ||
| rules: | ||
| - matches: | ||
| - headers: | ||
| - type: Exact | ||
| name: x-ai-eg-model | ||
| value: Qwen/Qwen2.5-0.5B-Instruct # Replace with the model name served by your vLLM instance. | ||
| backendRefs: | ||
| - name: envoy-ai-gateway-basic-openai | ||
| --- | ||
| apiVersion: aigateway.envoyproxy.io/v1alpha1 | ||
| kind: AIServiceBackend | ||
| metadata: | ||
| name: envoy-ai-gateway-basic-openai | ||
| namespace: default | ||
| spec: | ||
| schema: | ||
| name: OpenAI # vLLM exposes an OpenAI-compatible API, so Anthropic Messages Requests are translated | ||
| backendRef: | ||
| name: envoy-ai-gateway-basic-openai | ||
| kind: Backend | ||
| group: gateway.envoyproxy.io | ||
| --- | ||
| apiVersion: gateway.envoyproxy.io/v1alpha1 | ||
| kind: Backend | ||
| metadata: | ||
| name: envoy-ai-gateway-basic-openai | ||
| namespace: default | ||
| spec: | ||
| endpoints: | ||
| - ip: | ||
| address: 0.0.0.0 # Replace with your vLLM service hostname or IP (e.g. localhost's internal IP from kind cluster). | ||
| port: 8000 # Replace with the port your vLLM instance listens on (default: 8000). | ||
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The root path
/is intended for unified API endpoints which works for heterogeneous backends by translating between API schemas. For/v1/messagescurrently we only support pass through hence prefixed withanthropic, you could configure this root path on the client side to be compatible with the gateway path.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah I see you want Claude Code to work with models using OpenAI API, but I think vllm actually now supports
v1/messagesnatively.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#1867
Please follow through the conversations here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yuzisun Yes, I discussed the implementation details in the tagged issue. Please take a look and let me know what you think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @changminbark and @yuzisun
I work with @ehfd, just tested the PR in our cluster with curl and claude code, works perfectly! Looks great!
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the
/v1/messages->/v1/chat/completionstranslation will work with the existing registered endpoint, and the current change in this file is not required -https://github.com/envoyproxy/ai-gateway/pull/1878/changes#diff-33280abdb776271e54b6d3fea30758bc5ea3f458cdf3cce1b4d57e3be8caa853R310
The anthropic prefix can be set to an empty string
anthropic: ""in values.yaml, if you don't need it in the access URLUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ai-gateway-extproc time=2026-02-14T07:39:50.432Z level=ERROR msg="error processing request message" error="rpc error: code = Internal desc = cannot set backend: failed to create translator for backend nrp-llm/envoy-ai-gateway-nrp-glm-4/route/envoy-ai-gateway-nrp-glm/rule/1/ref/0: /v1/messages endpoint only supports backends that return native Anthropic format (Anthropic, GCPAnthropic, AWSAnthropic). Backend OpenAI uses different model format"In core, we want to get this rid and not have to duplicate APISchemaAnthropic, BackendSecurityPolicyAnthropicAPIKey, AnthropicAPIKey with the OpenAI schema. So the correct implementation is a translator like in https://github.com/envoyproxy/ai-gateway/tree/main/internal/translator?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, adding OpenAI Translator for existing anthropic /v1/messages endpoint is correct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I should get rid of registering the route with the OpenAI prefix?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dd9b9a9
Available here. I think this is resolved.