Skip to main content

Python client library for the Portkey API

Project description


Build reliable, secure, and production-ready AI apps easily.

pip install portkey-ai

💡 Features

🚪 AI Gateway:

  • Unified API Signature: If you've used OpenAI, you already know how to use Portkey with any other provider.
  • Interoperability: Write once, run with any provider. Switch between any model from any provider seamlessly.
  • Automated Fallbacks & Retries: Ensure your application remains functional even if a primary service fails.
  • Load Balancing: Efficiently distribute incoming requests among multiple models.
  • Semantic Caching: Reduce costs and latency by intelligently caching results.

🔬 Observability:

  • Logging: Keep track of all requests for monitoring and debugging.
  • Requests Tracing: Understand the journey of each request for optimization.
  • Custom Tags: Segment and categorize requests for better insights.

🚀 Quick Start

First, install the SDK & export Portkey API Key

Get Portkey API key here.

$ pip install portkey-ai
$ export PORTKEY_API_KEY=PORTKEY_API_KEY

Now, let's make a request with GPT-4

from portkey_ai import Portkey

# Construct a client with a virtual key
portkey = Portkey(
    api_key="PORTKEY_API_KEY",
    virtual_key="VIRTUAL_KEY"
)

completion = portkey.chat.completions.create(
    messages = [{ "role": 'user', "content": 'Say this is a test' }],
    model = 'gpt-3.5-turbo'
)
print(completion)

Portkey fully adheres to the OpenAI SDK signature. This means that you can instantly switch to Portkey and start using Portkey's advanced production features right out of the box.

🤝 Supported Providers

Provider Support Status Supported Endpoints
OpenAI ✅ Supported /completion, /embed
Azure OpenAI ✅ Supported /completion, /embed
Anthropic ✅ Supported /complete
Anyscale ✅ Supported /chat/completions
Cohere 🚧 Coming Soon generate, embed

📝 Full Documentation | 🛠️ Integration Requests |

follow on Twitter Discord

🛠️ Contributing

Get started by checking out Github issues. Feel free to open an issue, or reach out if you would like to add to the project!

Project details


Release history Release notifications | RSS feed

This version

1.1.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

portkey_ai-1.1.1-py3-none-any.whl (34.9 kB view details)

Uploaded Python 3

File details

Details for the file portkey_ai-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: portkey_ai-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 34.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for portkey_ai-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8a1bd5cc48c2a874058afba16b1ed993d80f9838de95c4f7ab5789153816d197
MD5 e8fa361d3d0633ae407c5214b11a05f5
BLAKE2b-256 efe52d273c81a619c71bd498243898c70befe6be718545201008164b7913adfc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page