YouTip LogoYouTip

Langchain Chat Model Api

This document provides the complete API reference for init_chat_model() and BaseChatModel. * * * ## init_chat_model() Complete Parameters | Parameter | Type | Default | Description | | --- | --- | --- | --- | | model | str or None | None | Model name in format provider:model_name. Pass None to create a configurable model | | model_provider | str or None | None | Specify provider separately. Used when model cannot be inferred automatically | | configurable_fields | "any" or list or None | None | Fields modifiable at runtime. None=fixed model, "any"=all configurable | | config_prefix | str or None | None | Configuration key prefix for multi-model scenarios | | temperature | float | Varies by model | Controls randomness, 0~2. 0=deterministic, 2=maximum creativity | | max_tokens | int | Model limit | Maximum 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 address | Custom API endpoint | | rate_limiter | BaseRateLimiter | None | Rate limiter | | top_p | float or None | Varies by model | Nucleus sampling parameter, 0~1 | | stop | list | None | Stop sequences | * * * ## BaseChatModel Methods | Method | Description | Return Value | | --- | --- | --- | | invoke(input, config=None, **kwargs) | Synchronous model invocation | AIMessage | | ainvoke(input, config=None, **kwargs) | Asynchronous model invocation | AIMessage | | stream(input, config=None, **kwargs) | Synchronous streaming invocation | Iterator | | astream(input, config=None, **kwargs) | Asynchronous streaming invocation | AsyncIterator | | batch(inputs, config=None, **kwargs) | Batch invocation | list | | 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 ## Example 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() response = model_with_tools.invoke("Query Weather") # Structured output model_structured = model.with_structured_output(MySchema) result = model_structured.invoke("Extract Information")
← Langchain Messages ApiLangchain Langsmith β†’