Request an update for the FASTAPI example using AI SDK v5
Description
Request an update for the FASTAPI example using AI SDK v5. https://github.com/vercel/ai/tree/main/examples/next-fastapi https://github.com/vercel/ai/pull/6167
AI SDK Version
- ai sdk v5
I have been experimenting with it and turns out it's not too different from before, just one thing I'm not getting is how to keep the order of text parts since they all get merged into one right now but instead of :
yield f'data:{json.dumps({"type": "text", "text": "foo bar. "})}\n\n'
yield f'data:{json.dumps({"type": "reasoning", "text": "some reasoning here"})}\n\n'
yield f'data:{json.dumps({"type": "text", "text": "more text later."})}\n\n'
yield f'data:{json.dumps({"type": "data-annotation", "data": [{"type": "citation", "id": "anno-1", "text": "Source [1]", "details": {"sourceId": "src-1"}}]})}\n\n'
Instead of V4 where it would look something like this :
yield f'0:{json.dumps("foo bar")}\n'
yield f'g:{json.dumps("some reasoning here")}\n'
yield f'0:{json.dumps("more text later")}\n'
yield f'8:{json.dumps([{"type": "citation", "id": "anno-1", "text": "Source [1]", "details": {"sourceId": "src-1"}}])}\n'
Before you would use the custom tunnels 0 , g , 8 , 3 etc now just data and put the type of the thing you're sending ... but again I still don't know why before foo bar and more text later would be two separate text parts but in V5 they will be combined into one text part which I don't think it's the intended way
I created an open-source Python library that handles the AI SDK streaming protocol and SSE event ordering for Python backends.
It may help for this issue/use case.
This is obsolete against the current FastAPI example/docs.
The original request was for an AI SDK v5 update. The repo now has examples/next-fastapi, and the current docs/examples have moved on to AI SDK 7. Relevant changes:
- #2458 added the FastAPI backend example.
- #3200 fixed JSON encoding for text stream parts in the Next/FastAPI example.
- #16357 released AI SDK 7, and #16365 updated the AI SDK 7 docs.
I’m closing this v5-specific docs/example request as obsolete. If the current FastAPI example is broken on [email protected], please open a new issue with the current failing path.
Identify issue type
Identified as Examples
Confidence: High
Rationale
The requested work concerns updating a repository example project rather than changing SDK behavior. Its later obsolescence does not change the original example-focused request.
Evidence
- The issue requests updating the runnable
examples/next-fastapiproject for AI SDK v5. - Discussion focuses on adapting the example’s Python streaming output and preserving text-part ordering.
- A maintainer later closed the request as obsolete because the FastAPI example and documentation had moved to AI SDK 7.