Note
本文档由 WeHub 基于上游 README 翻译整理,属于社区翻译,非官方中文文档。
English · 原始项目 · 上游 README
原作者、版权与许可证归属以原始项目及本仓库 LICENSE 文件为准。
Important
🚀 Gateway 2.0(预发布版)Portkey 的核心企业级网关将随 2.0 版本发布并入开源项目。你可以在此试用预发布分支 此处. 在我们的 A 轮融资公告. 中了解更多 Portkey 的未来规划
🆕 Portkey Models - 覆盖 40+ 提供商、2,300+ 模型的开源 LLM 定价。Explore →
AI Gateway 专为快速、可靠、安全地路由至 1600+ 语言、视觉、音频和图像模型而设计。这是一款轻量级、开源且企业就绪(enterprise-ready)的解决方案,可让你在 2 分钟内集成任意语言模型。
Tip
为本仓库加 Star 可帮助更多开发者发现 AI Gateway 🙏🏻
# Run the gateway locally (needs Node.js and npm)
npx @portkey-ai/gateway
部署指南:Gateway 运行在
http://localhost:8787/v1Gateway 控制台运行在
http://localhost:8787/public/
# 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"
)
支持的库:
JS
Python
REST
OpenAI SDKs
Langchain
LlamaIndex
Autogen
CrewAI
More..
在 Gateway 控制台(http://localhost:8787/public/)中,你可以在一处查看所有本地日志。
LLM 网关中的 Configs 允许你创建路由规则、增强可靠性并配置防护栏。
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.
你还可以在 AI Gateway 中通过配置实现更多功能。跳转到示例 →
AWS
Azure
GCP
OpenShift
Kubernetes
LLM Gateway 的企业版 提供面向组织管理、治理、安全及更多能力 的开箱即用高级功能。查看功能对比 →
各支持平台的企业部署架构可在此查看 — 企业私有云部署
MCP Gateway 为你的组织提供集中式控制平面,用于管理 MCP(Model Context Protocol,模型上下文协议)服务器。
可与 Claude Desktop、Cursor、VS Code 及任何兼容 MCP 的客户端配合使用。立即开始 →
面向 40+ 供应商的开源 LLM 定价数据库 — 供 Gateway 用于成本追踪。
探索 Gateway 与 45+ 供应商 及 8+ Agent 框架. 的集成
| Provider | Support | Stream | |
|---|---|---|---|
| OpenAI | ✅ | ✅ | |
| Azure OpenAI | ✅ | ✅ | |
| Anyscale | ✅ | ✅ | |
| Google Gemini | ✅ | ✅ | |
| Anthropic | ✅ | ✅ | |
| Cohere | ✅ | ✅ | |
| Together AI | ✅ | ✅ | |
| Perplexity | ✅ | ✅ | |
| Mistral | ✅ | ✅ | |
| Nomic | ✅ | ✅ | |
| AI21 | ✅ | ✅ | |
| Stability AI | ✅ | ✅ | |
| DeepInfra | ✅ | ✅ | |
| Ollama | ✅ | ✅ | |
| Novita AI | ✅ | ✅ |
Gateway 可与主流智能体框架无缝集成。在此阅读文档.
| 框架 | 调用 200+ 款 LLM | 高级路由(Advanced Routing) | 缓存(Caching) | 日志与追踪*(Logging & Tracing) | 可观测性*(Observability) | 提示词管理*(Prompt Management) |
|---|---|---|---|---|---|---|
| Autogen | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| CrewAI | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| LangChain | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Phidata | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Llama Index | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Control Flow | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Build Your Own Agents | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| IO Intelligence | ✅ | ✅ |
让你的 AI 应用更可靠、更具前向兼容性,同时确保完全的数据安全与隐私保护。
✅ 安全密钥管理(Secure Key Management)—— 用于基于角色的访问控制与追踪
✅ 简单与语义缓存(Simple & Semantic Caching)—— 更快响应重复查询并节省成本
✅ 访问控制与入站规则(Access Control & Inbound Rules)—— 控制哪些 IP 与地理区域可连接到你的部署
✅ PII 脱敏(PII Redaction)—— 自动从请求中移除敏感数据,防止无意泄露
✅ SOC2、ISO、HIPAA、GDPR 合规 —— 遵循最佳安全实践
✅ 专业支持 —— 并提供功能优先级排序
最简单的贡献方式是挑选带有 good first issue 标签的 issue 💪。贡献指南请见此处。
每周五(太平洋时间上午 8 点)参加我们的 AI Engineering Hours,你可以:
加入我们在全球不断壮大的社区,获取 AI 相关帮助、灵感与讨论。