SDK
Last updated
Was this helpful?
Last updated
Was this helpful?
The Portkey SDK client enables various features of Portkey in an easy to use config-as-code
paradigm.
Add the Portkey SDK to your application to interact with Portkey's gateway.
The basic Portkey SDK client needs 2 required parameters
The Portkey Account's API key to authenticate all your requests
The of the AI provider you want to use OR The being used
This is achieved through headers when you're using the REST API.
For example,
Find more info on what's available through .
You can then use the client to make completion and other calls like this
You can choose to override the configuration in individual requests as well and send trace id or metadata along with each request.
Portkey's Python SDK supports Async usage - just use AsyncPortkey
instead of Portkey
with await
:
Following are the parameter keys that you can add while creating the Portkey client.
Keeping in tune with the most popular language conventions, we use:
camelCase for Javascript keys
snake_case for Python keys
hyphenated-keys for the headers
API Key Your Portkey account's API Key.
apiKey
Virtual Key The virtual key created from Portkey's vault for a specific provider
virtualKey
config
provider
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.
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.
metadata
Cache Force Refresh Force refresh the cache for your request by making a new call and storing that value.
cacheForceRefresh
Cache Namespace Partition your cache based on custom strings, ignoring metadata and other headers.
cacheNamespace
Custom Host Route to locally or privately hosted model by configuring the API URL with custom host
customHost
Forward Headers Forward sensitive headers directly to your model's API without any processing from Portkey.
forwardHeaders
Azure OpenAI Headers Configuration headers for Azure OpenAI that you can send separately
azureResourceName
azureDeploymentId
azureApiVersion
azureModelName
Google Vertex AI Headers Configuration headers for Vertex AI that you can send separately
vertexProjectId
vertexRegion
AWS Bedrock Headers Configuration headers for Bedrock that you can send separately
awsAccessKeyId awsSecretAccessKey awsRegion awsSessionToken
Find more info on what's available through .
Config The slug or to use
Provider The AI provider to use for your calls. ().
Base URL You can edit the URL of the gateway to use. Needed if you're
Config The slug or to use
Provider The AI provider to use for your calls. ().
Base URL You can edit the URL of the gateway to use. Needed if you're
Config The slug or to use
Provider The AI provider to use for your calls. ().
Base URL You can edit the URL of the gateway to use. Needed if you're