The Portkey.ai Python client library provides an interface to the Portkey API, a unified AI gateway for managing, monitoring, and routing large language model (LLM) requests. It offers features like observability, caching, load balancing, and prompt management across various LLM providers. The library is actively maintained, with frequent updates.
pip install portkey-aiVerified import paths — ran on the pinned version, not inferred.
Initializes the Portkey client using the `PORTKEY_API_KEY` environment variable and directs requests through a configured provider slug (e.g., `@openai-prod`). It then makes a chat completion request using a model available via that provider.
Review the Portkey and OpenAI SDK changelogs for relevant updates. Test existing integrations thoroughly after upgrading to v2.0.0 or later. Consult Portkey documentation for updated usage patterns, especially for advanced configurations or when directly interacting with vendored client internals.
Ensure `PORTKEY_API_KEY` is set for the `Portkey` client. Manage LLM provider keys via Portkey's dashboard (recommended) and use provider slugs (e.g., `@openai-prod`) or `config` objects. Alternatively, provide provider-specific `Authorization` headers to the `Portkey` client for direct pass-through of provider keys.
Always use the full `@provider-slug/model-name` format for the `model` parameter when using the `provider` argument in the client constructor. Alternatively, define a `config` object for the `Portkey` client that specifies the desired routing strategy and provider details. Refer to the Portkey Model Catalog documentation for valid provider slugs and model names.
Ensure the PORTKEY_API_KEY environment variable is set correctly with an active API key from your Portkey dashboard, or pass it directly to the Portkey client constructor.
Set the appropriate provider API key (e.g., OPENAI_API_KEY) in your environment variables, configure it as a virtual key in the Portkey dashboard, or pass it via `Authorization` header in the Portkey client.
Include either the `x-portkey-config` header with your configuration slug or the `x-portkey-provider` header with the target provider slug in your API request.
Verify the model name against the Portkey model catalog or the provider's documentation, and ensure your Portkey configuration or provider settings allow access to that model.
Implement retry logic with exponential backoff, use Portkey's built-in rate limit management features, or check your usage and limits on the Portkey dashboard and the LLM provider's platform.
No dependency data recorded yet.