Headers in TypeScript SDK
Copy page
Define and validate HTTP headers in the TypeScript SDK to pass dynamic context for personalized agent interactions.
Overview
Headers allow you to pass request-specific values (like user IDs, authentication tokens, or organization metadata) to your Agent at runtime via HTTP headers. These values are validated, cached per conversation, and made available throughout your Agent system for:
- Context Fetchers: Dynamic data retrieval based on request values
- External Tools: Authentication and personalization for API calls
- Agent Prompts: Personalized responses using context variables
Passing context via headers
Include context values as HTTP headers when calling your agent API. These headers are validated against your configured schema and cached for the conversation.
Header keys are normalized to lowercase. Define them as lowercase in your schema and reference them as lowercase in templates.
Configuring headers
Define a schema for your headers and configure how it's used in your agent. You must include the headers schema in your context config.
How it works
Validation: Headers are validated against your configured schema when a request arrives
Caching: Validated context is cached per conversation for reuse across multiple interactions
Reuse: Subsequent requests with the same conversationId automatically use cached context values
Updates: Provide new header values to update the context for an ongoing conversation
Context values persist across conversation turns. To update them, send new header values with the same conversation ID.
Using headers in your agents
Header values can be used in your agent prompts and fetch definitions using JSONPath template syntax {{headers.field_name}}.
You can use the headers schema's toTemplate() method for type-safe templating with autocomplete and validation.
In Context Fetchers
Use header values to fetch dynamic data from external APIs:
In Agent Prompts
Reference context directly in agent prompts for personalization using the context config's template method:
In External Tools
Configure external agents or MCP servers with dynamic headers using the headers schema:
Verified claims from authenticated sessions
When using authenticated chat sessions, non-standard claims from the customer-signed JWT are automatically extracted and made available as verified claims in the conversation context. Unlike headers and userProperties, verified claims are cryptographically verified and cannot be modified by the client.
| Source | Trust level | Mutability |
|---|---|---|
| Headers | Validated against schema | Updated per-request |
| User properties | Unverified, client-provided | Client can modify freely |
| Verified claims | Cryptographically signed via JWT | Immutable for the session |
Verified claims are available at metadata.verifiedClaims in the execution context and are persisted in conversation metadata. Any non-standard claims in the JWT (e.g., email, org_id, role, or custom claims) are extracted automatically. Standard JWT claims (iss, aud, exp, iat, nbf, jti) are excluded.
Verified claims are limited to 1KB. Tokens with claims exceeding this limit are rejected.
Using verified claims in prompts
You can reference verified claims to personalize agent behavior with trusted identity data:
Use verified claims for authorization and identity decisions. Use headers and userProperties for non-sensitive personalization like display preferences.
For setup instructions, see Authenticated chat sessions.
Best practices
- Use lowercase keys: Always define schema properties in lowercase and reference them as lowercase in templates
- Validate early: Test your schema configuration with sample headers before deploying
- Cache wisely: Remember that context persists per conversation - design accordingly
- Secure sensitive data: For long-lived secrets, use the Credentials system instead of headers
- Keep it minimal: Only include context values that are actually needed by your agents
Common use cases
Multi-tenant applications
Pass tenant-specific configuration to customize agent behavior per customer:
User authentication
Provide user identity and session information for personalized interactions:
API gateway integration
Forward headers from your API gateway for consistent authentication:
Widget-provided headers
When using the Inkeep chat components, the following headers are automatically sent with each request:
| Header | Description | Example Value |
|---|---|---|
x-inkeep-client-timestamp | The client's current timestamp in ISO 8601 format | 2025-01-30T18:15:00.000Z |
x-inkeep-client-timezone | The client's timezone identifier | America/New_York |
These headers are useful for providing time-aware responses:
Troubleshooting
Invalid headers errors
If you receive a 400 error about invalid headers:
- Verify your schema matches the headers you're sending
- Ensure all header keys are lowercase
- Check that required fields are present
- Validate the data types match your schema
Context not persisting
If context values aren't available in subsequent requests:
- Ensure you're using the same
conversationIdacross requests - Verify headers are being sent correctly
- Check that your context config is properly attached to the Agent
Related documentation
- Context Fetchers - Learn about fetching and caching external data
- External Agents - Configure external agent integrations
- Credentials - Manage secure credentials for your Agents
- App Credentials - Authentication for chat components, including authenticated sessions