The Vercel AI SDK
Phases 1 to 4 built the plumbing by hand. Now a real SDK does it: streamText on the server, useChat in the browser, message parts, errors, metadata and saved chats.
In Phases 1 to 4 you wrote the plumbing yourself: the request, the stream reader, the parser, the states, stop, retry, the reducer, the saved chats. That was on purpose. Now you know what every line of a library has to do, so a library stops being magic.
This phase uses the Vercel AI SDK, version 7, the most widely used TypeScript toolkit for this job. On the server it gives you streamText (one call that talks to any model provider). In the browser it gives you useChat (messages, status, stop, regenerate, errors). Between them runs a stream format called the UI message stream, and every message is made of parts. You will see the real bytes, the real states, and every way it fails.
Every example runs the real ai and @ai-sdk/react packages inside the page, against a scripted stand-in model, so nothing needs an account or a key. The last topic rebuilds Mitra on the SDK: much less code, the same behaviour, and every state still handled.
Practise this phase
Hands-on exercises: write the code, see your page live, and press Check to have it tested automatically.