Unable to call Streaming Response from FastAPI in production
My StreamingResponse with FastAPI using Hypercorn works in development but not during production on Railway.
The deploy logs show a Prisma debug but stops mid way through the function with no error. On the frontend it Errors with 504 because it just Timesout.
Is there anything unique I should be aware of with Streaming Responses on Railway?
My API route I am calling is attached
Solution:Jump to solution
I figured it out. When disconnecting from Prisma Query Engine it would just freeze the server. I switched from using Hypercorn to Uvicorn and now it works!
26 Replies
Project ID:
272293fe-814d-4a92-9d85-82c242f56daa
this is just SSE right?
Yes its via an API call from a next.js server
no issues with SSE on railway - https://utilities.up.railway.app/sse
are you sending SSEs to a client's browser or? need a little more context here
Yes, sorry, I am sending it to a clients browser. They make an API call from the next.js backend to Railway for this 'gen_query'.
where does fastapi come into play with next and a clients browser
A call from next/api is sent to fastAPI via:
the whole route.ts is as follows:
for testing, cut out the nextjs app and call the public domain of the fastapi service
Okay will do. I have tested several different ways to make API calls but it seems once it hits one error or warning it stalls and I cant call it again... I thought it was a hypercorn thing maybe
this is no doubt a code or config issue, its just a question of where
What is the best way of logging on Railway during API calls?
json structured logs would be best
okay i'll try it out. thanks!
How come debugging in Deploy Logs is highlighted red with a level: "error" with really no other information besides this?
I get it that this means that its printing to stderr
are you doing json logging?
alot of it is print(). Should I use 'structlog' or is there a preference on Railway?