Skip to content
Discussion options

You must be logged in to vote
    response_model=StreamingResponse,

The above is inclorrect. StreamingResponse is response class, but not response model.

Since you return the instance of StreamingResponse (which is a sub-class of Response class). FastAPI will not validate response (https://fastapi.tiangolo.com/advanced/response-directly/).

You can still specify response model when using StreamingResponse, but it will be for documentation purpose only. You are in charge of the response validation:

@app.get(
    "/",
    status_code=fastapi_status.HTTP_200_OK,
    response_model=list[str],  # For documentation only
)
async def main() -> StreamingResponse:
    return StreamingResponse(generate_list())  # FastAPI will no…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by YuriiMotov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
2 participants