Describe the bug
When gr.Examples uses lazy caching, the first click executes the example function through an internal Blocks.process_api(..., request=None) call. As a result, the visitor request context is discarded. In a Space or Pod that calls a downstream ZeroGPU Space with gradio_client, the downstream call therefore cannot forward the visitor's X-IP-Token and is charged as visitor-less Space GPU usage.
Expected behavior
The first visitor who clicks a lazily cached example should provide the request context used to compute that cache entry, so downstream ZeroGPU calls receive that visitor's X-IP-Token. Subsequent clicks should continue to use the shared cached result without rerunning the function. Eager startup caching can remain visitor-less because no request exists.
Reproduction
- Build a Gradio app with
gr.Examples(..., cache_examples=True, cache_mode="lazy").
- In the example function, inspect
gradio.context.LocalContext.request or create a gradio_client.Client for a downstream ZeroGPU Space.
- Click an example while sending an
X-IP-Token header.
- Observe that the example function runs with no request and the token is not forwarded.
Additional context
Pod/Space GPU usage without X-IP-Token is being deprecated, so lazy example execution needs to be attributed to the clicking visitor.
Describe the bug
When
gr.Examplesuses lazy caching, the first click executes the example function through an internalBlocks.process_api(..., request=None)call. As a result, the visitor request context is discarded. In a Space or Pod that calls a downstream ZeroGPU Space withgradio_client, the downstream call therefore cannot forward the visitor'sX-IP-Tokenand is charged as visitor-less Space GPU usage.Expected behavior
The first visitor who clicks a lazily cached example should provide the request context used to compute that cache entry, so downstream ZeroGPU calls receive that visitor's
X-IP-Token. Subsequent clicks should continue to use the shared cached result without rerunning the function. Eager startup caching can remain visitor-less because no request exists.Reproduction
gr.Examples(..., cache_examples=True, cache_mode="lazy").gradio.context.LocalContext.requestor create agradio_client.Clientfor a downstream ZeroGPU Space.X-IP-Tokenheader.Additional context
Pod/Space GPU usage without
X-IP-Tokenis being deprecated, so lazy example execution needs to be attributed to the clicking visitor.