optimize_for_vision
Resize an image for a vision model
Resize an image to the largest size a given vision model still benefits from, and report what it costs that model in tokens before and after. Every provider downscales oversized input before counting tokens, so this alone saves bytes and upload latency rather than tokens. Pass max_tokens to trade resolution for tokens: that lever is continuous on Claude, unavailable on OpenAI (cost follows the aspect ratio alone), and on Gemini reaches only a flat 258. An image already within budget is returned untouched and free (X-Pig-Billed: 0).
Responses:
200: Processed image binary (Success Response) Content-Type: application/json Content-Type: image/jpeg
Example Response:
"string"Content-Type: image/png
Example Response:
"string"Content-Type: image/webp
Example Response:
"string"Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| q | No | Quality (1-100). Maps to libvips Q parameter. | |
| format | No | Output format: jpeg, png, webp, tiff, gif, or avif. If omitted, the original format is preserved. | |
| source | Yes | Image source: a public URL (https://...) or a base64-encoded string (optionally as a data URI like data:image/png;base64,...). | |
| delivery | No | ||
| max_tokens | No | Optional cap on what the image may cost the target model. Without it the image is resized to the model's own ceiling, which saves bytes and upload latency but no tokens, because every provider already downscales oversized input before counting. Set a budget to trade resolution for tokens. The response reports the cost actually achieved: on OpenAI it cannot be lowered by resizing at all, and on Gemini only down to a flat 258. | |
| target_model | Yes | Vision model the image is being prepared for, e.g. claude-opus-5, gpt-4o, gemini-2.5-pro. Unknown ids are rejected rather than guessed: the wrong limits would silently resize to the wrong size. |