context.Context to pass configuration and metadata through the request lifecycle. Context keys allow you to customize request behavior, pass request-specific settings, and read metadata set by Bifrost.
Request Configuration Keys
These keys can be set before making a request to customize behavior.Extra Headers
Pass custom headers with individual requests. Headers are automatically propagated to the provider.See Custom Headers Per Request for detailed information on header handling and security restrictions.
API Key Name Selection
Explicitly select a named API key from your configured keys.Direct Key
Bypass key selection and provide credentials directly. Useful for dynamic key scenarios.Skip Key Selection
Skip the key selection process entirely and pass an empty key to the provider. Useful for providers that don’t require authentication or when using ambient credentials.Request ID
Set a custom request ID for tracking and correlation.Custom URL Path
Append a custom path to the provider’s base URL. Useful for accessing provider-specific endpoints.Raw Request Body
Send a raw request body instead of Bifrost’s standardized format. The provider receives your payload as-is. You must both enable the context key AND set theRawRequestBody field on your request.
When using raw request body, Bifrost bypasses its request conversion and sends your payload directly to the provider. You’re responsible for ensuring the payload matches the provider’s expected format.
Send Back Raw Request/Response
Include the original request or response in theExtraFields for debugging.
Response Metadata Keys
These keys are set by Bifrost and can be read from the context after a request completes. They’re particularly useful in plugins and hooks.Selected Key Information
After Bifrost selects an API key, it stores the selection details in the context.Retry and Fallback Information
Track retry attempts and fallback progression.Stream End Indicator
For streaming responses, indicates when the stream has completed.Plugin developers: When implementing custom streaming in PreHook or PostHook, make sure to mark
BifrostContextKeyStreamEndIndicator as true at the end of the stream for proper cleanup.Integration Type
Identifies which integration format is being used (useful in gateway scenarios).Complete Example
Here’s a comprehensive example showing multiple context keys in use:Context Keys Reference
| Key | Type | Direction | Description |
|---|---|---|---|
BifrostContextKeyVirtualKey | string | Set | Virtual key identifier |
BifrostContextKeyAPIKeyName | string | Set | Explicit API key name selection |
BifrostContextKeyRequestID | string | Set | Custom request ID for tracking |
BifrostContextKeyFallbackRequestID | string | Read | Request ID when using fallback |
BifrostContextKeyDirectKey | schemas.Key | Set | Direct key credentials |
BifrostContextKeySelectedKeyID | string | Read | Selected key’s ID |
BifrostContextKeySelectedKeyName | string | Read | Selected key’s name |
BifrostContextKeyNumberOfRetries | int | Read | Number of retry attempts |
BifrostContextKeyFallbackIndex | int | Read | Current fallback index |
BifrostContextKeyStreamEndIndicator | bool | Read | Stream completion flag |
BifrostContextKeySkipKeySelection | bool | Set | Skip key selection |
BifrostContextKeyExtraHeaders | map[string][]string | Set | Custom request headers |
BifrostContextKeyURLPath | string | Set | Custom URL path suffix |
BifrostContextKeyUseRawRequestBody | bool | Set | Use raw request body |
BifrostContextKeySendBackRawRequest | bool | Set | Include raw request in response |
BifrostContextKeySendBackRawResponse | bool | Set | Include raw response |
BifrostContextKeyIntegrationType | string | Read | Integration format type |
BifrostContextKeyUserAgent | string | Read | Request user agent |
Next Steps
- Provider Configuration - Configure providers and keys
- Streaming Responses - Real-time response handling
- Tool Calling - Enable AI function calling
- Core Features - Advanced Bifrost capabilities

