ConstThe response object from OpenAI's Responses API. Can be either:
responses.create()responses.parse()An AIMessage containing:
id: The message ID from the response outputcontent: Array of message content blocks (text, images, etc.)tool_calls: Array of successfully parsed tool callsinvalid_tool_calls: Array of tool calls that failed to parseusage_metadata: Token usage information converted to LangChain formatadditional_kwargs: Extra data including:
refusal: Refusal text if the model refused to respondreasoning: Reasoning output for reasoning modelstool_outputs: Results from built-in tools (web search, file search, etc.)parsed: Parsed structured output when using json_schema formatresponse_metadata: Metadata about the response including model, timestamps, status, etc.Error if the response contains an error object. The error message and code are extracted from the response.error field.
const response = await client.responses.create({
model: "gpt-4",
input: [{ type: "message", content: "Hello" }]
});
const message = convertResponsesMessageToAIMessage(response);
console.log(message.content); // Message content
console.log(message.tool_calls); // Any tool calls made
The converter handles multiple output item types:
message: Text and structured content from the modelfunction_call: Tool/function calls that need to be executedreasoning: Reasoning traces from reasoning models (o1, o3, etc.)custom_tool_call: Custom tool invocationsTool calls are parsed and validated. Invalid tool calls (malformed JSON, etc.) are captured
in the invalid_tool_calls array rather than throwing errors.
Converts an OpenAI Responses API response to a LangChain AIMessage.
This converter processes the output from OpenAI's Responses API (both
createandparsemethods) and transforms it into a LangChain AIMessage object with all relevant metadata, tool calls, and content.