Working with Items
Understanding the items-based streaming paradigm for callModel
Understanding the items-based streaming paradigm for callModel
callModel is built on OpenRouter’s Responses API which uses an items-based
model rather than the messages-based model used by OpenAI Chat or Vercel AI
SDK.
The key insight: items are emitted multiple times with the same ID but progressively updated content. You replace the entire item by ID rather than accumulating stream chunks.
getItemsStream() yields these item types:
Each iteration yields a complete item with the same ID but updated content:
The same pattern applies to function calls:
The items paradigm eliminates manual chunk accumulation. Use a Map keyed by item ID and let React’s reconciliation handle updates:
Traditional streaming requires manual accumulation:
With items, each emission replaces the previous:
The items approach is especially powerful when the model produces multiple outputs simultaneously (e.g., thinking + tool calls + text).
getNewMessagesStream() is deprecated in favor of getItemsStream(). The
migration is straightforward:
The key difference: getItemsStream() includes all item types (reasoning,
function calls, etc.), not just messages.