Intermediate

Integration

Connect OpenRouter with popular AI coding tools, set up SDKs, and configure model routing and provider preferences for your workflow.

Using with Cline (VS Code)

Cline is one of the most popular AI coding assistants for VS Code, and it has built-in support for OpenRouter. This lets you access any of the 200+ models through Cline's interface.

  1. Install Cline Extension

    Open VS Code, go to Extensions (Ctrl+Shift+X), and search for "Cline". Install the extension.

  2. Select OpenRouter as Provider

    Open Cline settings and select OpenRouter as your API provider from the dropdown menu.

  3. Enter Your API Key

    Paste your OpenRouter API key (starting with sk-or-) into the API key field.

  4. Choose a Model

    Select a model from the dropdown. Popular choices include anthropic/claude-sonnet-4 for high-quality coding and openai/gpt-4o as a versatile alternative.

Cline tip: You can quickly switch models in Cline by clicking the model name at the top of the chat panel. This makes it easy to use a fast model for simple tasks and a powerful model for complex refactoring.

Using with Kilocode

Kilocode is another VS Code AI coding assistant that supports OpenRouter natively. The setup is very similar to Cline:

  1. Install Kilocode

    Search for "Kilocode" in the VS Code Extensions marketplace and install it.

  2. Configure OpenRouter

    Open Kilocode settings, select OpenRouter as the provider, and enter your API key.

  3. Select Model

    Choose your preferred model. Kilocode will show you all available OpenRouter models.

Using with Continue.dev

Continue.dev is an open-source AI code assistant for VS Code and JetBrains IDEs. To configure it with OpenRouter, edit your Continue configuration file:

JSON (~/.continue/config.json)
{
  "models": [
    {
      "title": "Claude Sonnet 4 (OpenRouter)",
      "provider": "openai",
      "model": "anthropic/claude-sonnet-4",
      "apiBase": "https://openrouter.ai/api/v1",
      "apiKey": "sk-or-your-api-key"
    },
    {
      "title": "GPT-4o (OpenRouter)",
      "provider": "openai",
      "model": "openai/gpt-4o",
      "apiBase": "https://openrouter.ai/api/v1",
      "apiKey": "sk-or-your-api-key"
    }
  ]
}

Using with Any OpenAI-Compatible Tool

Any application that supports the OpenAI API can be configured to use OpenRouter instead. The general steps are:

  1. Find the API base URL or endpoint setting and change it to https://openrouter.ai/api/v1
  2. Enter your OpenRouter API key (starting with sk-or-) as the API key
  3. Set the model name using OpenRouter's model ID format (e.g., anthropic/claude-sonnet-4)
💡
Compatibility: This works because OpenRouter implements the exact same API format as OpenAI. Tools like LiteLLM, Open WebUI, LibreChat, Jan, and many others can all connect through OpenRouter.

Python SDK Setup

For Python projects, use the official OpenAI SDK with OpenRouter:

Bash
# Install the OpenAI SDK
pip install openai

# Set your API key as an environment variable
export OPENROUTER_API_KEY="sk-or-your-api-key"
Python (Setup)
import os
from openai import OpenAI

# Create a reusable client
client = OpenAI(
    base_url="https://openrouter.ai/api/v1",
    api_key=os.getenv("OPENROUTER_API_KEY"),
    default_headers={
        "HTTP-Referer": "https://your-app.com",
        "X-Title": "Your App Name",
    },
)

# Now use it like you would the OpenAI client
response = client.chat.completions.create(
    model="anthropic/claude-sonnet-4",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)

Node.js SDK Setup

Bash
# Install the OpenAI Node.js SDK
npm install openai
JavaScript (Setup)
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 Name",
  },
});

// Use it like the standard OpenAI client
const response = await client.chat.completions.create({
  model: "google/gemini-2.5-pro",
  messages: [{ role: "user", content: "Hello!" }],
});
console.log(response.choices[0].message.content);

Model Routing and Fallbacks

OpenRouter can automatically handle model routing and provider fallbacks. You can configure this through request parameters:

Python (Routing & Fallbacks)
response = client.chat.completions.create(
    model="anthropic/claude-sonnet-4",
    messages=[{"role": "user", "content": "Hello!"}],
    extra_body={
        # Specify provider preferences
        "provider": {
            "order": ["Anthropic", "AWS Bedrock"],
            "allow_fallbacks": True,
        },
        # Use auto-routing for best model selection
        # "route": "fallback",
    },
)

Provider Preferences

You can control which underlying providers OpenRouter uses for each model:

  • order: Specify preferred providers in order of priority (e.g., try Anthropic first, then AWS Bedrock).
  • allow_fallbacks: If your preferred providers are unavailable, allow OpenRouter to use any available provider.
  • require_parameters: Only route to providers that support specific features like function calling or streaming.
Integration tip: Start with a simple setup using just the API key and model name. Add provider preferences and fallback configuration later once you understand your specific needs and usage patterns.

Ready to Go Deeper?

Live instructor-led courses from our partners. Affiliate disclosure.