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.
from portkey_ai import Portkeyportkey = Portkey( api_key = "PORTKEY_API_KEY", # defaults to os.environ.get("PORTKEY_API_KEY") provider = "@openai-prod" # Your AI Provider slug from Model Catalog)
import Portkey from 'portkey-ai';const portkey = new Portkey({ apiKey: 'PORTKEY_API_KEY', // defaults to process.env["PORTKEY_API_KEY"] provider: '@openai-prod' // Your AI Provider slug from Model Catalog});
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.
from portkey_ai import Portkeyportkey = Portkey( api_key = "PORTKEY_API_KEY", # defaults to os.environ.get("PORTKEY_API_KEY") config = "openai-config"# You can also send raw JSON# config = {"provider": "openai", "api_key": "OPENAI_API_KEY"})
import Portkey from 'portkey-ai';const portkey = new Portkey({ apiKey: 'PORTKEY_API_KEY', // defaults to process.env["PORTKEY_API_KEY"] config: 'openai-config'// You can also send raw JSON// config: {"provider": "openai", "api_key": "OPENAI_API_KEY"}});
Specifies the base URL where you want to send your request. Portkey validates custom host URLs and blocks private/reserved IP ranges by default. See Custom hosts for details.
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.
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)
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)
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.
from portkey_ai import Portkeyportkey = Portkey( api_key = "PORTKEY_API_KEY", # defaults to os.environ.get("PORTKEY_API_KEY") provider = "@openai-prod", X_Custom_Header = "....", Another_Header = "....", # The values in forward_headers list must be the original header names forward_headers = ['X-Custom-Header', 'Another-Header'])
import Portkey from 'portkey-ai';const portkey = new Portkey({ apiKey: 'PORTKEY_API_KEY', // defaults to process.env["PORTKEY_API_KEY"] provider: "@openai-prod", CustomHeader: "....", AnotherHeader: "....", forwardHeaders: ['CustomHeader', 'AnotherHeader']});
With the Python SDK, you need to transform your headers to Snake Case and then include them while initializing the Portkey 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.
With the JS SDK, you need to transform your headers to Camel Case and then include them while initializing the Portkey client.
Example: If you have a header of the format X-My-Custom-Header, it should be sent as xMyCustomHeader in the SDK
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
NodeJS
Python
REST Headers
Parameter
Type
Key
API Key Your Portkey account’s API Key.
stringrequired
apiKey
Virtual Key(Legacy — use provider with @provider-slug instead)
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
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
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