Overview
Chat models is part of the Agentic SDK LangChain integration. It provides a chat model interface that routes chat completion requests through watsonx Orchestrate using a consistent SDK interface. It aligns with the SDK runtime model for handling authentication, context, and API routing, and supports chat-based interactions, structured outputs, tool calling, and streaming responses. Chat models support the same API as langchain’s chat abstractions, and may be used as a direct replacement for running inside Orchestrate.Initialization patterns
From Instance Credentials (Standalone/Runs-Elsewhere Mode)
For standalone scripts or applications outside watsonx Orchestrate runtime:PYTHON
Direct initialization (Standalone/Runs-Elsewhere Mode) (Advanced)
See ‘Advanced Configuration’ section for more parameters.PYTHON
From RunnableConfig (Runtime/Runs-On Mode) (recommended)
For LangGraph agents with RunnableConfig:PYTHON
From Execution Context (Runtime/Runs-On Mode)
When running inside a watsonx Orchestrate runtime with execution context:PYTHON
watsonx Orchestrate Agentic Session
For advanced use cases with pre-configured AgenticSession:PYTHON
Usage examples
Basic chat completion
PYTHON
Streaming Responses
PYTHON
Tool calling
PYTHON
Structured output
PYTHON
Batch processing
PYTHON
Advanced Configuration
Note: additional params can be passed via direct initialization (ChatWxO.__init__()) or any of the helpers (from_instance_credentials, from_runnable_config, from_execution_context, from_session).
PYTHON
Supported Methods
ChatOpenAI supports the following methods:invoke(messages)- Synchronous chat completionainvoke(messages)- Async chat completionstream(messages)- Synchronous streamingastream(messages)- Async streamingbatch(messages_list)- Batch processingabatch(messages_list)- Async batch processingbind_tools(tools)- Bind tools/functionswith_structured_output(schema) - Structured output
Class Methods
from_instance_credentials(instance_url, api_key, model, **kwargs)- Create from instance credentials (standalone/runs-elsewhere)from_execution_context(execution_con text, model, **kwargs)- Create from execution context (runtime/runs-on)from_session(session, model, **kwargs)- Create from AgenticSession (runtime/runs-on)from_runnable_config(config, model, **kwargs)- Create from RunnableConfig (LangGraph)
Chat model IDs
Use the chat model ID formats returned by the watsonx Orchestrate/models endpoint:
PYTHON
watsonx/meta-llama/llama-3-2-90b-vision-instructwatsonx/ibm/granite-3-8b-instruct
- Chat models provides a drop-in replacement for chat model usage in LangChain-based agents.
- The model ID must follow the format returned by the platform.
- Authentication and request routing are handled through the SDK interface.

