Skip to main content

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.

✓ Fallback & load balance ✓ 8 LLM providers ✓ Python code 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.

Share this tool: X / Twitter LinkedIn
✓ 60,000+ developers use DevPlaybook ★★★★★ 4.8 / 5 on Gumroad ✓ MIT licensed · Instant download ✓ No login required

Related Products

on Gumroad

You Might Also Need

More Free Tools

AI Hallucination Detector AI Safety Checklist Generator CrewAI Agent Config Generator AI Model Comparator AI Model Comparison Tool Jotai Atom Explorer LLM Cost Calculator CSS Container Query Builder LLM Context Window Calculator AI Prompt Cost Calculator LLM JSON Schema Builder AI Agent Run Cost Tracker AI Pipeline DAG Builder LLM Benchmark Calculator Prompt Injection Tester LangChain PromptTemplate Builder AI Token Cost Calculator MySQL Query Explainer PostgreSQL EXPLAIN Analyzer AI Model Benchmark Comparator Cron Expression Explainer Font Pairing Preview LLM Prompt Cost Calculator AI Model Context Window Visualizer OpenAI Prompt Tester AI Rate Limit Calculator LLM System Prompt Analyzer Vibe Coding Prompt Optimizer AI IDE Comparator LLM Prompt Caching Calculator Token Counter & Cost Estimator AI Model Comparison Table RAG Chunk Size Optimizer LLM Prompt Template Builder AI Commit Message Generator AI Doc Generator — Pro Tool AI Regex Explainer — Pro Tool AI System Guardian Docker Compose Generator Mermaid Diagram Generator Elasticsearch Query Tester mTLS Certificate Chain Builder Prompt Token Estimator JS Prototype Chain Visualizer OpenAI Token Counter System Prompt Builder AI Agent Memory Planner Token Context Calculator Multi-Agent Orchestration Planner AI Prompt Token Estimator OpenAI Function Calling Generator AI Context Window Visualizer Embedding Storage Calculator AI API Rate Limit Calculator HTTP Headers Analyzer AI Code Review — Pro Tool AI Error Explainer — Pro Tool AI SQL Builder — Pro Tool AI Unit Test Generator — Pro Tool Color Palette Generator JWT Decoder Prompt Template Builder Regex Tester RSA Key Pair Generator Dockerfile Generator SMTP Server Tester Biome Config Generator Terraform Variable Validator Haproxy Config Validator SBOM Generator AI Variable Namer AI PR Description Generator AI JSDoc Generator K8s Resource Limits Calculator CI/CD Pipeline Generator Regex Flags Explainer LLM Token Counter OAuth2 Flow Visualizer Playwright E2E Testing Guide Core Web Vitals Calculator RAG Chunking Calculator Solana Program ID Generator Multi-Chain Wallet Address Validator Kubernetes Resource Calculator RAG Chunking Calculator TypeScript Discriminated Union Builder Core Web Vitals Budget Calculator JWT Decoder & Validator Blockchain Transaction Fee Calculator Database Query Cost Analyzer

Related Articles

Apr 1, 2026 · 14 min read

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.

Mar 28, 2026 · 12 min read

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.

Mar 28, 2026 · 14 min read

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.

Mar 28, 2026 · 20 min read

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.

Mar 27, 2026 · 16 min read

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.

DevPlaybook Pro 7 days free

Unlock AI-Powered Dev Tools

  • ⚡ AI Code Review, Doc Generator & SQL Builder
  • ⚡ All premium templates & early access
  • ⚡ Member discounts on Gumroad products
Start Free Trial →

$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.

$79
$241 separately Save $162 (67% off)
Get DevPlaybook Pro — $79 →

MIT licensed · Instant download · No subscription

See what's included → Browse all deals →