← プロジェクト一覧に戻る

Portkey AI Gateway

あらゆるモデル提供元の手前に置く1つの窓口。再試行、切り替え、費用の抑制をエージェントの呼び出し量に耐える形で担う

MIT
スター
12.8k
フォーク
1.3k
オープンIssue
247
最終コミット
2026年5月25日

Portkey AI Gatewayとは

エージェントはチャットアプリよりはるかに多くモデルを呼ぶため、提供元のたまの流量制限が日常的な停止に変わります。Portkeyのゲートウェイは、自分のコードと提供元の間に入ってそれを吸収します。失敗した呼び出しは再試行し、制限に達した鍵は別の鍵に譲り、使えないモデルは次の候補に切り替わります。同じプロンプトはキャッシュから返せるため、二重に支払わずに済みます。振り分けの規則を書けば、分類には安いモデル、難しい処理には高いモデルというように送り先を変えられ、その判断がコード全体に散らばりません。遅延の増加は1ミリ秒未満、大きさは約122KBだとプロジェクトは述べています。機能を前提に設計する前に確認したい点が1つあります。資料はオープンなゲートウェイと同社のホスティング型製品をまとめて説明しています。

Portkey AI Gatewayで何ができますか?

  • コードを変えずに提供元を替える — OpenAI互換の窓口1つが非常に多くのモデルの手前に立つため、切り替えはクライアントの書き直しではなく設定の一行で済みます。
  • 提供元の調子が悪い時間帯を乗り切る — 自動の再試行、別モデルへの切り替え、複数の鍵への分散により、流量制限や障害の最中でも実行を続けられます。
  • 同じプロンプトに二重で払わない — 繰り返しの要求をキャッシュから返します。毎ターン同じ文脈を送り直すエージェントのループでは特に効きます。
  • 要求に見合ったモデルへ振り分ける — 条件付きの振り分けが要求の内容から送り先を決めるため、定型的な処理は安いモデル、それ以外は高いモデルという使い分けができます。
  • 入口と出口で規則に照らす — ガードレールが送信時と受信時に働くので、何を送ってよく何を返してよいかの方針を、各サービスではなく1か所で適用できます。
  • MCPサーバーも同じ扉の内側に置く — リモートのMCPサーバーへもゲートウェイ経由で接続でき、ツールの利用にモデル呼び出しと同じ認証と記録を適用できます。

Portkey AI Gatewayを選ぶ前に

  • 資料はオープンなゲートウェイとPortkeyのホスティング型製品を区別せずに説明しています。機能を前提に設計する前に、自分が動かす版に含まれるかを確認してください。
  • 開発元は、企業向けゲートウェイをオープン版に統合する2.0を先行公開中だと説明しています。つまり現時点では、オープン版と資料に書かれた製品はまだ同一ではありません。

よくある質問

Portkey AI Gatewayは商用利用できますか?

Portkey AI GatewayはMITライセンスで公開されています。OSI承認のオープンソースライセンスで、商用利用が認められています。

Portkey AI Gatewayはどの形で使えますか?

Portkey AI Gatewayはセルフホスト・ローカル実行・マネージドクラウドの形で利用できます。

ドキュメント

Portkey-AI/gateway のREADMEより転載(MIT)。 原文を読む ↗

[!IMPORTANT] :rocket: Gateway 2.0 (Pre-Release) Portkey’s core enterprise gateway is merging into open-source with our 2.0 release. You can try the pre-release branch here. Read more about what’s next for Portkey in our Series A announcement.

🆕 Portkey Models - Open-source LLM pricing for 2,300+ models across 40+ providers. Explore →

AI Gateway

Route to 250+ LLMs with 1 fast & friendly API

Docs | Enterprise | Hosted Gateway | Changelog | API Reference

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

MCP Gateway

MCP Gateway provides a centralized control plane for managing MCP (Model Context Protocol) servers across your organization.

  • Authentication — Single auth layer at the gateway. Users authenticate once; your MCP servers receive verified requests
  • Access Control — Control which teams and users can access which servers and tools. Revoke access instantly
  • Observability — Every tool call logged with full context: who called what, parameters, response, latency
  • Identity Forwarding — Forward user identity (email, team, roles) to MCP servers automatically

Works with Claude Desktop, Cursor, VS Code, and any MCP-compatible client. Get started →

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

Portkey Models

Open-source LLM pricing database for 40+ providers - used by the Gateway for cost tracking.

GitHub | Model Explorer

Cookbooks

🚨 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✅✅

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✅✅✅✅✅✅
IO Intelligence✅✅

*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

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)

Portkey AI Gateway
AIに聞く
GitHub