IntermediateVocabulary#Vercel AI SDK#streaming#React#LLM tools
Vercel AI SDK Exercises
The Vercel AI SDK provides a unified TypeScript interface for building AI-powered applications. These exercises cover generateText return values, generateObject with Zod schemas, the useChat hook's api prop, streaming tool calls, and the provider model adapter pattern.
0 / 5 completed
1 / 5
A developer calls const result = await generateText({ model, prompt }) using the Vercel AI SDK. What does the return value contain?
generateText() returns an object with result.text (the full generated string), result.usage (token counts), result.finishReason, result.toolCalls if tools were used, and other metadata. It waits for the complete response before resolving, unlike streamText().
2 / 5
What is the purpose of generateObject() in the Vercel AI SDK?
generateObject() uses the provider's structured output mechanism (JSON mode, tool calling, or constrained generation) to produce output that is validated against a Zod schema and returned as a typed TypeScript object. It handles the provider-specific implementation details automatically.
3 / 5
A Next.js developer uses the AI SDK's useChat hook. Which prop must be provided to specify the backend API route?
The api prop specifies the backend route URL, defaulting to '/api/chat'. useChat({ api: '/api/my-chat' }) points the hook to a custom route. The backend route should use streamText() and return a streaming response compatible with the AI SDK's protocol.
4 / 5
How does the Vercel AI SDK handle tools in a streamText() call?
In streamText(), the model can emit tool call events mid-stream. The AI SDK streams these as structured data events. Developers can use onChunk, onStepFinish, or the result.steps async iterator to detect tool calls, execute them, and feed results back in a multi-step loop.
5 / 5
A developer imports anthropic from @ai-sdk/anthropic and uses anthropic('claude-3-5-sonnet-20241022'). What does this return?
The provider function returns a LanguageModel object that conforms to the Vercel AI SDK's standard model interface. This abstraction allows generateText(), streamText(), and other AI SDK functions to work identically regardless of whether you're using Anthropic, OpenAI, Google, or any other supported provider.