LangChain Chat Model API

This document provides the complete API reference for init_chat_model() and BaseChatModel.


init_chat_model() Full Parameters

ParametersTypeDefault ValueDescription
modelstr or NoneNoneModel name, in the format provider:model_name. Pass None to create a configurable model.
model_providerstr or NoneNoneSpecify the provider separately. Use when the model cannot be automatically inferred.
configurable_fields"any" or list or NoneNoneFields that can be modified at runtime. None=fixed model, "any"=all configurable.
config_prefixstr or NoneNoneConfiguration key prefix in multi-model scenarios.
temperaturefloatVaries by modelControls randomness, 0~2. 0=deterministic, 2=maximum creativity.
max_tokensintModel maximumMaximum number of output tokens
timeoutint/float or NoneNoneRequest timeout in seconds
max_retriesintVaries by modelNumber of retries on failure
base_urlstr or NoneOfficial URLCustom API endpoint
rate_limiterBaseRateLimiterNoneRate limiter
top_pfloat or NoneVaries by modelNucleus sampling parameter, 0~1
stoplist[str]NoneStop sequence

BaseChatModel Methods

MethodDescriptionReturn Value
invoke(input, config=None, **kwargs)Call the model synchronouslyAIMessage
ainvoke(input, config=None, **kwargs)Call the model asynchronouslyAIMessage
stream(input, config=None, **kwargs)Streaming call synchronouslyIterator[AIMessageChunk]
astream(input, config=None, **kwargs)Streaming call asynchronouslyAsyncIterator[AIMessageChunk]
batch(inputs, config=None, **kwargs)Batch calllist[AIMessage]
bind_tools(tools, **kwargs)Bind tool listRunnable[input, AIMessage]
with_structured_output(schema, **kwargs)Bind structured output schemaRunnable[input, BaseModel/dict]
bind(**kwargs)Bind runtime parametersRunnable

Supported Model Providers Quick Reference

Provider nameInstallation packageExample model value
openailangchain-deepseekdeepseek:deepseek-v4-flash
anthropiclangchain-anthropicanthropic:claude-sonnet-4-5-20250929
deepseeklangchain-deepseekdeepseek:deepseek-chat
google_genailangchain-google-genaigoogle_genai:gemini-2.5-flash
ollamalangchain-ollamaollama:llama3.2
groqlangchain-groqgroq:llama-3.3-70b
xailangchain-xaixai:grok-3
mistralailangchain-mistralaimistralai:mistral-large
openrouterlangchain-openrouteropenrouter:openai/gpt-4o
perplexitylangchain-perplexityperplexity: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")
Other Extensions