Headers
Header requirements and options for the Portkey API
Portkey API accepts 4 kinds of headers for your requests:
Portkey Authentication Header | Required | For Portkey auth |
Provider Authentication Headers OR Cloud-Specific Headers | Required | For provider auth |
Additional Portkey Headers | Optional | To pass config , metadata , trace id , cache refresh etc. |
Custom Headers | Optional | To forward any other headers directly |
Portkey Authentication
Portkey API Key
Authenticate your requests with your Portkey API key. Obtain API key from the Portkey dashboard.
Environment variable: PORTKEY_API_KEY
Provider Authentication
In addition to the Portkey API key, you must provide information about the AI provider you’re using. There are 4 ways to do this:
1. Provider Slug + Auth
Useful if you do not want to save your API keys to Portkey vault and make direct requests.
Specifies the provider you’re using (e.g., openai
, anthropic
, vertex-ai
).
List of Portkey supported providers here.
Pass the auth details for the specified provider as a "Bearer $TOKEN"
.
If your provider expects their auth with headers such as x-api-key
or api-key
, you can pass the token with the Authorization
header directly and Portkey will convert it into the provider-specific format.
2. Virtual Key
Save your provider auth on Portkey and use a virtual key to directly make a call. Docs)
3. Config
Pass your Portkey config with this header. Accepts a JSON object
or a config ID
that can also contain gateway configuration settings, and provider details.
- Configs can be saved in the Portkey UI and referenced by their ID (Docs)
- Configs also enable other optional features like Caching, Load Balancing, Fallback, Retries, and Timeouts.
4. Custom Host
Specifies the base URL where you want to send your request
Target provider that’s availabe on your base URL. If you are unsure of which target provider to set, you can set openai
.
Pass the auth details for the specified provider as a "Bearer $TOKEN"
.
If your provider expects their auth with headers such as x-api-key
or api-key
, you can pass the token with the Authorization
header directly and Portkey will convert it into the provider-specific format.
Additional Portkey Headers
There are additional optional Portkey headers that enable various features and enhancements:
Trace ID
An ID you can pass to refer to one or more requests later on. If not provided, Portkey generates a trace ID automatically for each request. (Docs)
Metadata
Allows you to attach custom metadata to your requests, which can be filtered later in the analytics and log dashboards.
You can include the special metadata type _user
to associate requests with specific users. (Docs)
Cache Force Refresh
Forces a cache refresh for your request by making a new API call and storing the updated value.
Expects true
or false
See the caching documentation for more information. (Docs)
Cache Namespace
Partition your cache store based on custom strings, ignoring metadata and other headers.
Request Timeout
Set timeout after which a request automatically terminates. The time is set in milliseconds.
Custom Headers
You can pass any other headers your API expects by directly forwarding them without any processing by Portkey.
This is especially useful if you want to pass send sensitive headers.
Forward Headers
Pass all the headers you want to forward directly in this array. (Docs)
Cloud-Specific Headers (Azure
, Google
, AWS
)
Pass more configuration headers for Azure OpenAI
, Google Vertex AI
, or AWS Bedrock
Azure
x-portkey-azure-resource-name
,x-portkey-azure-deployment-id
,x-portkey-azure-api-version
,Authorization
,x-portkey-azure-model-name
Google Vertex AI
x-portkey-vertex-project-id
,x-portkey-vertex-region
,X-Vertex-AI-LLM-Request-Type
AWS Bedrock
x-portkey-aws-session-token
,x-portkey-aws-secret-access-key
,x-portkey-aws-region
,x-portkey-aws-session-token
List of All Headers
The following is a comprehensive list of headers that can be used when initializing the Portkey client.
Portkey adheres to language-specific naming conventions:
- camelCase for JavaScript/Node.js parameters
- snake_case for Python parameters
- hyphenated-keys for HTTP headers
Parameter | Type | Key |
---|---|---|
API Key Your Portkey account’s API Key. | stringrequired | apiKey |
Virtual Key The virtual key created from Portkey’s vault for a specific provider | string | virtualKey |
Config The slug or config object to use | stringobject | config |
Provider The AI provider to use for your calls. (supported providers). | string | provider |
Base URL You can edit the URL of the gateway to use. Needed if you’re self-hosting the AI gateway | string | baseURL |
Trace ID An ID you can pass to refer to 1 or more requests later on. Generated automatically for every request, if not sent. | string | traceID |
Metadata Any metadata to attach to the requests. These can be filtered later on in the analytics and log dashboards Can contain _prompt , _user , _organisation , or _environment that are special metadata types in Portkey. You can also send any other keys as part of this object. | object | metadata |
Cache Force Refresh Force refresh the cache for your request by making a new call and storing that value. | boolean | cacheForceRefresh |
Cache Namespace Partition your cache based on custom strings, ignoring metadata and other headers. | string | cacheNamespace |
Custom Host Route to locally or privately hosted model by configuring the API URL with custom host | string | customHost |
Forward Headers Forward sensitive headers directly to your model’s API without any processing from Portkey. | array of string | forwardHeaders |
Azure OpenAI Headers Configuration headers for Azure OpenAI that you can send separately | string | azureResourceName azureDeploymentId azureApiVersion azureModelName |
Google Vertex AI Headers Configuration headers for Vertex AI that you can send separately | string | vertexProjectId vertexRegion |
AWS Bedrock Headers Configuration headers for Bedrock that you can send separately | string | awsAccessKeyId awsSecretAccessKey awsRegion awsSessionToken |
Parameter | Type | Key |
---|---|---|
API Key Your Portkey account’s API Key. | stringrequired | apiKey |
Virtual Key The virtual key created from Portkey’s vault for a specific provider | string | virtualKey |
Config The slug or config object to use | stringobject | config |
Provider The AI provider to use for your calls. (supported providers). | string | provider |
Base URL You can edit the URL of the gateway to use. Needed if you’re self-hosting the AI gateway | string | baseURL |
Trace ID An ID you can pass to refer to 1 or more requests later on. Generated automatically for every request, if not sent. | string | traceID |
Metadata Any metadata to attach to the requests. These can be filtered later on in the analytics and log dashboards Can contain _prompt , _user , _organisation , or _environment that are special metadata types in Portkey. You can also send any other keys as part of this object. | object | metadata |
Cache Force Refresh Force refresh the cache for your request by making a new call and storing that value. | boolean | cacheForceRefresh |
Cache Namespace Partition your cache based on custom strings, ignoring metadata and other headers. | string | cacheNamespace |
Custom Host Route to locally or privately hosted model by configuring the API URL with custom host | string | customHost |
Forward Headers Forward sensitive headers directly to your model’s API without any processing from Portkey. | array of string | forwardHeaders |
Azure OpenAI Headers Configuration headers for Azure OpenAI that you can send separately | string | azureResourceName azureDeploymentId azureApiVersion azureModelName |
Google Vertex AI Headers Configuration headers for Vertex AI that you can send separately | string | vertexProjectId vertexRegion |
AWS Bedrock Headers Configuration headers for Bedrock that you can send separately | string | awsAccessKeyId awsSecretAccessKey awsRegion awsSessionToken |
Parameter | Type | Key |
---|---|---|
API Key Your Portkey account’s API Key. | stringrequired | api_key |
Virtual Key The virtual key created from Portkey’s vault for a specific provider | string | virtual_key |
Config The slug or config object to use | stringobject | config |
Provider The AI provider to use for your calls. (supported providers). | string | provider |
Base URL You can edit the URL of the gateway to use. Needed if you’re self-hosting the AI gateway | string | base_url |
Trace ID An ID you can pass to refer to 1 or more requests later on. Generated automatically for every request, if not sent. | string | trace_id |
Metadata Any metadata to attach to the requests. These can be filtered later on in the analytics and log dashboards Can contain _prompt , _user , _organisation , or _environment that are special metadata types in Portkey. You can also send any other keys as part of this object. | object | metadata |
Cache Force Refresh Force refresh the cache for your request by making a new call and storing that value. | boolean | cache_force_refresh |
Cache Namespace Partition your cache based on custom strings, ignoring metadata and other headers. | string | cache_namespace |
Custom Host Route to locally or privately hosted model by configuring the API URL with custom host | string | custom_host |
Forward Headers Forward sensitive headers directly to your model’s API without any processing from Portkey. | array of string | forward_headers |
Azure OpenAI Headers Configuration headers for Azure OpenAI that you can send separately | string | azure_resource_name azure_deployment_id azure_api_version azure_model_name |
Google Vertex AI Headers Configuration headers for Vertex AI that you can send separately | string | vertex_project_id vertex_region |
AWS Bedrock Headers Configuration headers for Bedrock that you can send separately | string | aws_access_key_id aws_secret_access_key aws_region aws_session_token |
Parameter | Type | Header Key |
---|---|---|
API Key Your Portkey account’s API Key. | stringrequired | x-portkey-api-key |
Virtual Key The virtual key created from Portkey’s vault for a specific provider | string | x-portkey-virtual-key |
Config The slug or config object to use | string | x-portkey-config |
Provider The AI provider to use for your calls. (supported providers). | string | x-portkey-provider |
Base URL You can edit the URL of the gateway to use. Needed if you’re self-hosting the AI gateway | string | Change the request URL |
Trace ID An ID you can pass to refer to 1 or more requests later on. Generated automatically for every request, if not sent. | string | x-portkey-trace-id |
Metadata Any metadata to attach to the requests. These can be filtered later on in the analytics and log dashboards Can contain _prompt , _user , _organisation , or _environment that are special metadata types in Portkey. You can also send any other keys as part of this object. | string | x-portkey-metadata |
Cache Force Refresh Force refresh the cache for your request by making a new call and storing that value. | boolean | x-portkey-cache-force-refresh |
Cache Namespace Partition your cache based on custom strings, ignoring metadata and other headers | string | x-portkey-cache-namespace |
Custom Host Route to locally or privately hosted model by configuring the API URL with custom host | string | x-portkey-custom-host |
Forward Headers Forward sensitive headers directly to your model’s API without any processing from Portkey. | array of string | x-portkey-forward-headers |
Azure OpenAI Headers Configuration headers for Azure OpenAI that you can send separately | string | x-portkey-azure-resource-name , x-portkey-azure-deployment-id , x-portkey-azure-api-version , x-portkey-azure-model-name |
Google Vertex AI Headers Configuration headers for Vertex AI that you can send separately | string | x-portkey-vertex-project-id , x-portkey-vertex-region |
AWS Bedrock Headers Configuration headers for Bedrock that you can send separately | string | x-portkey-aws-session-token , x-portkey-aws-secret-access-key , x-portkey-aws-region , x-portkey-aws-session-token |
Using Headers
You can send these headers in multiple ways: