LogoToRouter Docs
LogoToRouter Docs
HomepageWhat is ToRouter5-minute quickstartCore concepts
OpenAI Python SDKOpenAI Node / TypeScript SDKAnthropic SDK (Python & TypeScript)Google Gen AI SDK (Gemini)CursorCline (VS Code extension)Claude Code CLILangChain & LlamaIndexDify & n8n (no-code)
Integrations

LangChain & LlamaIndex

Use LangChain's ChatOpenAI and LlamaIndex's OpenAI wrapper against ToRouter to mix Claude, GPT and Gemini in one chain.

LangChain's ChatOpenAI and LlamaIndex's OpenAI LLM wrapper both speak the OpenAI Chat Completions protocol — point them at ToRouter and you can drop any model from the catalog into chains, agents and RAG pipelines without changing framework code.

Configuration

FieldValue
Base URLhttps://portal.torouter.ai/v1
API keysk-***
Modelclaude-opus-4-7, gpt-5, gemini-2.5-pro, ...

OPENAI_BASE_URL and OPENAI_API_KEY env vars are auto-detected by both libraries.

LangChain

from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    base_url="https://portal.torouter.ai/v1",
    api_key="sk-***",
    model="claude-opus-4-7",
)

print(llm.invoke("Hello").content)
import { ChatOpenAI } from '@langchain/openai';

const llm = new ChatOpenAI({
  configuration: { baseURL: 'https://portal.torouter.ai/v1' },
  apiKey: 'sk-***',
  model: 'claude-opus-4-7',
});

const res = await llm.invoke('Hello');
console.log(res.content);

For embeddings use OpenAIEmbeddings with the same base URL and an embedding model id from the catalog (e.g. text-embedding-3-large).

LlamaIndex

llamaindex_quickstart.py
from llama_index.llms.openai import OpenAI

llm = OpenAI(
    api_base="https://portal.torouter.ai/v1",
    api_key="sk-***",
    model="gpt-5",
)

print(llm.complete("Hello").text)

Gotchas

  • LangChain Python uses base_url; LangChain JS uses configuration.baseURL; LlamaIndex uses api_base. The values are identical, the field names are not.
  • When mixing models in one chain (e.g. Claude for reasoning, GPT for tool-use), instantiate one wrapper per model — don't try to swap model mid-call.
  • Some agent frameworks expect strict OpenAI tool-call schemas; if a non-OpenAI model produces tool calls in a slightly different format, prefer the Anthropic SDK directly for that step. See anthropic.

Next steps

Create an API key

Base URL & auth reference

Model catalog

Troubleshoot errors

Claude Code CLI

Run Anthropic's official Claude Code CLI against ToRouter — full agentic coding without an Anthropic-only key.

Dify & n8n (no-code)

Wire Dify workflows and n8n automations to ToRouter via their OpenAI-compatible provider slots.

Table of Contents

ConfigurationLangChainLlamaIndexNext steps