Creates a response using the OpenResponses API with multiple consumption patterns.
*Either model or models is required.
Configuration for routing and provider selection.
Wrapper providing multiple consumption patterns for a response.
Get text content after tool execution completes.
Get full response with usage data (inputTokens, outputTokens, cachedTokens).
Stream text deltas.
Stream reasoning deltas (for reasoning models).
Stream cumulative message snapshots in OpenResponses format.
Stream all events including tool preliminary results.
Get all tool calls from initial response.
Stream tool calls as they complete.
Stream tool deltas and preliminary results.
Stream context snapshots whenever a tool calls
setContext(). Completes when tool execution finishes.
Cancel the stream and all consumers.
Create a typed tool with Zod schema validation.
* Provide exactly one of execute or onToolCalled. Omitting both (with execute: false) makes the tool a manual tool.
Union type of all tool types:
Regular tool with execute function:
Generator tool with eventSchema:
Tool without execute function:
Human-in-the-loop tool with onToolCalled and optional onResponseReceived hooks. outputSchema is required — it validates both the hook’s non-null return value and the caller-supplied response delivered via function_call_output.
Returning null from onToolCalled pauses the loop and sets the conversation status to 'awaiting_hitl'. Throwing from onToolCalled is surfaced as a tool error of the form { error: ... }. Throwing from onResponseReceived is surfaced as an error payload that includes the caller’s original output of the form { error: ..., originalOutput: ... }.
isManualTool — no execute and no onToolCalled. Always pauses the loop.isHITLTool — has an onToolCalled function.isAutoResolvableTool — either has an execute function (regular/generator) or is a HITL tool. Returns false for manual and server tools.Flat context passed to tool execute functions.
Merges TurnContext fields with tool-specific context:
Context map for callModel’s context option,
keyed by tool name:
Context can be static, a sync function, or an async function:
Convert OpenAI chat format to OpenResponses input.
Convert response to chat message format.
Convert Anthropic Claude format to OpenResponses input.
Convert response to Claude message format.