portkey-ai
Python client library for the Portkey API
What it is and what it does
Portkey is a Python client for the Portkey API that intercepts calls to OpenAI-compatible LLM providers and adds enterprise features on top. It maintains full API compatibility with the OpenAI SDK pattern, so you can adopt Portkey and immediately gain access to automated failover, load balancing across models, semantic caching, request tracing, and custom metadata tagging—all without rewriting your application logic.
The package is built on httpx, pydantic, and anyio, enabling both sync and async usage patterns. It supports integrations with agent frameworks and offers virtual key management to keep API credentials secure. Observability features include request logging, tracing, feedback collection, and analytics. The SDK is actively maintained and supports Python 3.8 and later.
Use it for:
- Route LLM requests across multiple providers or models to reduce latency and cost via load balancing and semantic caching.
- Implement automatic fallback to a secondary model or provider when the primary service is unavailable or slow.
- Monitor and debug LLM application behavior with request tracing, custom metadata, and weighted user feedback.
- Secure API keys by storing them in Portkey's vault and using disposable virtual keys instead of embedding credentials.
- Integrate LLM calls into agent frameworks while retaining Portkey's observability and routing features.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Portkey is a Python SDK that wraps OpenAI-compatible APIs to add monitoring, failover, load balancing, caching, and observability without rewriting existing code.
Yes. Portkey is actively maintained, has no known vulnerabilities, and offers genuine value for production LLM applications—especially if you need failover, load balancing, or observability without refactoring existing code. The MIT License is permissive. Install friction is low. The main prerequisite is a Portkey account and API key.
Install
portkey-ai on PyPI
pip
pip install portkey-aiuv
uv add portkey-aipoetry
poetry add portkey-aiInstalling portkey-ai
Before you install
Low install friction with a pure-Python wheel and 10 runtime dependencies. Actively maintained with a release 22 days ago.
License in practice
MIT License permits commercial use, modification, and distribution with minimal restrictions—suitable for most projects.
Quickstart
pip install portkey-ai
export PORTKEY_API_KEY=your_key
from portkey_ai import Portkey
portkey = Portkey(
api_key="PORTKEY_API_KEY",
virtual_key="VIRTUAL_KEY"
)
chat_completion = portkey.chat.completions.create(
messages=[{"role": "user", "content": "Say this is a test"}],
model="gpt-4"
)
print(chat_completion)
Requires a Portkey account and API key; virtual keys must be configured in Portkey's dashboard before use.
Verify before relying
- Whether the 40+ production-critical metrics mentioned in analytics are documented or accessible via the SDK.
- Performance overhead of semantic caching and request tracing relative to direct API calls.
- Support status for providers beyond OpenAI-like implementations (fact sheet lists 'any OpenAI-like provider' but does not enumerate them).
Package facts
| License | MIT License (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 10 — httpx, typing_extensions, pydantic, anyio, distro, sniffio, cached-property, tqdm, types-requests, jiter |
| Maintenance | actively maintained — 22 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 976,864/month — #4,592 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: portkey_ai-2.3.4-py3-none-any.whl
Tags
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to…
permissive · top 100 on PyPI
huggingface-hubClient library and CLI tool for downloading,…
permissive · top 100 on PyPI
langchainLangChain provides a framework for building…
permissive · top 1,000 on PyPI
hf-xethf-xet provides chunk-based deduplication and…
permissive · top 1,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
transformersTransformers provides a unified framework for…
permissive · top 1,000 on PyPI
openinference-instrumentation-portkeyAutomatically instruments Portkey AI API calls…
permissive · top 15,000 on PyPI
openaiProvides a Python client library for the OpenAI…
permissive · top 1,000 on PyPI
any-llm-sdkProvides a unified Python interface to…
permissive · top 15,000 on PyPI
llama-index-llms-openaiIntegrates OpenAI's language models into…
permissive · top 1,000 on PyPI
litellm-enterpriseLiteLLM Enterprise provides a unified Python…
unclear · top 5,000 on PyPI
openai-chatkitA backend SDK for building chat applications…
unclear · top 15,000 on PyPI
livekit-plugins-openaiIntegrates OpenAI's Realtime, Responses, LLM,…
permissive · top 5,000 on PyPI
llm-openai-pluginA plugin that extends LLM to access OpenAI…
permissive · top 15,000 on PyPI
astra-assistantsWraps OpenAI's Assistants API as a drop-in…
unclear · top 15,000 on PyPI