openrouter-openai-compat

Featured

Migrate from OpenAI to OpenRouter with minimal code changes. Use when switching to OpenRouter or maintaining dual compatibility. Triggers: 'openrouter openai compatible', 'openrouter drop-in', 'openai to openrouter', 'openrouter migration'.

AI & Automation 2,266 stars 315 forks Updated today MIT

Install

View on GitHub

Quality Score: 99/100

Stars 20%
100
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# OpenRouter OpenAI Compatibility ## Overview OpenRouter implements the OpenAI Chat Completions API specification (`/v1/chat/completions`). Existing OpenAI SDK code works with OpenRouter by changing two values: `base_url` and `api_key`. This gives you access to 400+ models from all providers through the same SDK interface. ## The Two-Line Migration ### Python (Before) ```python from openai import OpenAI client = OpenAI(api_key=os.environ["OPENAI_API_KEY"]) # OpenAI direct response = client.chat.completions.create( model="gpt-4o", messages=[{"role": "user", "content": "Hello"}], ) ``` ### Python (After) ```python from openai import OpenAI client = OpenAI( base_url="https://openrouter.ai/api/v1", # Changed api_key=os.environ["OPENROUTER_API_KEY"], # Changed default_headers={ "HTTP-Referer": "https://your-app.com", # Added (optional) "X-Title": "Your App", # Added (optional) }, ) response = client.chat.completions.create( model="openai/gpt-4o", # Prefix with provider namespace messages=[{"role": "user", "content": "Hello"}], ) ``` ### TypeScript (After) ```typescript import OpenAI from "openai"; const client = new OpenAI({ baseURL: "https://openrouter.ai/api/v1", apiKey: process.env.OPENROUTER_API_KEY, defaultHeaders: { "HTTP-Referer": "https://your-app.com", "X-Title": "Your App" }, }); const res = await client.chat.completions.create({ model: "op...

Details

Author
jeremylongshore
Repository
jeremylongshore/claude-code-plugins-plus-skills
Created
7 months ago
Last Updated
today
Language
Python
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category

AI & Automation Featured

openrouter-upgrade-migration

Migrate to OpenRouter from direct provider APIs or upgrade between SDK/model versions. Triggers: 'openrouter migrate', 'openrouter upgrade', 'switch to openrouter', 'migrate from openai to openrouter'.

2,266 Updated today
jeremylongshore
API & Backend Featured

openrouter-install-auth

Set up OpenRouter API authentication and configure API keys. Use when starting a new OpenRouter integration, rotating keys, or troubleshooting auth issues. Triggers: 'openrouter setup', 'openrouter api key', 'configure openrouter auth', 'sk-or key'.

2,266 Updated today
jeremylongshore
AI & Automation Featured

openrouter-hello-world

Send your first OpenRouter API request and understand the response. Use when learning OpenRouter, testing setup, or verifying connectivity. Triggers: 'openrouter hello world', 'openrouter first request', 'test openrouter', 'openrouter quickstart'.

2,266 Updated today
jeremylongshore
AI & Automation Featured

openrouter-model-routing

Implement intelligent model routing to optimize cost, quality, and latency on OpenRouter. Use when building multi-model systems or optimizing spend across task types. Triggers: 'openrouter routing', 'model routing', 'route to model', 'model selection openrouter'.

2,266 Updated today
jeremylongshore
AI & Automation Featured

openrouter-fallback-config

Configure automatic model fallbacks for high availability on OpenRouter. Use when building resilient systems that need to survive provider outages. Triggers: 'openrouter fallback', 'model fallback', 'openrouter failover', 'openrouter backup model'.

2,266 Updated today
jeremylongshore