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,926 stars 433 forks Updated yesterday 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
1 years ago
Last Updated
yesterday
Language
Python
License
MIT

Integrates with

Bundled in these plugins

Similar Skills

Semantically similar based on skill content — not just same category