LangChain Chat Model API
This document provides the complete API reference for init_chat_model() and BaseChatModel.
init_chat_model() Full Parameters
| Parameters | Type | Default Value | Description |
|---|---|---|---|
| model | str or None | None | Model name, in the format provider:model_name. Pass None to create a configurable model. |
| model_provider | str or None | None | Specify the provider separately. Use when the model cannot be automatically inferred. |
| configurable_fields | "any" or list or None | None | Fields that can be modified at runtime. None=fixed model, "any"=all configurable. |
| config_prefix | str or None | None | Configuration key prefix in multi-model scenarios. |
| temperature | float | Varies by model | Controls randomness, 0~2. 0=deterministic, 2=maximum creativity. |
| max_tokens | int | Model maximum | Maximum number of output tokens |
| timeout | int/float or None | None | Request timeout in seconds |
| max_retries | int | Varies by model | Number of retries on failure |
| base_url | str or None | Official URL | Custom API endpoint |
| rate_limiter | BaseRateLimiter | None | Rate limiter |
| top_p | float or None | Varies by model | Nucleus sampling parameter, 0~1 |
| stop | list[str] | None | Stop sequence |
BaseChatModel Methods
| Method | Description | Return Value |
|---|---|---|
| invoke(input, config=None, **kwargs) | Call the model synchronously | AIMessage |
| ainvoke(input, config=None, **kwargs) | Call the model asynchronously | AIMessage |
| stream(input, config=None, **kwargs) | Streaming call synchronously | Iterator[AIMessageChunk] |
| astream(input, config=None, **kwargs) | Streaming call asynchronously | AsyncIterator[AIMessageChunk] |
| batch(inputs, config=None, **kwargs) | Batch call | list[AIMessage] |
| bind_tools(tools, **kwargs) | Bind tool list | Runnable[input, AIMessage] |
| with_structured_output(schema, **kwargs) | Bind structured output schema | Runnable[input, BaseModel/dict] |
| bind(**kwargs) | Bind runtime parameters | Runnable |
Supported Model Providers Quick Reference
| Provider name | Installation package | Example model value |
|---|---|---|
| openai | langchain-deepseek | deepseek:deepseek-v4-flash |
| anthropic | langchain-anthropic | anthropic:claude-sonnet-4-5-20250929 |
| deepseek | langchain-deepseek | deepseek:deepseek-chat |
| google_genai | langchain-google-genai | google_genai:gemini-2.5-flash |
| ollama | langchain-ollama | ollama:llama3.2 |
| groq | langchain-groq | groq:llama-3.3-70b |
| xai | langchain-xai | xai:grok-3 |
| mistralai | langchain-mistralai | mistralai:mistral-large |
| openrouter | langchain-openrouter | openrouter:openai/gpt-4o |
| perplexity | langchain-perplexity | perplexity:sonar-pro |
Common Usage Examples
Examples
from langchain.chat_models import init_chat_model
# Fixed model
model = init_chat_model("deepseek:deepseek-v4-flash", temperature=0)
response = model.invoke("Hello")
# Configurable model
model = init_chat_model(configurable_fields=("model", "temperature"))
response = model.invoke("Hello", config={
"configurable": {"model": "deepseek:deepseek-v4-flash", "temperature": 0.3}
})
# Bind tools
model_with_tools = model.bind_tools([my_tool])
response = model_with_tools.invoke("Query the weather")
# Structured output
model_structured = model.with_structured_output(MySchema)
result = model_structured.invoke("Extract information")
# Fixed model
model = init_chat_model("deepseek:deepseek-v4-flash", temperature=0)
response = model.invoke("Hello")
# Configurable model
model = init_chat_model(configurable_fields=("model", "temperature"))
response = model.invoke("Hello", config={
"configurable": {"model": "deepseek:deepseek-v4-flash", "temperature": 0.3}
})
# Bind tools
model_with_tools = model.bind_tools([my_tool])
response = model_with_tools.invoke("Query the weather")
# Structured output
model_structured = model.with_structured_output(MySchema)
result = model_structured.invoke("Extract information")