Home

Awesome

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

AI Gateway

Reliably route to 200+ LLMs with 1 fast & friendly API

<img src="docs/images/demo.gif" width="650" alt="Gateway Demo"><br>

License Discord Twitter npm version Better Stack Badge

</div>

The AI Gateway streamlines requests to 250+ language, vision, audio and image models with a unified API. It is production-ready with support for caching, fallbacks, retries, timeouts, loadbalancing, and can be edge-deployed for minimum latency.

✅  Blazing fast (9.9x faster) with a tiny footprint (~100kb build) <br> ✅  Load balance across multiple models, providers, and keys <br> ✅  Fallbacks make sure your app stays resilient <br> ✅  Automatic Retries with exponential fallbacks come by default <br> ✅  Configurable Request Timeouts to easily handle unresponsive LLM requests <br> ✅  Multimodal to support routing between Vision, TTS, STT, Image Gen, and more models <br> ✅  Plug-in middleware as needed <br> ✅  Battle tested over 480B tokens <br> ✅  Enterprise-ready for enhanced security, scale, and custom deployments <br><br>

[!TIP] ⭐️ Star this repo to get Github release notifications for new provider integrations and features.

star-2

<details> <summary><kbd>Star History</kbd></summary> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=portkey-ai%2Fgateway&theme=dark&type=Date"> <img width="100%" src="https://api.star-history.com/svg?repos=portkey-ai%2Fgateway&type=Date"> </picture> </details> <br>

Setup & Installation

Use the AI gateway through the hosted API or self-host the open-source or enterprise versions on your environment. <br>

👉 Hosted Gateway on portkey.ai (Fastest)

The hosted API is the fastest way to setup an AI Gateway for your Gen AI application. We process billions of tokens daily and is in production with companies like Postman, Haptik, Turing, MultiOn, SiteGPT, and more.

<a href="https://app.portkey.ai/signup"><img src="https://portkey.ai/blog/content/images/2024/08/Get-API-Key--3-.png" height=50 alt="Get API Key" /></a><br> <br>

👉 Self-hosting the OSS version (MIT License)

To run the AI gateway locally, execute the following command in your terminal. (Needs npx installed) Or, explore deployment guides for Cloudflare, Docker, Node.js and more here.

npx @portkey-ai/gateway

<sup>Your AI Gateway is now running on http://localhost:8787 🚀</sup> <br>

👉 Self-hosting the Enterprise Version

The AI Gateway's enterprise version offers enterprise-ready capabilities for org management, governance, security and more out of the box. Compare the open source, hosted and enterprise versions here.

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

<a href="https://portkey.sh/demo-22"><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>

Making requests through the AI gateway

<img src="docs/images/openai.png" height=15 /> Compatible with OpenAI API & SDKs

The AI Gateway is compatible with the OpenAI API & SDKs, and extends them to call 200+ LLMs reliably. To use the Gateway through OpenAI, update the client to include the gateway's URL and headers and make requests as usual. The AI gateway can translate requests written in the OpenAI format to the signature expected by the specified provider. View examples <br><br>

<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/c/c3/Python-logo-notext.svg/1869px-Python-logo-notext.svg.png" height=15 /> Using the Python SDK   <a href="https://colab.research.google.com/drive/1hLvoq_VdGlJ_92sPPiwTznSra5Py0FuW?usp=sharing"><img src="https://colab.research.google.com/assets/colab-badge.svg"></a>

Portkey Python SDK is a wrapper over the OpenAI Python SDK with added support for additional parameters across all other providers. If you're building with Python, this is the recommended library to connect to the Gateway.

pip install -qU portkey-ai
<br>

<img src="https://cdn-icons-png.flaticon.com/512/5968/5968322.png" height=15 /> Using the Node.JS SDK

Portkey JS/TS SDK is a wrapper over the OpenAI JS SDK with added support for additional parameters across all other providers. If you're building with JS or TS, this is the recommended library to connect to the Gateway.

npm install --save portkey-ai
<br>

<img src="https://www.svgrepo.com/show/305922/curl.svg" height=15 /> Using the REST APIs

The AI gateway supports OpenAI compatible endpoints with added parameter support for all other providers and models. View API Reference. <br><br>

Other Integrations

LanguageSupported SDKs
JS / TSLangchainJS <br> LlamaIndex.TS
Python<br> Langchain <br> LlamaIndex
Gogo-openai
Javaopenai-java
Rustasync-openai
Rubyruby-openai
<br>

Gateway Cookbooks

Trending Cookbooks

Latest Cookbooks

More Examples

Supported Providers

Explore Gateway integrations with 25+ providers and 6+ 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 & Palm
<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>

