For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.
Static keys and passthrough
Send a static credential to a backend, forward the credential that the client sent, or add extra credentials to the request.
Verified Code examples on this page have been automatically tested and verified.Attaches to:
About
Use one of the following backend authentication methods to send a static credential to your backend. The client may already send the credential that the backend expects. If it does not, agentgateway must supply one of its own.
- Static key (
key) sends a value that you configure, either inline or from a file on disk. - Passthrough (
passthrough) sends the JWT that the client sent. - Extra credentials (
credentials) adds one or more credentials, each to its own location, either on its own or alongside one of the other two methods.
All of them write the credential to the Authorization header with a Bearer prefix by default. The location field changes where agentgateway writes it.
Note
Agentgateway supports more than one configuration style. Where a feature can also be configured in the simplified llm or mcp modes, the examples on this page show each option in tabs. For more information, see Routing-based configuration.
Static keys
To attach a static key as an Authorization value, use key:
# yaml-language-server: $schema=https://agentgateway.dev/schema/config
mcp:
port: 3000
policies:
backendAuth:
key:
value: $MY_API_KEY
targets:
- name: everything
stdio:
cmd: npx
args: ["@modelcontextprotocol/server-everything"]The remaining examples on this page show only the backendAuth policy. Attach each one to a backend under backends[].policies, as shown in the complete example above.
Read the key from a file
You can also add keys via a file path.
backendAuth:
key:
value:
file: /path/to/my/keyChange the credential location
By default, agentgateway writes the credential to the Authorization header with a Bearer prefix. Set the location field to write it somewhere else.
To use a different header name, use the location field as shown in the following example.
backendAuth:
key:
value: $MY_API_KEY
location:
# Send as a request header (default)
header:
name: authorization
prefix: "Bearer "Pass through client credentials
Any form of incoming authentication removes the original credential from the request by default, before agentgateway forwards it to the backend. That applies to JWT, API key, and basic auth. To send the original credential on to the backend, use the passthrough method.
backendAuth:
passthrough: {}The method forwards a JWT only. It re-sends the token that a JWT authentication policy validated on the route. An API key or basic auth credential is still stripped, and passthrough does not add it back.
The passthrough method has no field for where to read the credential from, because agentgateway does not read it from the request at all. It re-sends the token that the jwtAuth policy already validated. The source is therefore wherever that policy’s own location field reads from, which is the Authorization header by default.
The location field on passthrough controls only where agentgateway writes the token on the backend request. That location does not have to be where the client sent it.
backendAuth:
passthrough:
location:
header:
name: x-forwarded-tokenNote
Prefer passthrough over the preserveToken field of the jwtAuth policy. Both get the token to the backend. However, preserveToken leaves the token in its original location, where every policy that runs later can read it. The passthrough method re-adds the token only on the request that agentgateway forwards to the backend.
Send more than one credential
Some upstreams want two credentials on the same request, such as a bearer token and a subscription key. The credentials list covers that case. Each entry sets a location and a key, and the list is independent of the primary method, so you can set it on its own or together with one.
backendAuth:
key:
value: $MY_API_KEY
credentials:
- location:
header:
name: x-tenant-key
key: $MY_TENANT_KEY
- location:
queryParameter:
name: subscription
key:
file: /etc/agentgateway/subscription-keyThe policy in the example sends three credentials on every request: the Authorization header from key, an x-tenant-key header, and a subscription query parameter.
| Field | Description |
|---|---|
credentials[].location | Required location that agentgateway writes this credential to. Set exactly one of header, queryParameter, or cookie. Each entry carries its own location. |
credentials[].key | Required credential value, either inline or as {file: <path>}. |
Note
The credentials list is not supported on a backend that agentgateway reaches through a tunnel. A tunnel-bound backend supports the key method only.