Skip to main content
This guide covers image input with text output, not image generation. Select a model supporting both image input and Chat Completions. A model ID in the list alone does not establish vision support.

Two image sources

  • HTTPS image URL: use an image address directly accessible to the gateway or upstream. Browser access does not prove server access; login cookies, temporary authorization, or redirects may cause failures.
  • Base64 data URL: read a local image and encode it with its actual MIME type, such as data:image/png;base64,.... Public image hosting is unnecessary, but the request body grows.
Do not use a local path or file:// as a remote image URL. Remote access, formats, dimensions, and image counts depend on the deployment and model.

Runnable example: send a local image

Follow the Python SDK guide, then set one additional environment variable:
Replace the path with an image you are authorized to submit. Save as vision.py and run python vision.py. The command sends the image to the configured API service, which may forward it upstream. This example accepts PNG/JPEG up to 5 MiB; that is an example-specific limit, not a gateway or model allowance.
The example identifies MIME from the file header; it does not validate full image decodability. Services can additionally limit pixels, encoding, and total request size. Base64 payloads are larger than the original file. Avoid logging complete data URLs.

Protocol field differences

Switching to Responses also requires changing the input structure. Optional fields such as detail require model support; validate a request without extra options first.

Python: vision with Responses

Save as responses-vision.py, use the Python environment and API_IMAGE_PATH from above, and run python responses-vision.py. This submits the image to your configured service; choose a model and channel supporting Responses image input. The example keeps the same local 5 MiB file limit, uses input_text and input_image, and does not require a separate Files API upload.
As in the Chat example, a file signature check is not full image decoding. The response must be complete with nonempty text; refusals, incomplete messages, and tool items are not published as image descriptions.

Troubleshooting

HTTP integration · Errors and retries Reference: OpenAI image inputs. For generating or editing images, see image generation. 简体中文