DEV Community

Rohit Agarwal for Portkey

Posted on

We open sourced our AI gateway written in TS

We've been building a robust AI gateway at Portkey for the past 10 months.

Over this time, Portkey has been used by developers to test their prompts and measure costs and performance. We have been interface for shuttling 100B tokens and 10M requests daily to 100+ LLMs.

We've believed that to accelerate Gen AI adoption, companies and AI engineers need strong foundational platforms so going to production is not a nervous affair. The AI gateway in our mind is one of the MOST critical pieces of infrastructure in the new AI stack.

Guess what? Today, we are officially open-sourcing the magic sauce, that got us here.

Portkey's Opensource AI Gateway

GitHub logo Portkey-AI / gateway

A Blazing Fast AI Gateway. Route to 100+ LLMs with 1 fast & friendly API.

AI Gateway

Route to 100+ LLMs with 1 fast & friendly API.

License Discord Twitter npm version



Portkey's AI Gateway is the interface between your app and hosted LLMs. It streamlines API requests to OpenAI, Anthropic, Mistral, LLama2, Anyscale, Google Gemini and more with a unified API.

✅  Blazing fast (9.9x faster) with a tiny footprint (~45kb installed)
✅  Load balance across multiple models, providers, and keys
✅  Fallbacks make sure your app stays resilient
✅  Automatic Retries with exponential fallbacks come by default
✅  Plug-in middleware as needed
✅  Battle tested over 100B tokens

Getting Started

Installation

If you're familiar with Node.js and npx, you can run your private AI gateway locally. (Other deployment options)

npx @portkey-ai/gateway
Enter fullscreen mode Exit fullscreen mode

Your AI Gateway is now running on http://localhost:8787 🚀


Usage

Let's try making a chat completions call to OpenAI through the AI gateway:

curl '127.0.0.1:8787/v1/chat/completions' \
  -H 'x-portkey-provider: openai' \
Enter fullscreen mode Exit fullscreen mode

The AI gateway is an essential component of Portkey's platform. Portkey's AI Gateway helps you route requests to multiple LLMs and enables you to build on a unified API.

Portkey AI Gateway

Why an AI Gateway?

The Generative AI ecosystem has been expanding rapidly (for good!), leading to a lack of resiliency and a disjointed developer experience when building with different components.

Imagine that you have added a Generative AI feature to your SaaS app, which your users use widely. However, there is a new model available from the Large Language model provider that you want to test before implementing it in production.

Although you are satisfied with the success of your current AI feature, you still lack insights into the costs and errors from your users.

To address these issues, Portkey's AI Gateway is specifically designed to assist developers.

Key Features

Universal API

AI Gateway offers a universal and unified API that allows interaction with over 100 LLMs, whether privately deployed or public LLM vendors. We take care of request and response transformations automatically.

Load Balancing

Portkey's Load Balancing feature efficiently distributes network traffic across multiple Language Model APIs, preventing any LLM from becoming a performance bottleneck and ensuring high availability and optimal performance of your generative AI apps.

Fallbacks

Several Language Model APIs are available in the market, each with its strengths and specialities. It would be very convenient if the APIs could be easily switched between based on their performance or availability. Portkey's Fallback feature enables one to switch between multiple LLMs.

Just imagine your users are not affected by your LLM Vendor's downtime.

Getting Started

The gateway is built in TypeScript and blazingly fast to try out or deploy.

npx @portkey-ai/gateway
Enter fullscreen mode Exit fullscreen mode

Building with AI Gateway

While we understand the promise of universal API, we also acknowledge the learning curve of a new API.

Most of our SDKs support OpenAI convention and work with Llamaindex and LangChain.

Portkey's LLM Developer Community

Open-sourcing the gateway can lead to more community involvement and innovation, making it even more useful for developers building AI-enabled experiences.

Please join us with hundreds of developers at our discord to discuss building and contributing with AI.

We believe that Open-sourcing the gateway can lead to more community involvement and innovation, making it even more useful for developers building AI-enabled experiences.

Please consider giving Portkey's AI Gateway a star 🌟. We welcome code and non-code contributions from you - here are some good-first-issues to start.

If you have any questions, feedback. Please let us know in the comments below!

Top comments (1)

Collapse
 
ranjancse profile image
Ranjan Dailata

Congrats. This is awesome.

Please have some plans on building the official C# SDK.