The desk on a hosted model
init_chat_model is a loader that turns a provider:model string into a chat model with the same invoke, stream and bind_tools as the one you wrote. The desk around it does not change.
Last updated: 27 Sep, 2026 · LangChain 1.4
init_chat_model takes a string naming the provider and the model, imports the matching package, and hands back a chat model with the same invoke, stream and bind_tools as DeskModel.
Naming a model with init_chat_model
from langchain.chat_models import init_chat_model
model = init_chat_model("groq:openai/gpt-oss-120b")The one-argument model swap
In desk.py, that model goes where DeskModel() was. The tools, the four middleware, the context and the checkpointer stay where they are, because each was written against the base class. create_agent accepts the string directly too, as create_agent("groq:openai/gpt-oss-120b", ...).
Because the string is accepted directly, the swap is one argument and the tools, middleware, context and checkpointer stay where they are.
from langchain.agents import create_agent
# the string works in place of a model object; the rest of desk.py is unchanged
agent = create_agent("groq:openai/gpt-oss-120b", tools=tools, middleware=middleware)What happens with no key set
Load the model with no key in the environment and it fails before any request, naming the variable to fill in.
from langchain.chat_models import init_chat_model
init_chat_model("groq:openai/gpt-oss-120b")The model cannot be built, and the error names the variable to fill in. Set it and the same desk runs against a hosted model.
What the string does, and what it needs
- The string names provider and model.
groq:openai/gpt-oss-120btellsinit_chat_modelwhich package to import and which model to request. - No key, no model. With
GROQ_API_KEYunset the call raises before any request, and the message names the variable to set. - The desk is unchanged. The tools, the four middleware, the context and the checkpointer were each written against the base class, so only the model line moves.
When you move to a hosted model
- Moving the desk from the stand-in to a hosted model once the tests pass.
- Switching providers by editing the string, from Groq to Google or OpenAI, with no other change.
Related
- Previous: Integrations: real base classes
- Next: A persistent vector store with Chroma
- Reference: Chat models
- Set a Groq key and run the desk's three tickets against the hosted model.
- Change the string to
"google_genai:gemini-2.5-flash"after installinglangchain-google-genai. - Watch the call limit from lesson 20 with a hosted model and count the model calls.
Slow is fine. Stopping is the only problem.