Portkey AI Gateway Config
Configure your Portkey AI gateway with multiple LLM providers, routing strategy (fallback or load balance), retry logic, and response caching. Generate a production-ready config JSON with Python usage example.
Frequently Asked Questions
What is Portkey AI gateway?▼
Portkey is an AI gateway that sits between your application and LLM providers. It provides a unified API (compatible with OpenAI's SDK), automatic fallbacks, load balancing, request caching, observability, and cost tracking. Virtual keys let you manage multiple provider API keys centrally without exposing them in your code.
What's the difference between Fallback and Load Balance strategies?▼
Fallback tries providers in order — it only moves to the next provider if the current one fails (based on status codes like 429 or 503). Load Balance distributes requests across providers based on weights — useful for cost optimization (e.g. 70% cheap model, 30% expensive model). Use Fallback for reliability, Load Balance for cost optimization.
What are virtual keys?▼
Virtual keys are Portkey's abstraction over real provider API keys. You add your actual OpenAI/Anthropic keys to Portkey's vault, and Portkey gives you a virtual key (starting with portkey-vk-...). You use virtual keys in your config instead of real keys, so you can rotate/revoke real keys without changing your application code.
Does Portkey work with the OpenAI Python SDK?▼
Yes. Portkey is designed as a drop-in replacement. Just change `client = OpenAI(api_key=...)` to `client = Portkey(api_key=..., virtual_key=...)`. The rest of your code stays identical. The same works for Node.js with the OpenAI Node SDK.
When should I use semantic caching vs simple caching?▼
Simple caching does exact string matching — the same prompt returns the same cached response instantly. Semantic caching uses vector embeddings to match 'similar' prompts, so 'What's 2+2?' and 'What is 2 plus 2?' return the same cached result. Simple caching is great for API wrappers with predictable prompts. Semantic caching works well for chatbots and QA systems with paraphrased queries.
Related Products
on GumroadAI Prompt Engineering Toolkit
58 structured prompt templates for Claude, ChatGPT, and Gemini — organized by use case. Code Review, Debugging, Documentation, Architecture, and 10 model-specific tips. Stop writing prompts from scratch.
Buy on Gumroad →DevToolkit Starter Kit
A ready-to-deploy developer tools website with 12 built-in tools. Astro + Preact + Tailwind. Deploy to Cloudflare Pages for free. Built-in SEO, dark mode, and ad-ready layout.
Buy on Gumroad →AI Developer Prompts Pack
55 battle-tested prompt templates for the workflows developers actually use: code review, debugging, architecture, documentation, and testing. Stop writing prompts from scratch.
Buy on Gumroad →You Might Also Need
AI Hallucination Detector
Scan LLM-generated text for hallucination risk signals: fabricated citations, overconfident claims, suspect statistics, and verification gaps. Risk score 0-100 with highlighted problem spans.
Open free tool →
AI Safety Checklist Generator
Generate a customized AI safety evaluation checklist for your deployment. Covers technical safety, content moderation, security, bias, privacy, and regulatory compliance. Export to Markdown.
Open free tool →
CrewAI Agent Config Generator
Build CrewAI agent configurations visually. Define roles, goals, backstories, and tools. Generate YAML or Python code for multi-agent crews.
Open free tool →
More Free Tools
Related Articles
LiteLLM vs Portkey vs OpenRouter: Choosing Your AI Gateway in 2026
Complete comparison of AI gateway solutions in 2026. Compare LiteLLM, Portkey, and OpenRouter for multi-provider routing, fallbacks, cost tracking, observability, and production reliability. Includes setup examples and decision guide.
AI Coding Agents Compared 2026: Devin vs SWE-agent vs OpenHands vs Aider vs Claude Code
Comprehensive comparison of autonomous AI coding agents in 2026. Benchmark scores, real-world performance, pricing, and when to use Devin, SWE-agent, OpenHands, Aider, or Claude Code.
LLM Structured Output: JSON Mode, Function Calling, and Tool Use in 2026
Complete guide to LLM structured output in 2026: OpenAI JSON mode vs structured outputs, Anthropic tool use, the Instructor library, Pydantic AI, validation patterns, reliability techniques, and real-world examples.
Vercel AI SDK Complete Guide 2026: Streaming, Tool Calls & Multi-Provider
The complete guide to the Vercel AI SDK in 2026. Learn streaming text and objects, tool calling, multi-provider setup, Next.js integration, and production patterns for building LLM-powered apps.
LiteLLM vs OpenRouter vs AI Suite: LLM Gateway & Model Routing in 2026
A comprehensive comparison of LiteLLM, OpenRouter, and AI Suite for LLM gateway and model routing in 2026 — unified API, model fallback, cost routing, rate limiting, caching, and deployment options with Python code examples.
Enjoying this tool? Get more like it.
Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.
Unlock AI-Powered Dev Tools
- ⚡ AI Code Review, Doc Generator & SQL Builder
- ⚡ All premium templates & early access
- ⚡ Member discounts on Gumroad products
$9/mo after trial · Cancel anytime
Want the full toolkit?
Get DevPlaybook Pro
Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.
MIT licensed · Instant download · No subscription
See what's included → Browse all deals →