Skip to content
agentgateway has joined the Agentic AI FoundationLearn more

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

Page as Markdown

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/key

Change 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-token

Note

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-key

The 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.

Review the following table to understand this configuration.
FieldDescription
credentials[].locationRequired location that agentgateway writes this credential to. Set exactly one of header, queryParameter, or cookie. Each entry carries its own location.
credentials[].keyRequired 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.

Was this page helpful?
Agentgateway assistant

Ask me anything about agentgateway configuration, features, or usage.

Note: AI-generated content might contain errors; please verify and test all returned information.

Tip: one topic per conversation gives the best results. Use the + button in the chat header to start a new conversation.

Switching topics? Starting a new conversation improves accuracy.
↑↓ navigate select esc dismiss

What could be improved?

Your feedback helps us improve assistant answers and identify docs gaps we should fix.

Need more help? Join us on Discord: https://discord.gg/y9efgEmppm

Want to use your own agent? Add the Solo MCP server to query our docs directly. Get started here: https://search.solo.io/.