Class | Package | Local | Serializable | JS support | Package downloads | Package latest |
---|---|---|---|---|---|---|
ChatOpenAI | langchain-openai | ❌ | beta | ✅ |
Tool calling | Structured output | JSON mode | Image input | Audio input | Video input | Token-level streaming | Native async | Token usage | Logprobs |
---|---|---|---|---|---|---|---|---|---|
✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ |
langchain-openai
integration package.
langchain-openai
package:
ChatOpenAI
or AzureChatOpenAI
, set
stream_usage=True
as an initialization parameter or on invocation:
ChatOpenAI.bind_tools
, we can easily pass in Pydantic classes, dict schemas, LangChain tools, or even functions as tools to the model. Under the hood these are converted to an OpenAI tool schemas, which looks like:
strict=True
langchain-openai>=0.1.21
strict
argument when calling tools that will enforce that the tool argument schema is respected by the model. See more here: https://platform.openai.com/docs/guides/function-calling
Note: If strict=True
the tool definition will also be validated, and a subset of JSON schema are accepted. Crucially, schema cannot have optional args (those with default values). Read the full docs on what types of schema are supported here: https://platform.openai.com/docs/guides/structured-outputs/supported-schemas.
tool_calls
attribute. This contains in a standardized ToolCall format that is model-provider agnostic.
langchain-openai>=0.3.29
Context-free grammars
lark
or regex
format. See OpenAI docs for details. The format
parameter can be passed into @custom_tool
as shown below:langchain-openai>=0.3.9
ChatOpenAI
will route to the Responses API if one of these features is used. You can also specify use_responses_api=True
when instantiating ChatOpenAI
.
langchain-openai >= 0.3.26
allows users to opt-in to an updated AIMessage format when using the Responses API. Settingcontent
field, rather than additional_kwargs
. We recommend this format for new applications.{"type": "web_search_preview"}
to the model as you would another tool.
response.text
. For example, to stream response text:langchain-openai>=0.3.19
{"type": "image_generation"}
to the model as you would another tool.
ChatOpenAI
supports the "computer-use-preview"
model, which is a specialized model for the built-in computer use tool. To enable, pass a computer use tool as you would pass another tool.
Currently, tool outputs for computer use are present in the message content
field. To reply to the computer use tool call, construct a ToolMessage
with {"type": "computer_call_output"}
in its additional_kwargs
. The content of the message will be a screenshot. Below, we demonstrate a simple example.
First, load two screenshots:
content
:
tool_call_id
matching the call_id
from the computer-call.{"type": "computer_call_output"}
in its additional_kwargs
.image_url
or an input_image
output block (see OpenAI docs for formatting).MCP Approvals
"mcp_approval_request"
.To submit approvals for an approval request, structure it into a content block in an input message:previous_response_id
"id"
field in its metadata. Passing this ID to subsequent invocations will continue the conversation. Note that this is equivalent to manually passing in messages from a billing perspective.
previous_response_id
using the last response in a message sequence:
use_previous_response_id=True
, input messages up to the most recent response will be dropped from request payloads, and previous_response_id
will be set using the ID of the most recent response.
That is,
ChatOpenAI
to return this summary, specify the reasoning
parameter. ChatOpenAI
will automatically route to the Responses API if this parameter is set.
modelName
parameter.
This generally takes the form of ft:{OPENAI_MODEL_NAME}:{ORG_NAME}::{MODEL_ID}
. For example:
ChatOpenAI
, create a content block containing the data and incorporate it into a message, e.g., as below:
Images
PDFs
Audio
"gpt-4o-audio-preview"
.Refer to examples in the how-to guide here.In-line base64 data:langchain-openai>=0.2.6
gpt-4o
and gpt-4o-mini
series) support Predicted Outputs, which allow you to pass in a known portion of the LLM’s expected output ahead of time to reduce latency. This is useful for cases such as editing text or code, where only a small part of the model’s output will change.
Here’s an example:
langchain-openai>=0.2.3
gpt-4o-audio-preview
model.
output_message.additional_kwargs['audio']
will contain a dictionary like
model_kwargs['audio']['format']
.
We can also pass this message with audio data back to the model as part of a message history before openai expires_at
is reached.
audio
key in AIMessage.additional_kwargs
, but input content blocks are typed with an input_audio
type and key in HumanMessage.content
lists. **For more information, see OpenAI’s audio docs.service_tier="flex"
: