Subchapter 14.9
references/request-headers.mdMarkdown7 KBView on GitHub
Pass custom HTTP headers from the caller through to your agent’s invocation code.
Scripts
Process Payment ToolAgentCore Runtime strips all incoming headers from the request before it reaches your agent code except:
Authorization — always passed throughX-Amzn-Bedrock-AgentCore-Runtime-Custom-* — this is the reserved prefix for custom headersAnything else — X-Tenant-Id, X-Correlation-Id, traceparent, A2A-Version, Idempotency-Key, whatever — will not appear in your invocation context unless you explicitly add it to the runtime’s request header allowlist.
This is an intentional security boundary: the runtime doesn’t forward arbitrary caller-supplied headers by default. It’s also the #1 reason developers ask “why can’t my agent see the header I’m sending?”
Rename headers at the caller to use the X-Amzn-Bedrock-AgentCore-Runtime-Custom- prefix. These pass through without any runtime configuration change.
# Caller sends:
X-Amzn-Bedrock-AgentCore-Runtime-Custom-Tenant-Id: acme-corp
X-Amzn-Bedrock-AgentCore-Runtime-Custom-Correlation-Id: 8b2e3d...
# Agent code sees the same headers in the invocation contextThis is the simplest option for headers you control end-to-end (your app, your agent).
If the header names are fixed by a protocol or external system (A2A requires A2A-Version and A2A-Extensions; OpenTelemetry uses traceparent and baggage; some APIs use Idempotency-Key), you can’t rename them. Configure the runtime to allow them explicitly.
Edit agentcore/agentcore.json and add requestHeaderAllowlist to the runtime entry:
{
"runtimes": [
{
"name": "MyAgent",
"requestHeaderAllowlist": [
"X-Amzn-Bedrock-AgentCore-Runtime-Custom-X-Tenant-Id",
"X-Amzn-Bedrock-AgentCore-Runtime-Custom-A2A-Version"
]
}
]
}Then agentcore deploy. The $schema URL at the top of the file (https://schema.agentcore.aws.dev/v1/agentcore.json) gives IDE autocomplete and validation for every field.
CLI shortcut — agentcore add agent --request-header-allowlist "X-Tenant-Id,A2A-Version" writes the same array. Important: the CLI auto-prefixes entries with X-Amzn-Bedrock-AgentCore-Runtime-Custom- as they land in agentcore.json. If you’re editing the JSON by hand, write the prefixed form directly. If you’re using the CLI, pass the short name and let the CLI add the prefix.
Authorization passes through by default and doesn’t need to be in the allowlist.
Authorization if you include it explicitly)If you hit the 20-header cap, combine related data into one JSON-encoded header rather than using many separate ones.
Caller: X-Tenant-Id: acme-corp
Agent code: reads tenant from the header, scopes memory/data/tools per tenantAdd X-Tenant-Id to the allowlist. The agent can then isolate memory namespaces, database queries, and tool-call authorization per tenant.
Caller: traceparent: 00-<trace-id>-<span-id>-01
baggage: userId=alice,env=prod
Agent code: uses OTel SDK to continue the parent traceAdd traceparent and baggage to the allowlist. Your OTel SDK instrumentation will pick them up automatically and produce spans connected to the caller’s trace.
Caller: A2A-Version: 1.0
A2A-Extensions: x-capability-foo
Agent code: branches behavior based on protocol versionA2A v1.0 requires these headers. Add both to the allowlist; A2A v0.3 doesn’t need either.
Caller: Idempotency-Key: 7f3a...
Agent code: deduplicates or caches based on the keyFor agents that call external APIs with idempotency, propagating the caller’s key through to the agent’s outbound calls avoids duplicate side effects on retry.
Headers arrive in the runtime’s context object passed to your invocation handler. The exact accessor depends on the framework — check the bedrock-agentcore SDK docs for your language. In Python:
@app.entrypoint
def invoke(payload, context):
tenant = context.headers.get("X-Tenant-Id")
correlation_id = context.headers.get("X-Correlation-Id")
# ... use as neededHeaders that weren’t in the allowlist will be absent (not empty string) from the context.
requestHeaderConfiguration if a header you expect to see isn’t arriving.agents-connect Path D.“My agent doesn’t see the header I’m sending”
Check (in order): (1) Is the header in the allowlist? (2) Is the spelling an exact match including case? (3) Did you redeploy the runtime after updating the allowlist? (4) Is the caller actually sending the header — curl -v or equivalent network inspection.
“I hit the 20-header limit”
Consolidate related data into a single JSON-encoded header. For example, instead of X-Region, X-Environment, X-Service-Name as three separate headers, use X-Context: {"region":"us-west-2","env":"prod","service":"billing"}.
“Allowlist update didn’t take effect”
Redeploy the runtime. The header allowlist is config that applies on the next agentcore deploy, not immediately after editing agentcore.json.