Not yet available. The Agent SDK is tracked to be built — today, use the Client SDKs against the live chat completions API. The reference below describes the intended API.
This page is the complete type reference for callModel(). For a narrative introduction, see Call Model.
interface CallModelParams {
model: string;
messages?: InputMessage[];
inputItems?: Item[];
tools?: Tool[];
stopConditions?: StopCondition[];
dynamicParams?: (items: Item[]) => Partial<CallModelParams>;
nextTurnParams?: NextTurnParams;
stream?: boolean;
onToken?: (delta: string) => void;
onEvent?: (event: StreamEvent) => void;
maxTokens?: number;
temperature?: number;
topP?: number;
}
interface TurnResult {
output: string;
items: Item[];
usage: TokenUsage;
balance: bigint;
stopReason: StopReason;
stoppedBy?: StopCondition;
}
type StopReason =
| "end_turn"
| "stop_condition_met"
| "max_tokens"
| "error";
interface TokenUsage {
promptTokens: number;
completionTokens: number;
totalTokens: number;
costMicroDA: bigint;
}
type Item =
| MessageItem
| ToolCallItem
| ToolResultItem
| ErrorItem;
interface MessageItem {
type: "message";
role: "user" | "assistant" | "system";
content: string | ContentPart[];
turnIndex: number;
}
interface ToolCallItem {
type: "tool_call";
id: string;
name: string;
arguments: Record<string, unknown>;
turnIndex: number;
}
interface ToolResultItem {
type: "tool_result";
toolCallId: string;
output: string;
error?: string;
turnIndex: number;
}
interface ErrorItem {
type: "error";
code: string;
message: string;
turnIndex: number;
}
interface Tool {
name: string;
description: string;
parameters: JSONSchema;
execute: (args: Record<string, unknown>) => Promise<string>;
approval?: "always" | "never" | ((call: ToolCallItem) => Promise<boolean>);
}
type StopCondition =
| { type: "no_tool_calls" }
| { type: "max_turns"; maxTurns: number }
| { type: "balance_below"; threshold: bigint }
| { type: "output_schema"; schema: JSONSchema }
| { type: "custom"; check: (result: TurnResult) => boolean };
type StreamEvent =
| { type: "token"; delta: string }
| { type: "tool_call_start"; name: string }
| { type: "tool_call_end"; name: string }
| { type: "turn_end"; result: TurnResult }
| { type: "error"; code: string; message: string };
client.callModelStream(params) → AsyncIterable<StreamEvent> — the async-iterator alternative to the onToken/onEvent callbacks. See Streaming for events and usage.