1.9.19 β€’ Published 5 months ago

@portkey-ai/gateway v1.9.19

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

AI Gateway

Route to 250+ LLMs with 1 fast & friendly API

Docs | Enterprise | Hosted Gateway | Changelog | API Reference

License Discord Twitter npm version Better Stack Badge

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.

  • Blazing fast (<1ms latency) with a tiny footprint (122kb)
  • Battle tested, with over 10B tokens processed everyday
  • Enterprise-ready with enhanced security, scale, and custom deployments

What can you do with the AI Gateway?

!TIP Starring this repo helps more developers discover the AI Gateway πŸ™πŸ»

star-2

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/

2. Make your first request

# 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"
)

Supported Libraries: Β  JS Β  Python Β  REST Β  OpenAI SDKs Β  Langchain Β  LlamaIndex Β  Autogen Β  CrewAI Β  More..

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

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.

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

Enterprise Version (Private deployments)

AWS Β  Azure Β  GCP Β  OpenShift Β  Kubernetes

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

AI Engineering Hours

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

Minutes of Meetings published here.

LLMs in Prod'25

Insights from analyzing 2 trillion+ tokens, across 90+ regions and 650+ teams in production. What to expect from this report:

  • Trends shaping AI adoption and LLM provider growth.
  • Benchmarks to optimize speed, cost and reliability.
  • Strategies to scale production-grade AI systems.

Get the Report

Core Features

Reliable Routing

  • Fallbacks: Fallback to another provider or model on failed requests using the LLM gateway. You can specify the errors on which to trigger the fallback. Improves reliability of your application.
  • Automatic Retries: Automatically retry failed requests up to 5 times. An exponential backoff strategy spaces out retry attempts to prevent network overload.
  • Load Balancing: Distribute LLM requests across multiple API keys or AI providers with weights to ensure high availability and optimal performance.
  • Request Timeouts: Manage unruly LLMs & latencies by setting up granular request timeouts, allowing automatic termination of requests that exceed a specified duration.
  • Multi-modal LLM Gateway: Call vision, audio (text-to-speech & speech-to-text), and image generation models from multiple providers β€” all using the familiar OpenAI signature
  • Realtime APIs: Call realtime APIs launched by OpenAI through the integrate websockets server.

Security & Accuracy

  • Guardrails: Verify your LLM inputs and outputs to adhere to your specified checks. Choose from the 40+ pre-built guardrails to ensure compliance with security and accuracy standards. You can bring your own guardrails or choose from our many partners.
  • Secure Key Management: Use your own keys or generate virtual keys on the fly.
  • Role-based access control: Granular access control for your users, workspaces and API keys.
  • Compliance & Data Privacy: The AI gateway is SOC2, HIPAA, GDPR, and CCPA compliant.

Cost Management

  • Smart caching: Cache responses from LLMs to reduce costs and improve latency. Supports simple and semantic* caching.
  • Usage analytics: Monitor and analyze your AI and LLM usage, including request volume, latency, costs and error rates.
  • Provider optimization*: Automatically switch to the most cost-effective provider based on usage patterns and pricing models.

Collaboration & Workflows

Cookbooks

β˜„οΈ Trending

🚨 Latest

View all cookbooks β†’

Supported Providers

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

ProviderSupportStream
OpenAIβœ…βœ…
Azure OpenAIβœ…βœ…
Anyscaleβœ…βœ…
Google Geminiβœ…βœ…
Anthropicβœ…βœ…
Cohereβœ…βœ…
Together AIβœ…βœ…
Perplexityβœ…βœ…
Mistralβœ…βœ…
Nomicβœ…βœ…
AI21βœ…βœ…
Stability AIβœ…βœ…
DeepInfraβœ…βœ…
Ollamaβœ…βœ…
Novita AIβœ…βœ…/chat/completions, /completions

View the complete list of 200+ supported models here

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βœ…βœ…βœ…βœ…βœ…βœ…

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

Gateway Enterprise Version

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

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

Schedule a call to discuss enterprise deployments

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:

  • Meet other contributors and community members
  • Learn advanced Gateway features and implementation patterns
  • Share your experiences and get help
  • Stay updated with the latest development priorities

Join the next session β†’ | Meeting notes

Community

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

Rubeus Social Share (4)

1.8.7-alpha.2

10 months ago

1.8.7-alpha.1

10 months ago

1.8.2

11 months ago

1.8.1

11 months ago

1.9.19

5 months ago

1.9.18

6 months ago

1.9.17

6 months ago

1.9.16

6 months ago

1.9.15

6 months ago

1.9.14

7 months ago

1.9.13

7 months ago

1.9.12

7 months ago

1.9.11

7 months ago

1.9.10

8 months ago

1.9.9

8 months ago

1.9.8

8 months ago

1.9.7

8 months ago

1.9.6

9 months ago

1.9.5

9 months ago

1.9.4

9 months ago

1.9.3

9 months ago

1.9.2

9 months ago

1.9.1

9 months ago

1.9.0

9 months ago

1.8.7

10 months ago

1.8.6

10 months ago

1.8.5

10 months ago

1.8.4

10 months ago

1.8.3

10 months ago

1.8.0

1 year ago

1.7.7

1 year ago

1.7.6

1 year ago

1.7.5

1 year ago

1.7.4

1 year ago

1.7.3

1 year ago

1.7.2

1 year ago

1.7.1

1 year ago

1.5.5

1 year ago

1.5.4

1 year ago

1.5.3

1 year ago

1.7.0

1 year ago

1.5.2

1 year ago

1.6.0

1 year ago

1.5.1

1 year ago

1.5.0

1 year ago

1.4.1

1 year ago

1.4.0

1 year ago

1.5.7

1 year ago

1.5.6

1 year ago

1.3.2

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago

1.2.0

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago