API Reference
callModel
Creates a response using the OpenResponses API with multiple consumption patterns.
CallModelInput
*Either model or models is required.
ProviderPreferences
Configuration for routing and provider selection.
RequestOptions
ModelResult
Wrapper providing multiple consumption patterns for a response.
Methods
getText()
Get text content after tool execution completes.
getResponse()
Get full response with usage data (inputTokens, outputTokens, cachedTokens).
getTextStream()
Stream text deltas.
getReasoningStream()
Stream reasoning deltas (for reasoning models).
getNewMessagesStream()
Stream cumulative message snapshots in OpenResponses format.
getFullResponsesStream()
Stream all events including tool preliminary results.
getToolCalls()
Get all tool calls from initial response.
getToolCallsStream()
Stream tool calls as they complete.
getToolStream()
Stream tool deltas and preliminary results.
getContextUpdates()
Stream context snapshots whenever a tool calls
setContext(). Completes when tool execution finishes.
cancel()
Cancel the stream and all consumers.
Tool Types
tool()
Create a typed tool with Zod schema validation.
ToolConfig
* Provide exactly one of execute or onToolCalled. Omitting both (with execute: false) makes the tool a manual tool.
Tool
Union type of all tool types:
ToolWithExecute
Regular tool with execute function:
ToolWithGenerator
Generator tool with eventSchema:
ManualTool
Tool without execute function:
HITLTool
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: ... }.
Tool Type Guards
isManualTool— noexecuteand noonToolCalled. Always pauses the loop.isHITLTool— has anonToolCalledfunction.isAutoResolvableTool— either has anexecutefunction (regular/generator) or is a HITL tool. Returnsfalsefor manual and server tools.
Context Types
TurnContext
ToolExecuteContext
Flat context passed to tool execute functions.
Merges TurnContext fields with tool-specific context:
ToolContextMap
Context map for callModel’s context option,
keyed by tool name:
ContextInput
Context can be static, a sync function, or an async function:
NextTurnParamsContext
Stream Event Types
EnhancedResponseStreamEvent
ToolStreamEvent
ParsedToolCall
ToolExecutionResult
Stop Conditions
StopWhen
StopCondition
StopConditionContext
StepResult
Warning
Built-in Helpers
Format Helpers
fromChatMessages
Convert OpenAI chat format to OpenResponses input.
toChatMessage
Convert response to chat message format.
fromClaudeMessages
Convert Anthropic Claude format to OpenResponses input.
toClaudeMessage
Convert response to Claude message format.