API Reference

Complete reference for the callModel API, ModelResult class, tool types, and helper functions.

callModel

Creates a response using the OpenResponses API with multiple consumption patterns.

CallModelInput

ParameterTypeRequiredDescription
modelstring | ((ctx: TurnContext) => string)Yes*Model ID (e.g., “openai/gpt-5-nano”)
modelsstring[]Yes*Model fallback array
inputOpenResponsesInputYesInput messages or string
instructionsstring | ((ctx: TurnContext) => string)NoSystem instructions
toolsTool[]NoTools available to the model
maxToolRoundsMaxToolRoundsNoTool execution limit (deprecated)
stopWhenStopWhenNoStop conditions
temperaturenumber | ((ctx: TurnContext) => number)NoSampling temperature (0-2)
maxOutputTokensnumber | ((ctx: TurnContext) => number)NoMaximum tokens to generate
topPnumberNoTop-p sampling
textResponseTextConfigNoText format configuration
providerProviderPreferencesNoProvider routing and configuration
topKnumberNoTop-k sampling
metadataRecord<string, string>NoRequest metadata
toolChoiceToolChoiceNoTool choice configuration
parallelToolCallsbooleanNoEnable parallel tool calling
reasoningReasoningConfigNoReasoning configuration
promptCacheKeystringNoCache key for prompt caching
previousResponseIdstringNoContext from previous response
includestring[]NoInclude extra fields in response
backgroundbooleanNoRun request in background
safetyIdentifierstringNoUser safety identifier
serviceTierstringNoService tier preference
truncationstringNoTruncation mode
pluginsPlugin[]NoEnabled plugins
userstringNoEnd-user identifier
sessionIdstringNoSession identifier
storebooleanNoStore request data

*Either model or models is required.

ProviderPreferences

Configuration for routing and provider selection.

ParameterTypeDescription
allowFallbacksbooleanAllow backup providers when primary is unavailable (default: true)
requireParametersbooleanOnly use providers that support all requested parameters
dataCollection"allow" | "deny"Data collection policy (allow/deny)
orderstring[]Custom provider routing order
onlystring[]Restrict to specific providers
ignorestring[]Exclude specific providers
quantizationsstring[]Filter by quantization levels
sortstringLoad balancing strategy (e.g., “throughput”)
maxPriceobjectMaximum price limits
preferredMinThroughputnumberMinimum tokens per second preference
preferredMaxLatencynumberMaximum latency preference

RequestOptions

ParameterTypeDescription
timeoutnumberRequest timeout in milliseconds
signalAbortSignalAbort signal for cancellation

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 incremental message updates 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.

cancel()

Cancel the stream and all consumers.


Tool Types

tool()

Create a typed tool with Zod schema validation.

ToolConfig

ParameterTypeRequiredDescription
namestringYesTool name
descriptionstringNoTool description
inputSchemaZodObjectYesInput parameter schema
outputSchemaZodTypeNoOutput schema
eventSchemaZodTypeNoEvent schema (triggers generator mode)
executefunction | falseYesExecute function or false for manual
nextTurnParamsNextTurnParamsFunctionsNoParameters to modify next turn

Tool

Union type of all tool types:

ToolWithExecute

Regular tool with execute function:

ToolWithGenerator

Generator tool with eventSchema:

ManualTool

Tool without execute function:


Context Types

TurnContext

NextTurnParamsContext


Stream Event Types

EnhancedResponseStreamEvent

ToolStreamEvent

ParsedToolCall

ToolExecutionResult


Stop Conditions

StopWhen

StopCondition

StopConditionContext

StepResult

Warning

Built-in Helpers

FunctionSignatureDescription
stepCountIs(n: number) => StopConditionStop after n steps
hasToolCall(name: string) => StopConditionStop when tool is called
maxTokensUsed(n: number) => StopConditionStop after n tokens
maxCost(amount: number) => StopConditionStop after cost limit
finishReasonIs(reason: string) => StopConditionStop on finish reason

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.


Type Utilities

InferToolInput

InferToolOutput

InferToolEvent

TypedToolCall


Exports