Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

langchain-openrouter

БесплатноБез исполняемых скриптовНе проверен

LangChain OpenRouter integration — ChatOpenRouter gives access to hundreds of models (Claude, GPT-4o, Gemini, Llama, etc.) through a single API key. Supports…

enunoот enuno★ 17 звёзд на GitHub

Об этом скилле

LangChain OpenRouter Skill

Expert assistance for langchain-openrouter: one class (ChatOpenRouter) that routes to hundreds of models from OpenAI, Anthropic, Google, Meta, and more through a single API and API key.

Install: pip install -U langchain-openrouter
Setup: export OPENROUTER_API_KEY=your_api_key
Models: https://openrouter.ai/models

Reference: references/api.md (500 KB — full API reference).

When to Use This Skill

Activate when:

  • Switching between model providers — using ChatOpenRouter with different model strings
  • Routing to a specific provider — using openrouter_provider={"order": [...]} to prefer one backend
  • Using reasoning models — setting reasoning param for models like deepseek/deepseek-r1
  • Tool calling — using .bind_tools() with any OpenRouter model
  • Structured output — using .with_structured_output() with a Pydantic schema
  • Adding app attribution — setting app_url, app_title, app_categories for marketplace
  • Grouping requests — using session_id for observability
  • Tracing broadcast metadata — using trace param
  • Using OpenRouter plugins — setting plugins param

Quick Reference

ChatOpenRouter — basic usage

from langchain_openrouter import ChatOpenRouter

# Use any model from openrouter.ai/models
model = ChatOpenRouter(
    model="anthropic/claude-sonnet-4-6",
    temperature=0.7,
    max_tokens=1024,
    # api_key="...",  # or set OPENROUTER_API_KEY env var
)

response = model.invoke("Explain quantum entanglement in plain English.")
print(response.content)

# Stream
for chunk in model.stream("Write a haiku about code:"):
    print(chunk.content, end="", flush=True)

Switch models with one variable

from langchain_openrouter import ChatOpenRouter

# GPT-4o
model = ChatOpenRouter(model="openai/gpt-4o", temperature=0)

# Gemini Flash (fast, cheap)
model = ChatOpenRouter(model="google/gemini-2.0-flash", temperature=0)

# Llama 3.1 (open source, free tier)
model = ChatOpenRouter(model="meta-llama/llama-3.1-8b-instruct", temperature=0.5)

# DeepSeek R1 (reasoning)
model = ChatOpenRouter(model="deepseek/deepseek-r1", temperature=0)

Force routing to a specific provider

from langchain_openrouter import ChatOpenRouter

# Force anthropic/claude-sonnet-4-5 to route through Anthropic (not a proxy)
model = ChatOpenRouter(
    model="anthropic/claude-sonnet-4-6",
    openrouter_provider={
        "order": ["Anthropic"],          # try Anthropic first
        # "allow_fallbacks": False,      # fail if Anthropic unavailable
        # "require_parameters": True,    # only use providers that support all params
    },
)

# Route through Azure OpenAI
model = ChatOpenRouter(
    model="openai/gpt-4o",
    openrouter_provider={"order": ["Azure"]},
)

Reasoning models

from langchain_openrouter import ChatOpenRouter

model = ChatOpenRouter(
    model="deepseek/deepseek-r1",
    reasoning={
        "effort": "high",       # low | medium | high
        # "exclude": False,     # True to hide reasoning from response
    },
    temperature=0,
)

response = model.invoke("What is the 100th Fibonacci number?")
print(response.content)
# response.additional_kwargs may contain reasoning trace

Tool calling

from langchain_openrouter import ChatOpenRouter
from langchain_core.tools import tool

@tool
def get_stock_price(ticker: str) -> float:
    """Get the current stock price for a ticker symbol."""
    return 150.25  # mock

model = ChatOpenRouter(model="openai/gpt-4o-mini")
model_with_tools = model.bind_tools([get_stock_price])

response = model_with_tools.invoke("What's the current AAPL price?")
print(response.tool_calls)

Structured output

from langchain_openrouter import ChatOpenRouter
from pydantic import BaseModel, Field

class MovieReview(BaseModel):
    title: str = Field(description="Movie title")
    rating: float = Field(description="Rating from 0 to 10")
    summary: str = Field(description="Brief review summary")

model = ChatOpenRouter(model="anthropic/claude-sonnet-4-6")
structured = model.with_structured_output(MovieReview)

review = structured.invoke("Review the movie Inception.")
print(f"{review.title}: {review.rating}/10")

Attribution and observability

from langchain_openrouter import ChatOpenRouter

model = ChatOpenRouter(
    model="openai/gpt-4o-mini",
    app_url="https://myapp.example.com",    # shows in OpenRouter dashboard
    app_title="My LLM App",
    app_categories=["productivity", "coding"],
    session_id="user-session-abc123",        # group related requests
    trace={                                   # metadata for broadcast
        "user_id": "user-123",
        "experiment": "v2-prompts",
    },
)

API Reference

ChatOpenRouter key parameters

Param Type Description
model str Model ID (e.g. `"ant
Полный SKILL.md на GitHub

Установить langchain-openrouter в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

references/api.mdreferences/index.mdreferences/llms-full.mdreferences/llms.md

FAQ

Что делает скилл langchain-openrouter?

LangChain OpenRouter integration — ChatOpenRouter gives access to hundreds of models (Claude, GPT-4o, Gemini, Llama, etc.) through a single API key. Supports provider routing preferences, reasoning models, plugins, tool calling, structured output, and request attribution/tracing.

Как установить скилл langchain-openrouter?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл langchain-openrouter запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить langchain-openrouter с