Skip to main content
This will help you get started with OpenRouter chat models. OpenRouter is a unified API that provides access to models from multiple providers (OpenAI, Anthropic, Google, Meta, and more) through a single endpoint.
API ReferenceFor detailed documentation of all features and configuration options, head to the ChatOpenRouter API reference.
For a full list of available models, visit the OpenRouter models page.

Overview

Integration details

Model features

Setup

To access models via OpenRouter you’ll need to create an OpenRouter account, get an API key, and install the @langchain/openrouter integration package.

Credentials

Head to the OpenRouter keys page to sign up and generate an API key. Once you’ve done this set the OPENROUTER_API_KEY environment variable:
To enable automated tracing of your model calls, set your LangSmith API key:

Installation

The LangChain OpenRouter integration lives in the @langchain/openrouter package:

Instantiation

Now you can instantiate the model:

Invocation


Streaming


Tool calling

OpenRouter uses the OpenAI-compatible tool calling format. You can describe tools and their arguments, and have the model return a JSON object with a tool to invoke and the inputs to that tool.

Bind tools

With ChatOpenRouter.bindTools, you can pass in Zod schemas, LangChain tools, or raw function definitions as tools to the model. Under the hood these are converted to OpenAI tool schemas and passed in every model invocation.

Strict mode

Pass strict: true to guarantee that model output exactly matches the JSON Schema provided in the tool definition:
For more on binding tools and tool call outputs, head to the tool calling docs.

Structured output

ChatOpenRouter supports structured output via the .withStructuredOutput() method. The extraction strategy is chosen automatically based on model capabilities:
  • jsonSchema—native JSON Schema response format (used when the model supports it)
  • functionCalling—wraps the schema as a tool call (default fallback)
  • jsonMode—asks the model to respond in JSON without strict schema constraints
When multi-model routing is active (models list or route: "fallback"), the method always falls back to functionCalling because the actual backend model’s capabilities are unknown at request time.
You can pass strict: true with the jsonSchema and functionCalling methods to enforce exact schema adherence:

Multimodal inputs

OpenRouter supports multimodal inputs for models that accept them. The available modalities depend on the model you select—check the OpenRouter models page for details.
Not all models support all modalities. Check the OpenRouter models page for model-specific support.

Image input

Provide image inputs along with text using a list content format.

Token usage metadata

After an invocation, token usage information is available on the usage_metadata attribute of the response:
When the underlying provider includes detailed token breakdowns in its response, they are surfaced automatically:
  • output_token_details.reasoning—tokens used for internal chain-of-thought reasoning
  • input_token_details.cache_read—input tokens served from prompt cache
When streaming, aggregate token usage from the final chunk:

Provider routing

Many models on OpenRouter are served by multiple providers. The provider parameter gives you control over which providers handle your requests and how they’re selected.

Order and filter providers

Use order to set a preferred provider sequence. OpenRouter tries each provider in order and falls back to the next if one is unavailable:
To restrict requests to specific providers only, use only. To exclude certain providers, use ignore:

Sort by cost, speed, or latency

By default, OpenRouter load-balances across providers with a preference for lower cost. Use sort to change the priority:

Data collection policy

If your use case requires that providers do not store or train on your data, set data_collection to "deny":

Filter by quantization

For open-weight models, you can restrict routing to specific precision levels:

Combine options

Provider options can be composed together:
See the OpenRouter provider routing docs for the full list of options.

Multi-model routing

OpenRouter supports routing requests across multiple models. Pass a models array and an optional route strategy:

Plugins

OpenRouter supports plugins that extend model capabilities. Pass plugin configurations via the plugins parameter:
Available plugins include web (web search), file-parser (PDF parsing), moderation, auto-router, and response-healing.

App attribution

OpenRouter supports app attribution via HTTP headers. Set these through constructor params:

API reference

For detailed documentation of all ChatOpenRouter features and configurations, head to the ChatOpenRouter API reference. For more information about OpenRouter’s platform, models, and features, see the OpenRouter documentation.