image-proxy

API Reference

HTTP endpoints and request parameters

Image Endpoint

GET /{filename}

Serves an image from the configured root path, optionally applying transformations. The filename supports nested paths (e.g., photos/2024/sample.jpg).

Query Parameters

ParameterTypeDescription
formatstringOutput format: avif, jpeg, jpg, jxl, png, webp
sizeu32Maximum bounding-box dimension in pixels. Maintains aspect ratio. Does not upscale.
dprf64Device pixel ratio (1.0–10.0). Multiplies size to produce actual output dimension.
resize_algorithmstringResize algorithm override: lanczos3, thumbnail, auto

Request Headers

HeaderDescription
AcceptBrowser format preferences. Used for automatic format selection when no format parameter is set.
Sec-CH-DPRClient hint for device pixel ratio. Overridden by the dpr query parameter if both are present.

Response Headers

HeaderValue
Content-Typeimage/{format} matching the output format
Cache-Controlpublic, max-age=31536000, no-transform (customizable)
VaryAccept, Sec-CH-DPR
X-Image-Proxy-CacheHIT or MISS (when caching is enabled; header name configurable via IMAGE_PROXY_CACHE_STATUS_HEADER)

Status Codes

CodeMeaning
200Image served successfully
404File not found (and no fallback URL configured)
415Unsupported input/output format or missing file extension
502Fallback image fetch failed
500Internal processing error

Examples

# Serve original file (no transformation, raw bytes streamed)
curl http://localhost:8000/photo.jpg

# Convert to WebP
curl http://localhost:8000/photo.jpg?format=webp

# Resize to fit within 400x400 bounding box
curl http://localhost:8000/photo.jpg?size=400

# Resize + convert + 2x DPR (actual output: 800px)
curl http://localhost:8000/photo.jpg?size=400&format=avif&dpr=2

# Override resize algorithm
curl http://localhost:8000/photo.jpg?size=400&resize_algorithm=lanczos3

# Use Sec-CH-DPR header instead of query param
curl -H "Sec-CH-DPR: 2.0" http://localhost:8000/photo.jpg?size=400

Behavior

  • No transformation parameters — The raw file is streamed directly without decoding or re-encoding.
  • With transformations — The image is decoded, processed through the pipeline (resize → encode), and the result is cached if caching is enabled.
  • File not found + fallback URL — The image is fetched from the configured IMAGE_PROXY_FALLBACK_IMAGE_URL, transformed, and served. The response size is capped by IMAGE_PROXY_FALLBACK_IMAGE_MAX_SIZE.
  • File not found + no fallback — Returns 404 Not Found.

Metrics Endpoint

GET /metrics

Returns Prometheus metrics in text exposition format.

Response:

  • Status: 200 OK
  • Content-Type: text/plain; version=0.0.4; charset=utf-8

See Metrics for details on available metrics.

On this page