For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.
Amazon Bedrock
Configure Amazon Bedrock as an LLM provider for agentgateway.
Configure Amazon Bedrock as an LLM provider in agentgateway.
Note
Agentgateway accepts OpenAI-formatted requests (such as the /v1/chat/completions request body shape) and returns OpenAI-formatted responses, regardless of the route path that you configure. Agentgateway translates between OpenAI and Bedrock formats internally. Bedrock-native APIs such as the Converse API request and response shapes are not supported. Usage fields in responses follow the OpenAI shape (prompt_tokens, completion_tokens, total_tokens), not the Bedrock shape (inputTokens, outputTokens, totalTokens).
Note
Bedrock excludes cached tokens from the input count that it reports. The CEL field llm.inputTokens adds them back, so telemetry, metrics, and token-based limits count a cache-heavy request higher than the number that Bedrock reports. To read the Bedrock number itself, use llm.providerInputTokens. Do not confuse these CEL fields with the Bedrock wire fields named in the previous note. For more information, see Token usage fields.
Before you begin
- Set up an agentgateway proxy.
- Make sure that your Amazon credentials have access to the Bedrock models that you want to use. You can alternatively use an AWS Bedrock API key.
- Optional: You can configure AWS IAM Identity Center to allow single sign-on (SSO) credentials to authenticate to AWS Bedrock. Make sure that you have access to AWS Bedrock and set up your AWS profile to use SSO, such as through the
awsCLI. Make sure the workload can use that profile (for example withAWS_PROFILE). Later when you create the AgentgatewayBackend, omitpolicies.authso the proxy uses implicit AWS SSO credentials.
Set up access to Amazon Bedrock
Store your credentials to access the AWS Bedrock API.
Warning
These steps store the gateway’s credentials in
AGW_-prefixed environment variables, as opposed to the standardAWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY, andAWS_SESSION_TOKENvariables that theawsCLI and the AWS SDKs read. This way, when you export the variables, you do not replace your own personal user identity for the rest of the shell session, which could lead to unexpected auth errors. To use the standard names anyway, set them in a subshell, or store the gateway’s credentials in a named AWS profile and select that profile withAWS_PROFILEfor the agentgateway process only.Log in to the AWS console and store your access credentials as environment variables.
export AGW_AWS_ACCESS_KEY_ID="<aws-access-key-id>" export AGW_AWS_SECRET_ACCESS_KEY="<aws-secret-access-key>" export AGW_AWS_SESSION_TOKEN="<aws-session-token>"Create a secret with your Bedrock API key. Optionally provide the session token.
kubectl create secret generic bedrock-secret \ -n agentgateway-system \ --from-literal=accessKey="$AGW_AWS_ACCESS_KEY_ID" \ --from-literal=secretKey="$AGW_AWS_SECRET_ACCESS_KEY" \ --from-literal=sessionToken="$AGW_AWS_SESSION_TOKEN" \ --type=Opaque \ --dry-run=client -o yaml | kubectl apply -f -
Create an AgentgatewayBackend resource to configure your LLM provider. Make sure to reference the secret that holds your credentials to access the LLM.
kubectl apply -f- <<EOF apiVersion: agentgateway.dev/v1alpha1 kind: AgentgatewayBackend metadata: name: bedrock namespace: agentgateway-system spec: ai: provider: bedrock: model: "amazon.nova-micro-v1:0" region: "us-east-1" policies: auth: aws: secretRef: name: bedrock-secret EOFReview the following table to understand this configuration. For more information, see the API reference.
Setting Description ai.provider.bedrockDefine the LLM provider that you want to use. The example uses Amazon Bedrock. bedrock.modelThe model to use to generate responses. In this example, you use the amazon.nova-micro-v1:0model. Keep in mind that some models support cross-region inference. These models begin with aus.prefix, such asus.anthropic.claude-sonnet-4-20250514-v1:0. For more models, see the AWS Bedrock docs.bedrock.regionThe AWS region where your Bedrock model is deployed. Multiple regions are not supported. policies.authProvide the credentials to use to access the Amazon Bedrock API. The example refers to the secret that you previously created. To use implicit credentials from the workload or environment instead (for example IRSA and AWS IAM Identity Center (SSO) profiles), omit the authsettings.Create an HTTPRoute resource to route requests through your agentgateway proxy to the Bedrock AgentgatewayBackend.
kubectl apply -f- <<EOF apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: bedrock namespace: agentgateway-system spec: parentRefs: - name: agentgateway-proxy namespace: agentgateway-system rules: - matches: - path: type: PathPrefix value: /v1/chat/completions backendRefs: - name: bedrock namespace: agentgateway-system group: agentgateway.dev kind: AgentgatewayBackend EOFSend a request to the LLM provider API along the route that you previously created, such as
/bedrockor/v1/chat/completionsdepending on your route configuration. The request body must be in OpenAI chat-completions format. Verify that the request succeeds and that you get back a response from the chat completion API.Cloud Provider LoadBalancer:
curl "$INGRESS_GW_ADDRESS/v1/chat/completions" -H content-type:application/json -d '{ "model": "", "messages": [ { "role": "user", "content": "You are a cloud native solutions architect, skilled in explaining complex technical concepts such as API Gateway, microservices, LLM operations, kubernetes, and advanced networking patterns. Write me a 20-word pitch on why I should use an AI gateway in my Kubernetes cluster." } ] }' | jqLocalhost:
curl "localhost:8080/v1/chat/completions" -H content-type:application/json -d '{ "model": "", "messages": [ { "role": "user", "content": "You are a cloud native solutions architect, skilled in explaining complex technical concepts such as API Gateway, microservices, LLM operations, kubernetes, and advanced networking patterns. Write me a 20-word pitch on why I should use an AI gateway in my Kubernetes cluster." } ] }' | jqExample output. Note that agentgateway returns OpenAI-shaped responses, including OpenAI-style usage fields (
prompt_tokens,completion_tokens,total_tokens), even though the upstream provider is Bedrock.{ "id": "chatcmpl-abc123", "object": "chat.completion", "created": 1730000000, "model": "amazon.nova-micro-v1:0", "choices": [ { "index": 0, "message": { "role": "assistant", "content": "An AI gateway in your Kubernetes cluster can enhance performance, scalability, and security while simplifying complex operations. It provides a centralized entry point for AI workloads, automates deployment and management, and ensures high availability." }, "finish_reason": "stop" } ], "usage": { "prompt_tokens": 60, "completion_tokens": 47, "total_tokens": 107 } }
Bedrock Mantle
Bedrock serves models on two API surfaces: the Runtime endpoint, which carries the Converse and Invoke APIs, and the Mantle endpoint, which carries the native OpenAI and Anthropic APIs. Some models are served on only one of the two.
For chat requests, the endpoint is chosen per model from the runtime and mantle tags in your model cost catalog. Run agctl catalog import to populate those tags, because the default sources include aws-bedrock-mantle, which reads them from the AWS model cards. Without a catalog, no model carries either tag, so every chat request falls back to the preference alone.
Set spec.ai.provider.bedrock.endpointPreference on the AgentgatewayBackend resource to choose how the tags are applied. The AgentgatewayModel resource takes the same setting at spec.bedrock.endpointPreference.
spec:
ai:
provider:
bedrock:
model: "amazon.nova-micro-v1:0"
region: "us-east-1"
endpointPreference: RuntimePreferred| Value | Endpoint selection |
|---|---|
RuntimePreferred | Use Runtime, except for a model tagged mantle but not runtime. This value is the default. |
MantlePreferred | Use Mantle, except for a model tagged runtime but not mantle. |
RuntimeOnly | Always use Runtime, whatever the tags say. |
MantleOnly | Always use Mantle, whatever the tags say. |
Standalone mode takes the same four values in lowercase, such as runtimePreferred, under params.bedrockEndpointPreference. A value that you copy from one mode to the other fails to load.
The preference applies to chat completions, messages, responses, and Anthropic token counting. The other route types ignore it: embeddings, reranking, realtime, Gemini token counting, detection, passthrough, and content generation always take Runtime, and model listing always takes Mantle.
Whether the preference changes the request format that a model accepts depends on the endpoint that it selects. A model that resolves to Runtime accepts the Bedrock Converse format only, and its chat format tags do not apply. A model that resolves to Mantle accepts the formats in its tags, except for anthropic.claude* models, which always take the Anthropic Messages format. For more information, see Chat format tags.
Note
Requests to the Mantle endpoint are signed for the bedrock-mantle service rather than bedrock. If you scope an IAM policy by service name, grant both before you switch a route to Mantle.
Prompt caching
Prompt Caching is a performance, cost-optimization, and cost-reduction feature that allows the model to “remember” frequently used parts of your prompt, including long system instructions, reference documents, or tool definitions. This way, the model does not need to reprocess these parts every time you send a new prompt.
For example, let’s assume you have a 50-page manual and you want to ask your model different questions about the manual. Instead of re-reading the manual for each question, the model can read it once and save it in its internal cache. Then, the model can answer subsequent questions more quickly and more cost efficient.
Prompt caching is configured by using the backend.ai.promptCaching fields in the AgentgatewayPolicy resource.
Note
Prompt caching is supported for Bedrock Claude 3+ and Nova models.
Create an AgentgatewayPolicy resource with your prompt cache settings. The following example enables caching for system prompts and conversation messages, but disables it for tool definitions. Bedrock requires you to set the minimum token count after which caching is enabled. By default, a minimum of 1024 tokens are required by Bedrock for caching to be effective. This is also referred to as a caching checkpoint. For more information, see the API reference.
kubectl apply -f- <<EOF apiVersion: agentgateway.dev/v1alpha1 kind: AgentgatewayPolicy metadata: name: bedrock-caching-policy namespace: agentgateway-system spec: targetRefs: - group: gateway.networking.k8s.io kind: HTTPRoute name: bedrock backend: ai: promptCaching: cacheSystem: true cacheMessages: true cacheTools: false minTokens: 1024 EOFPort-forward the agentgateway proxy on port 15000.
kubectl port-forward deploy/agentgateway-proxy -n agentgateway-system 15000Get the caching configuration and verify that you see the cache settings.
curl -s http://localhost:15000/config_dump | jq '.policies[] | select(.name.name == "bedrock-caching-policy" and .policy.backend.aI.promptCaching != null)'Example output:
{ "key": "backend/agentgateway-system/bedrock-caching-policy:ai:agentgateway-system/bedrock", "name": { "kind": "AgentgatewayPolicy", "name": "bedrock-caching-policy", "namespace": "agentgateway-system" }, "target": { "route": { "name": "bedrock", "namespace": "agentgateway-system", "kind": "HTTPRoute" } }, "policy": { "backend": { "aI": { "defaults": {}, "overrides": {}, "promptCaching": { "cacheSystem": true, "cacheMessages": true, "cacheTools": false, "minTokens": 1024 } } } } }
Extended thinking and reasoning
Extended thinking and reasoning lets models reason through complex problems before generating a response. You can opt in to extended thinking and reasoning by adding the OpenAI reasoning_effort field to your request. Agentgateway translates this setting to Bedrock’s native thinking budget automatically.
Note: Extended thinking and reasoning requires a Claude model that supports it, such as us.anthropic.claude-opus-4-20250514-v1:0.
Use the reasoning_effort field to control how much reasoning the model applies. The value is automatically mapped to a thinking budget.
reasoning_effort value | Thinking budget |
|---|---|
minimal or low | 1,024 tokens |
medium | 2,048 tokens |
high | 4,096 tokens |
xhigh | 8,192 tokens in agentgateway 1.4 and later. 4,096 tokens in earlier versions, including 2.2.x. |
max | 16,384 tokens. Supported in agentgateway 1.4 and later. |
For Claude models that support adaptive thinking, the request is sent with thinking.type set to adaptive and the effort level in output_config.effort, instead of a thinking budget. The value minimal is sent as low. Which models take this form depends on the adaptive_thinking tag in the model cost catalog. The built-in catalog sets this tag for these models.
reasoning_effort also works with the following non-Claude model families. The family is chosen by matching the model ID, and the value is added to the additionalModelRequestFields of the Bedrock request.
| Model ID contains | What the Bedrock request receives |
|---|---|
gpt-oss or deepseek | reasoning_effort, with the value from your request unchanged. |
openai., other than gpt-oss models | reasoning.effort, with the value from your request unchanged. |
amazon.nova-2- | reasoningConfig with maxReasoningEffort set to low, medium, or high. If you set none or omit reasoning_effort, no reasoning configuration is sent. Any other value is rejected. |
Any other model ID is treated as a Claude model.
Cloud Provider LoadBalancer:
curl "$INGRESS_GW_ADDRESS/v1/chat/completions" -H content-type:application/json -d '{
"model": "",
"max_tokens": 6000,
"reasoning_effort": "high",
"messages": [
{
"role": "user",
"content": "Explain the trade-offs between consistency and availability in distributed systems."
}
]
}' | jqLocalhost:
curl "localhost:8080/v1/chat/completions" -H content-type:application/json -d '{
"model": "",
"max_tokens": 6000,
"reasoning_effort": "high",
"messages": [
{
"role": "user",
"content": "Explain the trade-offs between consistency and availability in distributed systems."
}
]
}' | jqStructured outputs
Structured outputs constrain the model to respond with a specific JSON schema. Provide the schema definition in the OpenAI response_format field of your request. Agentgateway translates this to Bedrock’s native format automatically.
Cloud Provider LoadBalancer:
curl "$INGRESS_GW_ADDRESS/v1/chat/completions" -H content-type:application/json -d '{
"model": "",
"max_tokens": 256,
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "answer_schema",
"schema": {
"type": "object",
"properties": {
"answer": { "type": "string" },
"confidence": { "type": "number" }
},
"required": ["answer", "confidence"],
"additionalProperties": false
}
}
},
"messages": [
{
"role": "user",
"content": "Is the sky blue? Respond with your answer and a confidence score between 0 and 1."
}
]
}' | jqLocalhost:
curl "localhost:8080/v1/chat/completions" -H content-type:application/json -d '{
"model": "",
"max_tokens": 256,
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "answer_schema",
"schema": {
"type": "object",
"properties": {
"answer": { "type": "string" },
"confidence": { "type": "number" }
},
"required": ["answer", "confidence"],
"additionalProperties": false
}
}
},
"messages": [
{
"role": "user",
"content": "Is the sky blue? Respond with your answer and a confidence score between 0 and 1."
}
]
}' | jq