ai icon indicating copy to clipboard operation
ai copied to clipboard

i want to use steaming protocol in django,but have some problem

Open Ufodar opened this issue 1 year ago • 3 comments

Description

I want to use the streaming protocol in the AI SDK, but my backend is Django instead of the FastAPI provided in the sample. After testing, I found that when using Django's streamHttpResponse to return data, the front-end sample cannot obtain the streaming data in real time. Instead, it waits for all the data to be transmitted completely before displaying them all together on the interface. What should I do? `` @api_view(['GET']) def test_get1(request): def event_stream(): for i in range(10):

yield '{{"data":{text}}}\n\n'.format(text=json.dumps(i))

yield 'data:'+json.dumps(i) + '\n\n' sleep(1) response = StreamingHttpResponse(event_stream(),content_type='text/event-stream') response.headers['x-vercel-ai-data-stream'] = 'v1' return response

AI SDK Version

No response

Ufodar avatar Jun 12 '25 07:06 Ufodar

got same error here

gerardburgues avatar Sep 16 '25 17:09 gerardburgues

I created an open-source Python library that handles the AI SDK streaming protocol and SSE event ordering for Python backends.

ai-sdk-stream-python

It may help for this issue/use case.

shloimy-wiesel avatar May 10 '26 15:05 shloimy-wiesel

Identify issue type

Identified type: None
Confidence: High

Rationale: This is primarily a support/integration question about implementing streaming with Django, not a confirmed bug in the AI SDK or a request to change documentation/examples/product behavior.

Evidence:

  • Reporter asks how to use the AI SDK streaming protocol with a Django backend instead of the FastAPI sample.
  • The described problem is that Django StreamingHttpResponse output is buffered until complete, with a request for guidance: “What should I do?”
  • Comments only echo the same issue or suggest a third-party Python library; they do not identify a concrete AI SDK defect.

lgrammel avatar Jul 02 '26 09:07 lgrammel