Working With Items

Normalize item streams into deterministic application behavior.

Item Iteration

TypeScript
const result = await client.callModel({ /* ... */ });

for (const item of result.items) {
  if (item.type === "text") console.log(item.text);
  if (item.type === "tool_call") await runTool(item);
  if (item.type === "reasoning") saveReasoning(item.summary);
}

Item Types

NameTypeRequiredDescription
text
itemRequiredFinal or partial natural language output.
tool_call
itemTool invocation with name and JSON args.
tool_result
itemTool execution result item for next turn.
reasoning
itemModel reasoning summary metadata.

Text Extraction Utility

extract-text.ts
export function extractText(items: Array<{ type: string; text?: string }>) {
  return items
    .filter((item) => item.type === "text" && item.text)
    .map((item) => item.text)
    .join("
");
}
Stable item handling
Always branch on item.type and keep a default handler for forward-compatible item variants.