Loading topic
async/await, how HTTP requests and responses work, and what an LLM chat API does. It also assumes you have6 min readStreamingResponse. It assumes you know basic async/await, can run a script with asyncio.run, and know 6 min readasync/await, how HTTP requests and responses work, and how to write a FastAPI route with a Pydantic model. It also assumes you have read the previous chapter on asyn7 min readasync/await, can read an HTTP response, and have written a FastAPI route that returns a StreamingResponse. The previous chapter showed that an async generator can yi6 min readasync/await code and know what an async generator is. It also assumes you have a FastAPI route with a Pyda6 min readasync/await and know the earlier chapters' StreamingResponse endpoint. Here you will look at one line of that endpoint, client: AsyncOpenAI = Depends(get_client), and see why it is t6 min readhttpx that prints tokens as they arrive. It also shows how to parse the Server-Sent Events (SSE) framing correctly and how to handle the failures a client sees on a long-lived respons5 min readStreamingResponse, how Server-Sent Events (SSE) frame messages, and how the /chat endpoint streams chunks from an AsyncOpenAI client. You should also be comfortable with Pytho5 min read/chat endpoint from the previous chapters: a StreamingResponse that yields Server-Sent Events (SSE). You should know the basics of HTTP headers and have seen a reverse proxy such as nginx. The endpoint can be correct and still look broken in production. Tokens a5 min read/chat endpoint built earlier in this tutorial. That means the get_client dependency, the token_events generator, and the sse helper. You should also know basic pytest. By the end you will have tests for the streaming endpoint that run offline, cost not5 min read/chat endpoint from the earlier chapters.6 min read