kmail.at
← learning

langchain · difficulty ◆◆

init_chat_model Gains a langsmith Provider

Swap your model by environment variable - now including models served on LangSmith.

The same one-liner that makes an OpenAI model can now point at a LangSmith-hosted fine-tune.

2026-08-14 · 8 min read

$ pip install -U langchain==1.3.15

What it does

init_chat_model() is LangChain\u2019s unified factory for creating chat models without hard-coding a provider. Until now it targeted OpenAI, Anthropic, Google, Mistral, AWS Bedrock, and many others by provider string or model-name inference. In langchain 1.3.15, init_chat_model gains a langsmith provider, so you can instantiate a chat model hosted on LangSmith - used for evaluating and serving models, including fine-tuned or hosted variants - with the same one-line API. Under the hood it selects the right BaseChatModel subclass and wires credentials, just like other providers.

Why it matters

init_chat_model is the backbone of provider-agnostic apps: you write your chain once against a generic chat model and swap providers via a config value. Adding LangSmith as a first-class provider means you can point the same app at a LangSmith-hosted model - great for evaluation harnesses, A/B-testing candidates, or serving fine-tunes - without rewriting your pipeline. This is exactly the seam you want for switch-by-environment-variable setups: a single model= string controls whether you hit openai:gpt-4o or langsmith:your-model.

Example

$ Instantiate an OpenAI model and a LangSmith-hosted model through the same factory
openai: ChatOpenAI
langsmith: <langsmith chat model class>
ChatOpenAI -> Hello!
<langsmith model> -> Hello!
Configured: openai ChatOpenAI

Both are BaseChatModel subclasses, so downstream components work unchanged.

$ Swap provider by environment variable
provider = os.environ.get("CHAT_PROVIDER", "openai")
model_name = os.environ.get("CHAT_MODEL", "gpt-4o-mini")
model = init_chat_model(model_name, model_provider=provider)

Common flags

init_chat_model
Unified factory that creates a chat model for any provider.
model_provider
Explicitly selects the provider, e.g. openai or langsmith.
create_chat_model
Legacy/alternative constructor for building chat models with explicit defaults.

History

From many providers to a provider registry

init_chat_model grew from a convenience for a handful of big providers into a genuine registry spanning the ecosystem. Adding LangSmith rounds out that story: evaluation and serving were the missing piece, and now a single factory can target them alongside the usual suspects. It is a small change with a big implication for test/rollout workflows.

Fun facts

Pros & cons

pros

  • + One factory for every provider
  • + Switch model by config value
  • + Eval and serving in the same API

cons

  • − Class name varies by integration
  • − Requires langchain>=1.3.15

Takeaways

  1. 1Upgrade to langchain>=1.3.15 for the langsmith provider.
  2. 2Centralize provider selection in an environment variable.
  3. 3Point eval harnesses at LangSmith-hosted candidates through init_chat_model.

Related commands

← all learning