OpenRouter chat model integration.
Talks directly to the OpenRouter REST API via fetch (no SDK dependency)
and supports tool calling, structured output, and streaming. Any model
available on OpenRouter can be used by passing its identifier (e.g.
"anthropic/claude-4-sonnet") as the model param.
class ChatOpenRouterOpenRouter API key. Falls back to the OPENROUTER_API_KEY env var.
Marketplace categories for OpenRouter attribution.
Maps to X-OpenRouter-Categories header.
See https://openrouter.ai/docs/app-attribution for recognized categories.
Base URL for the API. Defaults to "https://openrouter.ai/api/v1".
The async caller should be used by subclasses to make any async calls, which will thus benefit from the concurrency and retry logic.
Additive penalty based on how often a token has appeared so far (−2 to 2).
A path to the module that contains the class, eg. ["langchain", "llms"] Usually should be the same as the entrypoint the class is exported from.
Token-level biases to apply during sampling.
Maximum number of tokens to generate.
Minimum probability threshold for token sampling.
Model identifier, e.g. "anthropic/claude-4-sonnet".
Extra params passed through to the API body.
OpenRouter-specific list of models for routing.
OpenRouter plugins to enable (e.g. web search).
Additive penalty based on whether a token has appeared at all (−2 to 2).
OpenRouter-specific provider preferences and ordering.
Multiplicative penalty applied to repeated token logits (0 to 2).
OpenRouter-specific routing strategy.
Random seed for deterministic generation.
Identifier used by OpenRouter to group related requests together.
Application title for OpenRouter attribution. Maps to X-Title header.
Defaults to 'LangChain'. Set this to your app's name to get attribution
for API usage in the OpenRouter dashboard.
See https://openrouter.ai/docs/app-attribution for details.
Application URL for OpenRouter attribution. Maps to HTTP-Referer header.
Defaults to LangChain docs URL. Set this to your app's URL to get attribution for API usage in the OpenRouter dashboard.
See https://openrouter.ai/docs/app-attribution for details.
Stop sequences that halt generation.
Whether to include token usage in streaming chunks. Defaults to true.
Sampling temperature (0–2).
Top-A sampling threshold.
Top-K sampling: only consider the K most likely tokens.
Number of most-likely log-probabilities to return per token.
Nucleus sampling cutoff probability.
Trace metadata for OpenRouter broadcast destinations.
OpenRouter-specific transformations to apply to the request.
Stable identifier for end-users, used for abuse detection.
Whether to print out response text.