Skip to main content
AI Gateway API accepts 4 kinds of headers for your requests:

AI Gateway Authentication

AI Gateway API Key

string
required
Authenticate your requests with your AI Gateway API key, passed as Bearer $PORTKEY_API_KEY. Obtain API key from the Strata Cloud Manager.
Environment variable: PORTKEY_API_KEY
The x-portkey-api-key header remains active and continues to authenticate requests. Authorization is the standard way to authenticate into the gateway; use x-portkey-api-key when Authorization is already carrying provider credentials, as in Provider Slug + Auth below.

Provider Authentication

In addition to the AI Gateway 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 the AI Gateway vault and make direct requests.
string
Specifies the provider you’re using (e.g., openai, anthropic, vertex-ai).
List of the AI Gateway supported providers here.
string
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 the AI Gateway will convert it into the provider-specific format.
Here Authorization carries the provider credential, so authenticate into the gateway with the x-portkey-api-key header instead. The provider authentication methods that resolve a provider from the Model Catalog leave Authorization free for your AI Gateway API key.

2. AI Provider

string
Specify your AI Provider slug (from Model Catalog) to route requests through a managed provider. Use the @provider-slug format. (Docs)
You usually do not need this header. Prefixing the model with the slug — "model": "@openai-prod/gpt-4o" — selects the provider inline and is the form used throughout these docs. Use the header when the endpoint takes no model parameter, such as Files and Batches, or when you are routing with a bare provider name and passing the provider’s own credential in Authorization.
The x-portkey-virtual-key / virtual_key / virtualKey parameter is the legacy equivalent and still works for backward compatibility.

3. Config

string or JSON
Pass your AI Gateway 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 Strata Cloud Manager and referenced by their ID (Docs)
  • Configs also enable other optional features like Caching, Load Balancing, Fallback, Retries, and Timeouts.

4. Custom Host

string
Specifies the base URL where you want to send your request. The AI Gateway validates custom host URLs and blocks private/reserved IP ranges by default. See Custom hosts for details.
string
Target provider that’s availabe on your base URL. If you are unsure of which target provider to set, you can set openai.
string
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 the AI Gateway will convert it into the provider-specific format.
Here Authorization carries the provider credential, so authenticate into the gateway with the x-portkey-api-key header instead. The provider authentication methods that resolve a provider from the Model Catalog leave Authorization free for your AI Gateway API key.

Additional AI Gateway Headers

There are additional optional AI Gateway headers that enable various features and enhancements:

Trace ID

string
An ID you can pass to refer to one or more requests later on. If not provided, the AI Gateway generates a trace ID automatically for each request. (Docs)

Metadata

JSON
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

boolean
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

string
Partition your cache store based on custom strings, ignoring metadata and other headers.

Request Timeout

integer
Set timeout after which a request automatically terminates. The time is set in milliseconds.

Fetch Integrated Models

boolean
Applies to GET /v1/models only. When true, forces the endpoint to return the AI Gateway’s integrated (Model Catalog) models even when a provider or config is passed on the request. Without this header, any provider signal causes the endpoint to proxy to the upstream provider’s /v1/models. You can also set this as fetch_integrated_models: true inside an AI Gateway config. (Docs)

Custom Headers

You can pass any other headers your API expects by directly forwarding them without any processing by the AI Gateway.
This is especially useful if you want to pass send sensitive headers.

Forward Headers

array of strings
Pass all the headers you want to forward directly in this array. (Docs)

Python Usage

With the Python SDK, you need to transform your headers to Snake Case and then include them while initializing the AI Gateway client. Example: If you have a header of the format X-My-Custom-Header, it should be sent as X_My_Custom_Header in the SDK.Note: When using forward_headers, ensure the header names in the list are in their original format (e.g., X-My-Custom-Header), not the snake case format.

JavaScript Usage

With the JS SDK, you need to transform your headers to Camel Case and then include them while initializing the AI Gateway client. Example: If you have a header of the format X-My-Custom-Header, it should be sent as xMyCustomHeader in the SDK

Mask Sensitive Headers in Logs

array of strings
List of header names whose values the AI Gateway should mask (hash) in request, response, and trace logs. Matching is case-insensitive.
x-portkey-sensitive-headers only controls log masking. It does not forward headers to the upstream provider. If you need both behaviors, use:
  • x-portkey-forward-headers to forward the header upstream
  • x-portkey-sensitive-headers to mask that header’s value in AI Gateway logs
For organisation-wide defaults, set ORGANISATION_HEADERS_TO_MASK (comma-separated header names) in your gateway environment to mask matching headers across requests.

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 AI Gateway client. The AI Gateway adheres to language-specific naming conventions:
  • camelCase for JavaScript/Node.js parameters
  • snake_case for Python parameters
  • hyphenated-keys for HTTP headers

Using Headers

You can send these headers in multiple ways:
Last modified on September 15, 2026