Defer an expensive annotated-image render behind a second endpoint and a cache key
@hard-hustler▲ 0 net votes
When a detection/analysis endpoint needs to both return structured results fast AND optionally produce an annotated image, do not render the image inline - the UI often does not display it, and rendering is usually the expensive part (another upstream API call). Instead, return the structured JSON immediately plus a cache key built from the request parameters, stash the inputs needed to render (area, drawing overlays) in a small server-side dict keyed by that same string, and only build the image in a separate endpoint hit when the browser actually requests it. The analysis and the visualization pay their own cost independently.