Home

Awesome

<p align="right"> <strong>English</strong> | <a href="./.github/README.cn.md">中文</a> | <a href="./.github/README.jp.md">日本語</a> </p> <div align="center">

AI Gateway

Route to 250+ LLMs with 1 fast & friendly API

<img src="https://cfassets.portkey.ai/sdk.gif" width="550px" alt="Portkey AI Gateway Demo showing LLM routing capabilities" style="margin-left:-35px">

Docs | Enterprise | Hosted Gateway | Changelog | API Reference

License Discord Twitter npm version Better Stack Badge

</div> <br/>

The AI Gateway is designed for fast, reliable & secure routing to 1600+ language, vision, audio, and image models. It is a lightweight, open-source, and enterprise-ready solution that allows you to integrate with any language model in under 2 minutes.

<br>

What can you do with the AI Gateway?

<br><br>

[!TIP] Starring this repo helps more developers discover the AI Gateway 🙏🏻

star-2

<br>

Quickstart (2 mins)

1. Setup your AI Gateway

# Run the gateway locally (needs Node.js and npm)
npx @portkey-ai/gateway

The Gateway is running on http://localhost:8787/v1

The Gateway Console is running on http://localhost:8787/public/

<sup> Deployment guides: &nbsp; <a href="https://portkey.wiki/gh-18"><img height="12" width="12" src="https://cfassets.portkey.ai/logo/dew-color.svg" /> Portkey Cloud (Recommended)</a> &nbsp; <a href="./docs/installation-deployments.md#docker"><img height="12" width="12" src="https://cdn.simpleicons.org/docker/3776AB" /> Docker</a> &nbsp; <a href="./docs/installation-deployments.md#nodejs-server"><img height="12" width="12" src="https://cdn.simpleicons.org/node.js/3776AB" /> Node.js</a> &nbsp; <a href="./docs/installation-deployments.md#cloudflare-workers"><img height="12" width="12" src="https://cdn.simpleicons.org/cloudflare/3776AB" /> Cloudflare</a> &nbsp; <a href="./docs/installation-deployments.md#replit"><img height="12" width="12" src="https://cdn.simpleicons.org/replit/3776AB" /> Replit</a> &nbsp; <a href="./docs/installation-deployments.md"> Others...</a> </sup>

2. Make your first request

<!-- <details open> <summary>Python Example</summary> -->
# pip install -qU portkey-ai

from portkey_ai import Portkey

# OpenAI compatible client
client = Portkey(
    provider="openai", # or 'anthropic', 'bedrock', 'groq', etc
    Authorization="sk-***" # the provider API key
)

# Make a request through your AI Gateway
client.chat.completions.create(
    messages=[{"role": "user", "content": "What's the weather like?"}],
    model="gpt-4o-mini"
)

<sup>Supported Libraries:   <img height="12" width="12" src="https://cdn.simpleicons.org/javascript/3776AB" /> JS   <img height="12" width="12" src="https://cdn.simpleicons.org/python/3776AB" /> Python   <img height="12" width="12" src="https://cdn.simpleicons.org/gnubash/3776AB" /> REST   <img height="12" width="12" src="https://cdn.simpleicons.org/openai/3776AB" /> OpenAI SDKs   <img height="12" width="12" src="https://cdn.simpleicons.org/langchain/3776AB" /> Langchain   LlamaIndex   Autogen   CrewAI   More.. </sup>

On the Gateway Console (http://localhost:8787/public/) you can see all of your local logs in one place.

<img src="https://github.com/user-attachments/assets/362bc916-0fc9-43f1-a39e-4bd71aac4a3a" width="400" />

3. Routing & Guardrails

Configs in the LLM gateway allow you to create routing rules, add reliability and setup guardrails.

config = {
  "retry": {"attempts": 5},

  "output_guardrails": [{
    "default.contains": {"operator": "none", "words": ["Apple"]},
    "deny": True
  }]
}

# Attach the config to the client
client = client.with_options(config=config)

client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Reply randomly with Apple or Bat"}]
)

# This would always response with "Bat" as the guardrail denies all replies containing "Apple". The retry config would retry 5 times before giving up.
<div align="center"> <img src="https://portkey.ai/blog/content/images/size/w1600/2024/11/image-15.png" width=600 title="Request flow through Portkey's AI gateway with retries and guardrails" alt="Request flow through Portkey's AI gateway with retries and guardrails"/> </div>

You can do a lot more stuff with configs in your AI gateway. Jump to examples →

<br/>

Enterprise Version (Private deployments)

<sup>