*Only available on the hosted app. For detailed documentation click here.

Features

<table width=100%> <tr> <td width="50%"> <strong><a href="https://portkey.ai/docs/product/ai-gateway-streamline-llm-integrations/fallbacks">Fallbacks</a></strong><br/> Fallback to another provider or model on failed requests. You can specify the errors on which to trigger the fallback. Improves reliability of your application <br><br> <img src="https://framerusercontent.com/images/gmlOW8yeKP2pGuIsObM6gKLzeMI.png" height=100 /> </td> <td width="50%"> <strong><a href="https://portkey.ai/docs/product/ai-gateway-streamline-llm-integrations/automatic-retries">Automatic Retries</a></strong><br/> Automatically retry failed requests up to 5 times. An exponential backoff strategy spaces out retry attempts to prevent network overload. <br><br> <img src="https://github.com/roh26it/Rubeus/assets/971978/8a6e653c-94b2-4ba7-95c7-93544ee476b1" height=100 /> </td> </tr> </table> <table width="100%"> <tr> <td width="50%"> <strong><a href="https://portkey.ai/docs/product/ai-gateway-streamline-llm-integrations/load-balancing">Load Balancing</a></strong><br/> Distribute LLM requests across multiple API keys or AI providers with weights to ensure high availability and optimal performance. <br><br> <img src="https://framerusercontent.com/images/6EWuq3FWhqrPe3kKLqVspevi4.png" height=100 /> </td> <td width="50%"> <strong><a href="https://portkey.ai/docs/product/ai-gateway-streamline-llm-integrations/request-timeouts">Request Timeouts</a></strong></br><br/> Manage unruly LLMs & latencies by setting up granular request timeouts, allowing automatic termination of requests that exceed a specified duration. <br><br> <img src="https://github.com/vrushankportkey/gateway/assets/134934501/b23b98b2-6451-4747-8898-6847ad8baed4" height=100 /> </td> </tr> </table> </table> <table width="100%"> <tr> <td width="50%"> <strong><a href="https://docs.portkey.ai/docs/product/ai-gateway-streamline-llm-integrations/multimodal-capabilities">Multi-modal LLM Gateway</a></strong><br/> Call vision, audio (text-to-speech & speech-to-text), and image generation models from multiple providers — all using the familiar OpenAI signature <br><br> <img src="https://docs.portkey.ai/~gitbook/image?url=https%3A%2F%2F2878743244-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252Fy3MCfQqftZOnHqSmVV5x%252Fuploads%252FOVuOxN4uFdBp1BdXX4E6%252Fmultimodal-icon.png%3Falt%3Dmedia%26token%3Db8b7bd49-0194-4d2f-89d4-c6633a872372&width=768&dpr=2&quality=100&sign=f51129a9&sv=1" height=100 /> </td> <td width="50%"> <strong><a href="https://docs.portkey.ai/docs/product/guardrails">Guardrails</a></strong></br><br/> Verify your LLM inputs AND outputs to adhere to your specified checks. Build your own checks or choose from the 20+ pre-built guardrails. <br><br> <img src="https://docs.portkey.ai/~gitbook/image?url=https%3A%2F%2F2878743244-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252Fy3MCfQqftZOnHqSmVV5x%252Fuploads%252FDFkhZpqtBfQMIW9BhVum%252Fguardrails-icon.png%3Falt%3Dmedia%26token%3D91cfe226-5ce9-44b3-a0e8-be9f3ae3917f&width=768&dpr=2&quality=100&sign=73608afc&sv=1" height=100 /> </td> </tr> </table>

These features are configured through the Gateway Config added to the x-portkey-config header or the config parameter in the SDKs.

Here's a sample config JSON showcasing the above features. All the features are optional

{
	"retry": { "attempts": 5 },
	"request_timeout": 10000,
	"strategy": { "mode": "fallback" }, // or 'loadbalance', etc
	"targets": [{
		"provider": "openai",
		"api_key": "sk-***"
	},{
		"strategy": {"mode": "loadbalance"}, // Optional nesting
		"targets": {...}
	}]
}

Then use the config in your API requests to the gateway.

Using Gateway Configs

Here's a guide to use the config object in your request.

<br>

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

<br>

Community

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

<!-- - Visit us on [YouTube](https://www.youtube.com/channel/UCZph50gLNXAh1DpmeX8sBdw) --> <!-- - Join our [Dev community](https://dev.to/portkeyai) --> <!-- - Questions tagged #portkey on [Stack Overflow](https://stackoverflow.com/questions/tagged/portkey) -->

Rubeus Social Share (4)