Get confident with Vercel AI SDK vocabulary — streaming text and objects, tool call handling, and provider switching.
0 / 5 completed
1 / 5
During standup, a full-stack dev explains the useChat hook from the Vercel AI SDK. What does it handle?
useChat is a client-side hook that manages everything for a streaming chat UI: the messages array, input state, handleSubmit and handleInputChange event handlers, an isLoading flag, and a stop() function to abort. It streams responses from your /api/chat route and appends token-by-token to the last message.
2 / 5
In a PR review, a teammate uses streamText vs generateText. When should each be used?
streamText returns an async iterable of text deltas — pipe it to result.toDataStreamResponse() (formerly StreamingTextResponse) for client streaming. generateText awaits the complete response and returns the full text at once, suitable for batch processing, evals, or server-side pipelines where the client doesn't need incremental rendering.
3 / 5
An incident reveals that tool calls in streams are not being handled correctly. How should they work?
During a streamText call with tools defined, the model emits tool-call stream parts when it wants to invoke a tool. Your application catches these, executes the tool functions, and feeds results back. Use maxSteps to let streamText handle multi-turn tool use automatically — the model receives tool results and continues generating the final response.
4 / 5
In a design review, the team evaluates streamObject for a form-fill feature. What does it do?
streamObject uses the model's structured output mode and streams partial JSON as it's generated. Client-side, you receive a partialObjectStream of increasingly complete objects validated against your Zod schema. This enables progressively rendering a structured response — e.g. a product card filling in as fields arrive.
5 / 5
During a code review, the team discusses AI SDK provider packages. How does provider switching work?
Vercel AI SDK's provider abstraction means streamText({ model: openai('gpt-4o'), ... }) and streamText({ model: anthropic('claude-3-5-sonnet-20241022'), ... }) use identical code — just swap the model function. Each provider package handles authentication (via environment variables) and API format differences internally.