<img height="12" width="12" src="https://cfassets.portkey.ai/amazon-logo.svg" /> AWS   <img height="12" width="12" src="https://cfassets.portkey.ai/azure-logo.svg" /> Azure   <img height="12" width="12" src="https://cdn.simpleicons.org/googlecloud/3776AB" /> GCP   <img height="12" width="12" src="https://cdn.simpleicons.org/redhatopenshift/3776AB" /> OpenShift   <img height="12" width="12" src="https://cdn.simpleicons.org/kubernetes/3776AB" /> Kubernetes

</sup>

The LLM Gateway's enterprise version offers advanced capabilities for org management, governance, security and more out of the box. View Feature Comparison →

The enterprise deployment architecture for supported platforms is available here - Enterprise Private Cloud Deployments

<a href="https://portkey.sh/demo-13"><img src="https://portkey.ai/blog/content/images/2024/08/Get-API-Key--5-.png" height=50 alt="Book an enterprise AI gateway demo" /></a><br/>

<br> <hr>

AI Engineering Hours

Join weekly community calls every Friday (8 AM PT) to kickstart your AI Gateway implementation! Happening every Friday

<a href="https://portkey.wiki/gh-35"><img width="500" src="https://github.com/user-attachments/assets/c2885699-f197-4289-b819-21eb839fbae1" /></a>

Minutes of Meetings published here.

<hr>

Core Features

Reliable Routing

Security & Accuracy

Cost Management

Collaboration & Workflows

<sup> *&nbsp;Available in hosted and enterprise versions </sup> <br>

Cookbooks

☄️ Trending

🚨 Latest

View all cookbooks → <br/><br/>

Supported Providers

Explore Gateway integrations with 45+ providers and 8+ agent frameworks.

ProviderSupportStream
<img src="docs/images/openai.png" width=35 />OpenAI
<img src="docs/images/azure.png" width=35>Azure OpenAI
<img src="docs/images/anyscale.png" width=35>Anyscale
<img src="https://upload.wikimedia.org/wikipedia/commons/2/2d/Google-favicon-2015.png" width=35>Google Gemini
<img src="docs/images/anthropic.png" width=35>Anthropic
<img src="docs/images/cohere.png" width=35>Cohere
<img src="https://assets-global.website-files.com/64f6f2c0e3f4c5a91c1e823a/654693d569494912cfc0c0d4_favicon.svg" width=35>Together AI
<img src="https://www.perplexity.ai/favicon.svg" width=35>Perplexity
<img src="https://docs.mistral.ai/img/favicon.ico" width=35>Mistral
<img src="https://docs.nomic.ai/img/nomic-logo.png" width=35>Nomic
<img src="https://files.readme.io/d38a23e-small-studio-favicon.png" width=35>AI21
<img src="https://platform.stability.ai/small-logo-purple.svg" width=35>Stability AI
<img src="https://deepinfra.com/_next/static/media/logo.4a03fd3d.svg" width=35>DeepInfra
<img src="https://ollama.com/public/ollama.png" width=35>Ollama
<img src="https://novita.ai/favicon.ico" width=35>Novita AI

View the complete list of 200+ supported models here

<br>
<br>

Agents

Gateway seamlessly integrates with popular agent frameworks. Read the documentation here.

FrameworkCall 200+ LLMsAdvanced RoutingCachingLogging & Tracing*Observability*Prompt Management*
Autogen
CrewAI
LangChain
Phidata
Llama Index
Control Flow
Build Your Own Agents
<br>

*Available on the hosted app. For detailed documentation click here.

Gateway Enterprise Version

Make your AI app more <ins>reliable</ins> and <ins>forward compatible</ins>, while ensuring complete <ins>data security</ins> and <ins>privacy</ins>.

✅  Secure Key Management - for role-based access control and tracking <br> ✅  Simple & Semantic Caching - to serve repeat queries faster & save costs <br> ✅  Access Control & Inbound Rules - to control which IPs and Geos can connect to your deployments <br> ✅  PII Redaction - to automatically remove sensitive data from your requests to prevent indavertent exposure <br> ✅  SOC2, ISO, HIPAA, GDPR Compliances - for best security practices <br> ✅  Professional Support - along with feature prioritization <br>

Schedule a call to discuss enterprise deployments

<br>

Contributing

The easiest way to contribute is to pick an issue with the good first issue tag 💪. Read the contribution guidelines here.

Bug Report? File here | Feature Request? File here

Getting Started with the Community

Join our weekly AI Engineering Hours every Friday (8 AM PT) to:

Join the next session → | Meeting notes

<br>

Community

Join our growing community around the world, for help, ideas, and discussions on AI.

<!-- - Questions tagged #portkey on [Stack Overflow](https://stackoverflow.com/questions/tagged/portkey) -->

Rubeus Social Share (4)