LangChainLangChain 1.4 · Python 3.10+
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
46 small wins to finish your pathNext lesson →

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

python
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.

python
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.

Example
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-120b tells init_chat_model which package to import and which model to request.
  • No key, no model. With GROQ_API_KEY unset 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.
Watch out. A hosted model does not follow your rules. It may put a sentence and a tool call in one message, word an answer differently twice, or ask the customer a question back. Keep the five key-free tests as the check on your own code, since the model's wording will vary.
Try it yourself
  • 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 installing langchain-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.