Feature guides
Returning response objects and SSEs
Get more control by directly creating the response object.
Classically, the truss server wraps the prediction results of your custom model into a response object to be sent back via HTTP to the client.
In advanced use case you might want to create these response objects yourself. Example use cases are:
- Control over the HTTP status codes.
- With streaming responses, you can use server-side-events (SSEs).
There is likewise support for
using request objects.
You can return a response from either predict
or postprocess
and
any subclasses from starlette.responses.Response
are supported.
If you return a response from
predict
, you cannot use
postprocessing
. SSE / Streaming example
Response headers are not fully propagated. Include all information in the response itself.