Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/v1alpha1/shared_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ const (
APISchemaAnthropic APISchema = "Anthropic"
// APISchemaAWSAnthropic is the schema for Anthropic models hosted on AWS Bedrock.
// Uses the native Anthropic Messages API format for requests and responses.
// When used with /v1/chat/completions endpoint, translates OpenAI format to Anthropic.
// When used with /v1/messages endpoint, passes through native Anthropic format.
//
// https://aws.amazon.com/bedrock/anthropic/
// https://docs.claude.com/en/api/claude-on-amazon-bedrock
Expand Down
109 changes: 109 additions & 0 deletions examples/basic/aws-bedrock-openai-anthropic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# 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 demonstrates using the AWSAnthropic schema to access
# Claude models on AWS Bedrock via the InvokeModel API with OpenAI-compatible requests.
#
# The AWSAnthropic schema works with both input formats:
# - /v1/chat/completions: Translates OpenAI ChatCompletion requests to Anthropic Messages API format
# - /v1/messages: Passes through native Anthropic Messages API format
#
# Use cases:
# - When you want to use OpenAI SDK/format with Claude models on AWS Bedrock
# - When migrating from OpenAI to Claude on AWS without changing client code
# - When using tools that only support OpenAI format but need Claude on AWS

apiVersion: aigateway.envoyproxy.io/v1alpha1
kind: AIGatewayRoute
metadata:
name: envoy-ai-gateway-aws-bedrock-claude-openai-format
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: anthropic.claude-3-5-sonnet-20241022-v2:0
backendRefs:
- name: envoy-ai-gateway-aws-bedrock-claude-openai
---
apiVersion: aigateway.envoyproxy.io/v1alpha1
kind: AIServiceBackend
metadata:
name: envoy-ai-gateway-aws-bedrock-claude-openai
namespace: default
spec:
# AWSAnthropic schema supports both OpenAI and Anthropic input formats.
# The endpoint path determines the translator used.
schema:
name: AWSAnthropic
# Optional: Specify Anthropic API version for Bedrock
# Default: bedrock-2023-05-31
version: bedrock-2023-05-31
backendRef:
name: envoy-ai-gateway-basic-aws
kind: Backend
group: gateway.envoyproxy.io
---
apiVersion: aigateway.envoyproxy.io/v1alpha1
kind: BackendSecurityPolicy
metadata:
name: envoy-ai-gateway-aws-bedrock-credentials
namespace: default
spec:
targetRefs:
- group: aigateway.envoyproxy.io
kind: AIServiceBackend
name: envoy-ai-gateway-aws-bedrock-claude-openai
type: AWSCredentials
awsCredentials:
region: us-east-1
credentialsFile:
secretRef:
name: envoy-ai-gateway-basic-aws-credentials
---
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: Backend
metadata:
name: envoy-ai-gateway-basic-aws
namespace: default
spec:
endpoints:
- fqdn:
hostname: bedrock-runtime.us-east-1.amazonaws.com
port: 443
---
apiVersion: gateway.networking.k8s.io/v1alpha3
kind: BackendTLSPolicy
metadata:
name: envoy-ai-gateway-basic-aws-tls
namespace: default
spec:
targetRefs:
- group: "gateway.envoyproxy.io"
kind: Backend
name: envoy-ai-gateway-basic-aws
validation:
wellKnownCACertificates: "System"
hostname: bedrock-runtime.us-east-1.amazonaws.com
---
apiVersion: v1
kind: Secret
metadata:
name: envoy-ai-gateway-basic-aws-credentials
namespace: default
type: Opaque
stringData:
# Replace this with your AWS credentials.
# You can also use AWS IAM roles for service accounts (IRSA) in EKS.
credentials: |
[default]
aws_access_key_id = AWS_ACCESS_KEY_ID
aws_secret_access_key = AWS_SECRET_ACCESS_KEY
2 changes: 2 additions & 0 deletions internal/endpointspec/endpointspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ func (ChatCompletionsEndpointSpec) GetTranslator(schema filterapi.VersionedAPISc
return translator.NewChatCompletionOpenAIToOpenAITranslator(schema.OpenAIPrefix(), modelNameOverride), nil
case filterapi.APISchemaAWSBedrock:
return translator.NewChatCompletionOpenAIToAWSBedrockTranslator(modelNameOverride), nil
case filterapi.APISchemaAWSAnthropic:
return translator.NewChatCompletionOpenAIToAWSAnthropicTranslator(schema.Version, modelNameOverride), nil
case filterapi.APISchemaAzureOpenAI:
return translator.NewChatCompletionOpenAIToAzureOpenAITranslator(schema.Version, modelNameOverride), nil
case filterapi.APISchemaGCPVertexAI:
Expand Down
1 change: 1 addition & 0 deletions internal/endpointspec/endpointspec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func TestChatCompletionsEndpointSpec_GetTranslator(t *testing.T) {
supported := []filterapi.VersionedAPISchema{
{Name: filterapi.APISchemaOpenAI, Prefix: "v1"},
{Name: filterapi.APISchemaAWSBedrock},
{Name: filterapi.APISchemaAWSAnthropic},
{Name: filterapi.APISchemaAzureOpenAI, Version: "2024-02-01"},
{Name: filterapi.APISchemaGCPVertexAI},
{Name: filterapi.APISchemaGCPAnthropic, Version: "2024-05-01"},
Expand Down
5 changes: 3 additions & 2 deletions internal/filterapi/filterconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const (
APISchemaOpenAI APISchemaName = "OpenAI"
// APISchemaCohere represents the Cohere API schema.
APISchemaCohere APISchemaName = "Cohere"
// APISchemaAWSBedrock represents the AWS Bedrock API schema.
// APISchemaAWSBedrock represents the AWS Bedrock Converse API schema.
APISchemaAWSBedrock APISchemaName = "AWSBedrock"
// APISchemaAzureOpenAI represents the Azure OpenAI API schema.
APISchemaAzureOpenAI APISchemaName = "AzureOpenAI"
Expand All @@ -127,7 +127,8 @@ const (
// APISchemaAnthropic represents the standard Anthropic API schema.
APISchemaAnthropic APISchemaName = "Anthropic"
// APISchemaAWSAnthropic represents the AWS Bedrock Anthropic API schema.
// Used for Claude models hosted on AWS Bedrock using the native Anthropic Messages API.
// Used for Claude models hosted on AWS Bedrock. Supports both OpenAI and Anthropic input formats
// depending on the endpoint path, similar to APISchemaGCPAnthropic.
APISchemaAWSAnthropic APISchemaName = "AWSAnthropic"
)

Expand Down
Loading