openrouter

OpenRouter unified AI API - Access 200+ LLMs through single interface with intelligent routing, streaming, cost optimization, and model fallbacks

By bobmatnyc · 363 installs

npx skills add bobmatnyc/claude-mpm-skills --skill openrouter

Source repository · Upstream listing

OpenRouter Unified AI API Gateway Overview OpenRouter provides a single API to access 200+ language models from OpenAI, Anthropic, Google, Meta, Mistral, and more. It offers intelligent routing, streaming, cost optimization, and standardized OpenAI compatible interface. Key Features : Access 200+ models through one API OpenAI compatible interface (drop in replacement) Intelligent model routing and fallbacks Real time streaming responses Cost tracking and optimization Model performance analytics Function calling support Vision model support Pricing Model : Pay per token (no subscriptions) Volume discounts available Free tier with credits Per model pricing varies Installation : Quick Start 1. Get API Key 2. Basic Chat Completion 3. Streaming Response Model Selection Strategy Available Model Categories Flagship Models (Highest Quality): Fast Models (Low Latency): Cost Optimized Models : Specialized Models : Model Selection Logic Streaming Implementation TypeScript Streaming with Error Handling Python Streaming React Streaming Component Function Calling Basic Function Calling Multi Step Function Calling Cost Optimization Token Counting and Cost Estimation Dynamic Model Selection by Budget Batching for Cost Reduction Model Fallback and Retry Strategy Automatic Fallback Exponential Backoff for Rate Limits Prompt Engineering Best Practices System Prompts for Consistency Few Shot Prompting Chain of Thought Prompting Rate Limits and Throttling Rate Limit Handler Vision Models Image Understanding Multi Image Analysis Error Handling and Monitoring Comprehensive Error Handler Request/Response Logging Best Practices 1. Model Selection : Use fast models (Haiku, Flash) for simple tasks Use flagship models (Sonnet, GPT 4) for complex reasoning Consider context size requirements Test multiple models for your use case 2. Cost Optimization : Estimate costs before requests Use cheaper models when possible Implement token limits Cache common responses Batch similar requests 3. Streaming : Always use streaming for user facing apps Handle connection interruptions Show progress indicators Buffer partial responses 4. Error Handling : Implement retry logic with exponential backoff Use model fallbacks for reliability Log all errors for debugging Handle rate limits gracefully 5. Prompt Engineering : Use system prompts for consistency Implement few shot learning for specific tasks Use chain of thought for complex reasoning Keep prompts concise to reduce costs 6. Rate Limiting : Respect API rate limits Implement request queuing Use exponential backoff Monitor usage metrics 7. Security : Never expose API keys in client code Use environment variables Implement server side proxies Validate user inputs 8. Monitoring : Track token usage Monitor response times Log errors and failures Analyze model performance Common Pitfalls ❌ Exposing API keys in frontend : ✅ Correct Server side proxy : ❌ Not handling streaming errors : ✅ Correct with error handling : ❌ Ignoring rate limits : ✅ Correct with rate limiting : Performance Optimization Caching Responses Parallel Processing Resources Documentation : https://openrouter.ai/docs API Reference : https://openrouter.ai/docs/api reference Model List : https://openrouter.ai/models Pricing : https://openrouter.ai/docs/pricing Status Page : https://status.openrouter.ai Related Skills MCP Servers : Integration with Model Context Protocol (when built) TypeScript API Integration : Type safe OpenRouter clients Python API Integration : Python SDK usage patterns Summary OpenRouter provides unified access to 200+ LLMs OpenAI compatible API for easy migration Cost optimization through model selection and token management Streaming for responsive user experiences Function calling for tool integration Vision models for image understanding Fallback strategies for reliability Rate limiting and error handling essential Perfect for multi model apps, cost sensitive deployments, avoiding vendor lock in