Module image_fetch

Module image_fetch 

Source
Expand description

AI-13 (#201): Gateway-side image URL fetcher.

When a client sends a multimodal request with a remote image URL (the OpenAI image_url.url convention) and the target provider adapter requires base64 image data (Anthropic, Gemini), the gateway fetches the image, converts it to base64, and fills the data_b64 + media_type fields on ContentPart::Image. The OpenAI adapter continues to pass the remote URL through unchanged.

The fetcher is async and runs in serve_ai after guardrails and before adapter.build_request. It is opt-in per route via the ai.image_fetch config block; when disabled, remote URLs are dropped by the Anthropic/Gemini adapters as before (preserving backward compatibility).

Structs§

ImageFetchConfig
Configuration for the image fetcher.

Functions§

fetch_remote_images
Fetch remote image URLs in a ChatRequest and fill data_b64 + media_type on each ContentPart::Image that has a remote URL but no base64 data. Images that already have data_b64 (from data: URIs) are left unchanged. The url field is preserved so the OpenAI adapter can still pass it through.
has_remote_images
Check if a ChatRequest has any remote image URLs that would need fetching. Used to skip the fetcher entirely when not needed.