Pass custom headers to Amazon Bedrock AgentCore Runtime
Custom headers let you pass contextual information from your application directly to your agent code without cluttering the main request payload. You can pass any valid HTTP header that is not in the restricted headers list, including webhook signatures like X-Custom-Signature, API keys like X-Api-Key, trace context, or session identifiers. You can also pass the Authorization header for JWT-based authentication when your agent is configured with a custom JWT authorizer. Headers prefixed with X-Amzn-Bedrock-AgentCore-Runtime-Custom- continue to be supported for backward compatibility. Up to 20 headers can be configured per runtime, and each header value is limited to 4KB.
Amazon Bedrock AgentCore Runtime lets you pass headers in a request to your agent code provided the headers meet the following criteria:
-
Header name is a valid HTTP header (alphanumeric characters, hyphens, and underscores) and is not in the restricted headers list.
-
Headers starting with
x-amz-are not allowed (these are reserved for AWS SigV4 signing). -
Headers starting with
x-amzn-are not allowed, except for headers prefixed withX-Amzn-Bedrock-AgentCore-Runtime-Custom-. -
The
Authorizationheader requires the agent runtime to be configured with acustomJWTAuthorizerfor OAuth-based inbound access. -
Header value is not greater than 4KB in size.
-
Up to 20 headers can be configured per runtime.
-
Header names are case-insensitive and duplicates (by case-insensitive comparison) are not allowed.
Restricted headers
To maintain security and prevent exposure of sensitive information, the following headers are restricted and cannot be configured for propagation:
| Category | Headers |
|---|---|
|
Authentication & Authorization |
Proxy-Authorization, WWW-Authenticate |
|
Content Negotiation |
Accept, Accept-Charset, Accept-Encoding, Accept-Language, Content-Type, Content-Length, Content-Encoding, Content-Language, Content-Location, Content-Range |
|
Caching |
Cache-Control, ETag, Expires, If-Match, If-Modified-Since, If-None-Match, If-Range, If-Unmodified-Since, Last-Modified, Pragma, Vary |
|
Connection Management |
Connection, Keep-Alive, Proxy-Connection, Upgrade |
|
Request Context |
Host, User-Agent, Referer, From |
|
Range / Transfer |
Range, Accept-Ranges, Transfer-Encoding, TE, Trailer |
|
Server Information |
Server, Date, Location, Retry-After |
|
Cookies |
Set-Cookie, Cookie |
|
Security |
Content-Security-Policy, Content-Security-Policy-Report-Only, Strict-Transport-Security, X-Content-Type-Options, X-Frame-Options, X-XSS-Protection, Referrer-Policy, Permissions-Policy, Cross-Origin-Embedder-Policy, Cross-Origin-Opener-Policy, Cross-Origin-Resource-Policy |
|
CORS |
Access-Control-Allow-Origin, Access-Control-Allow-Methods, Access-Control-Allow-Headers, Access-Control-Allow-Credentials, Access-Control-Expose-Headers, Access-Control-Max-Age, Access-Control-Request-Method, Access-Control-Request-Headers, Origin |
|
Client Hints |
Accept-CH, Accept-CH-Lifetime, DPR, Width, Viewport-Width, Downlink, ECT, RTT, Save-Data |
|
Experimental / Proposed |
Clear-Site-Data, Feature-Policy, Expect-CT, Public-Key-Pins, Public-Key-Pins-Report-Only |
|
Proxy |
Via, Forwarded, X-Forwarded-For, X-Forwarded-Host, X-Forwarded-Proto, X-Real-IP, X-Requested-With, X-CSRF-Token |
|
IP Spoofing / URL Manipulation |
True-Client-IP, X-Client-IP, X-Cluster-Client-IP, X-Originating-IP, X-Source-IP, X-Original-URL, X-Original-Host, X-Rewrite-URL |
|
CDN / Proxy |
CF-Ray, CF-Connecting-IP, X-Amz-Cf-Id, X-Cache, X-Served-By |
|
HTTP/2 Pseudo Headers |
:method, :path, :scheme, :authority, :status |
|
Server Push |
Link |
|
WebSocket |
Sec-WebSocket-Key, Sec-WebSocket-Accept, Sec-WebSocket-Version, Sec-WebSocket-Protocol, Sec-WebSocket-Extensions |
In addition to the restricted headers listed above:
-
All headers starting with
x-amz-are restricted (for example,x-amz-security-token,x-amz-date,x-amz-content-sha256). These are reserved for AWS request signing. -
All headers starting with
x-amzn-are restricted, except for headers prefixed withX-Amzn-Bedrock-AgentCore-Runtime-Custom-.
Step 1: Create your agent
Create an AgentCore project using the AgentCore CLI:
agentcore create --name MyHeaderAgent cd MyHeaderAgent
Update your agent’s entrypoint file to access the custom headers from the request context:
import json from bedrock_agentcore import BedrockAgentCoreApp, RequestContext from strands import Agent app = BedrockAgentCoreApp() agent = Agent() @app.entrypoint def agent_invocation(payload, context: RequestContext): """Handler for agent invocation""" user_message = payload.get( "prompt", "No prompt found in input, please guide customer to create a json payload with prompt key" ) app.logger.info("invoking agent with user message: %s", payload) response = agent(user_message) # access request headers here request_headers = context.request_headers app.logger.info("Headers: %s", json.dumps(request_headers)) return response app.run()
Step 2: Configure and deploy your agent with custom headers
Configure the request header allowlist on your agent runtime so that custom headers are forwarded to your agent code at invocation time.
Example
Step 3: Invoke your agent with custom headers
Pass custom headers when invoking your agent so that your agent code can access them through the request context.
Example
Step 4: (Optional) Configure inbound JWT authentication
To pass the JWT token used for OAuth-based inbound access to your agent, configure authorizerType and authorizerConfiguration in your agent configuration.