Skip to main content

Using LangChain

LangChain provides a standard interface for working with chat models. You can use OpenRouter with LangChain using the dedicated ChatOpenRouter integration packages. For more details on LangChain’s model interface, see the LangChain Models documentation. Resources:
import { ChatOpenRouter } from "@langchain/openrouter";

const model = new ChatOpenRouter(
  "anthropic/claude-sonnet-4.6",
  { temperature: 0.8 }
);

// Example usage
const response = await model.invoke([
  { role: "system", content: "You are a helpful assistant." },
  { role: "user", content: "Hello, how are you?" },
]);
from langchain_openrouter import ChatOpenRouter

model = ChatOpenRouter(
    model="anthropic/claude-sonnet-4.6",
    temperature=0.8,
)

# Example usage
response = model.invoke("What NFL team won the Super Bowl in the year Justin Bieber was born?")
print(response.content)
For full documentation — including streaming, tool calling, structured output, reasoning, multimodal inputs, provider routing, and more — see the LangChain integration guides: