Headers
Last updated
Was this helpful?
Last updated
Was this helpful?
When making requests to the Portkey API, you need to include specific headers to authenticate your requests, specify the provider, and configure various features. This guide explains the essential and optional headers you can use to build applications on top of Portkey.
x-portkey-api-key
)The x-portkey-api-key
header is required to authenticate your requests and ensure secure access to the Portkey API. You can obtain your API key from the .
Example:
In addition to the API key, you must provide information about the AI provider you're using. There are four ways to do this:
2.1. Provider (x-portkey-provider
) + Authentication Header
x-portkey-provider
: Specifies the provider you're using (e.g., "openai", "anthropic"). See the list of .
Authorization
(or another appropriate auth header like x-api-key
or api-key
): Includes the necessary authentication details for the specified provider.
Example:
2.2. Virtual Key (x-portkey-virtual-key
)
x-portkey-virtual-key
: Allows you to use a pre-configured virtual key that encapsulates the provider and authentication details.
Example:
2.3. Config (x-portkey-config
)
x-portkey-config
: Accepts a JSON object or a config ID that contains the provider details and other configuration settings. Using a config object provides flexibility and allows for dynamic configuration of your requests.
Configs also enable other optional features like Caching, Load Balancing, Fallback, Retries, and Timeouts.
Example with JSON Object:
Example with Config ID:
2.4. Custom Host (x-portkey-custom-host
) + Provider (x-portkey-provider) + Authentication Header
Use this combination when connecting to a custom-hosted provider endpoint.
x-portkey-provider
indicates the provider type.
Authorization
(or the appropriate auth header) includes the authentication details for the custom endpoint.
There are additional optional Portkey headers that enable various features and enhancements:
1. Trace ID (x-portkey-trace-id
)
Example:
x-portkey-metadata
)Example:
x-portkey-cache-force-refresh
)Example:
x-portkey-cache-namespace
)x-portkey-cache-namespace
: Partition your cache store based on custom strings, ignoring metadata and other headers.
Example:
x-portkey-request-timeout
)x-portkey-request-timeout
: Set timeout after which a request automatically terminates. The time is set in milliseconds.
Example:
x-portkey-forward-headers
)Example:
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
AWS Bedrock
x-portkey-aws-session-token
, x-portkey-aws-secret-access-key
, x-portkey-aws-region
, x-portkey-aws-session-token
For a comprehensive list of all available parameters and their detailed descriptions, please refer to the Portkey SDK Client documentation.
You can send these headers through REST API calls as well as by using the OpenAI or Portkey SDKs. With the Portkey SDK, Other than cacheForceRefresh
, traceID
, and metadata
, rest of the headers are passed while instantiating the Portkey client.
Virtual keys can be created and managed through the Portkey dashboard. ()
Configs can be saved in the Portkey UI and referenced by their ID as well. ()
x-portkey-custom-host
specifies the URL of the custom endpoint. ()
x-portkey-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. ()
x-portkey-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. ()
x-portkey-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. ()
x-portkey-forward-headers
: Allows you to forward sensitive headers directly to your model's API without any processing by Portkey. Expects an array of strings
. ()