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
| Name | Type | Required | Description |
|---|---|---|---|
text | item | Required | Final or partial natural language output. |
tool_call | item | Tool invocation with name and JSON args. | |
tool_result | item | Tool execution result item for next turn. | |
reasoning | item | Model 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.