skillfed

portkey-ai

Python client library for the Portkey API

portkey-ai v2.3.4 976.9K downloads/30d#4,592 on PyPI118
Permissive license MIT License Active released

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-ai

uv

uv add portkey-ai

poetry

poetry add portkey-ai

Installing 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

Operating System :: OS IndependentProgramming Language :: Python :: 3

Tags

openai api gatewayllm failover and load balancingai observability and monitoringsemantic caching for llmsmulti-provider llm routing
llm-gatewayobservabilityapi-routing

More Artificial Intelligence packages