AI SDK Runtime
Use AI SDK as the application runtime layer for streaming, tools, agents, and telemetry.
Written and reviewed by Eric Han · Co-founder & CTO, reopt
Key takeaways
- AI SDK is the application runtime layer that turns model behavior into concrete product features: messages, streaming, structured output, tool calls, and telemetry.
- Keep tool schemas narrow and explicit, and scope which tools are available per user and task.
- Always validate structured output against its schema before triggering any side effect.
- Persist generation IDs and separate ephemeral UI state from durable task state for later review.
- Wire telemetry into product and cost dashboards so quality, cost, and latency stay connected.
AI SDK 7 compatibility contract
AI SDK 7 requires Node.js 22+ and ESM. Use Node.js 24 for these examples.
| Older API | Current API |
|---|---|
stepCountIs | isStepCount |
system | instructions; older name remains a deprecated fallback |
onFinish / onStepFinish | onEnd / onStepEnd |
experimental_telemetry | telemetry plus a registered integration |
result.fullStream | result.stream |
| Result response methods | Top-level stateless stream/response helpers |
Instructions returned by prepareStep carry into subsequent steps. Explicitly restore them for one-step overrides. Review stream, tool, approval, usage, and regression behavior after any codemod.
AI SDK is the application layer where product behavior becomes concrete: messages, streaming, structured outputs, tool calls, telemetry, and UI state.
Runtime Responsibilities
| Responsibility | Operating question |
|---|---|
| Message handling | What is persisted and replayed? |
| Streaming | What partial states can users see? |
| Tool calling | Which tools are available for this user and task? |
| Structured output | Which schema must the model satisfy? |
| Telemetry | Which traces connect quality, cost, and latency? |
| Error handling | What happens when model or tool calls fail? |
Runtime Rules
- Keep tool schemas narrow and explicit.
- Validate structured output before side effects.
- Persist generation IDs for later review.
- Separate UI state from durable task state.
- Connect telemetry to product and cost dashboards.