Hi, the docs directly say we can use Open Router inside init_chat_model by model_provider="openrouter"
However, when I do, I get an error that doesn’t include the open router. How do I get the init chat model to use the open router? The error I get is
The error comes from the legacy langchain package (pre-1.0). init_chat_model there has a fixed _SUPPORTED_PROVIDERS set that doesn’t include openrouter — that’s why the provider list in the error stops at the older integrations.
OpenRouter support in init_chat_model lives in langchain v1, which dispatches to the langchain-openrouter partner package. Two ways to fix:
import os
from langchain.chat_models import init_chat_model
os.environ["OPENROUTER_API_KEY"] = "sk-..."
model = init_chat_model("auto", model_provider="openrouter")
print(model.invoke("Why do parrots talk?"))
2. Or skip init_chat_model and instantiate directly
from langchain_openrouter import ChatOpenRouter
model = ChatOpenRouter(model="auto")