Zum Inhalt springen

Lektion 15 · Images, Audio and Realtime

Images and Files as Input

Send images and PDF files to the OpenAI API with input_image and input_file, choose URLs, uploads or Base64, set detail and verify extracted facts.

Models in the Responses API can read more than text. You can send a photo of a damaged parcel, a screenshot of an error, or a PDF contract, and ask questions about it. Instead of a plain string, the message content becomes a list of parts, one for text and one for each image or file.

You will learn the request shapes, the three ways to supply data, the main limits, and how to check what the model says it saw.

Send an image

Python
# Read-only: the URL is a placeholder
response = client.responses.create(
    model="gpt-6.2-sol",
    input=[{
        "role": "user",
        "content": [
            {"type": "input_text", "text": "What is damaged in this photo?"},
            {"type": "input_image",
             "image_url": "https://example.com/parcel.jpg",
             "detail": "auto"},
        ],
    }],
)
print(response.output_text)

You can supply an image in three ways:

Method Field Good for
Public URL image_url Images already online
Base64 data URL image_url with data:image/...;base64, Local files
Uploaded file file_id Reusing an image; upload with purpose vision

Supported types include PNG, JPEG, WEBP and non-animated GIF. A request has limits on total size, number of images and image dimensions, so check the images guide if you send large batches.

Only use public URLs for content that may be public. A "secret" link to a private photo is not access control.

Build a data URL from a file

This runnable helper builds the data URL you would send. It checks the file's first bytes instead of trusting its name, and it applies a size limit that you choose.

Python Build a safe image data URL

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

A signature check is only a first filter. It does not prove that a file is safe or valid.

The detail setting

detail controls how much visual information the model processes. Values include low, high, original and auto (the default), and supported values depend on the model.

  • Use low when you only need a rough idea, such as "is this a receipt?"
  • Use higher detail for small text or fine features.
  • Test it: higher detail can use more tokens, and low is not always cheaper than high on every model.

Images count toward input tokens, so many large images can cost more than a long text.

Send a PDF or document

A file part has the type input_file.

Python
# Read-only
uploaded = client.files.create(
    file=open("contract.pdf", "rb"), purpose="user_data"
)

response = client.responses.create(
    model="gpt-6.2-sol",
    input=[{"role": "user", "content": [
        {"type": "input_file", "file_id": uploaded.id},
        {"type": "input_text", "text": "List the dates mentioned, with page numbers."},
    ]}],
)

Instead of file_id, you can use file_url, or file_data with a Base64 data URL and a filename. As of December 2026, each file must be under 50 MB, and all files in one request share a 50 MB total.

How a file is read depends on its type:

  • For PDFs, the API uses extracted text and also page images, for models that accept images. Page images add tokens. A detail setting affects page processing.
  • For other documents, you get extracted text only. Images and charts inside them are not included. Convert to PDF if you need them.
  • Spreadsheets are only partly read: the guide says up to the first 1,000 rows of each sheet. For real data analysis, use code on the full data.

For a large collection of documents, do not send everything in each request. Use retrieval.

Combine with structured outputs

For receipts and forms, ask for structured output and then validate it. Allow null for unreadable values. Check totals in code.

Know the limits of vision

Models can misread small or blurry text, confuse similar digits, miscount objects, or miss details in rotated and crowded images. They can also describe something that is not there. Good habits are:

  1. Ask the model to say when something is unreadable.
  2. Keep the original image next to the result for reviewers.
  3. Verify important numbers with a second method or a person.
  4. Test on your real kinds of images: poor light, phone photos, many languages.

Privacy

Photos and documents often contain more than you need: faces, addresses, ID numbers, location data in file metadata. Crop or redact before sending when you can. Do not use image analysis to identify people or to infer sensitive traits. Read OpenAI's usage policies and the laws that apply to you.

Text inside an image or PDF can contain instructions such as "ignore your rules." Treat everything in uploaded content as data, not as commands.

Ask precise questions

Vague questions give vague answers. Instead of "what is in this image?", say what you need: "Read the total amount and the date on this receipt. If either is unclear, say so." Tell the model what the image is meant to be, and what to do if it is something else, such as a photo of a cat instead of a receipt.

When you send several images, refer to them clearly, for example "the first photo shows the item before shipping." For a long PDF, ask about specific sections and request page numbers, then check those pages. For comparisons between two documents, ask for a table of differences and verify each important row against the originals.

Resize very large images before upload when detail is not needed. It saves bandwidth and can save tokens. Do not shrink so much that small text becomes unreadable, and test the smallest size that still works.

Finally, set limits in your own app: allowed file types, maximum size and page count, and how many uploads a user may make each day.

Delete uploaded files when you no longer need them.

Check your understanding

Quick check · 4 questions

of 4 answered You scored / 4 · perfect!

  1. 1. Which content part type sends an image in the Responses API?

    An input_image part takes an image_url or a file_id.
  2. 2. What do you get from a non-PDF document such as a word processor file?

    Convert to PDF if the visual content matters.
  3. 3. What does a file signature check prove?

    It is a basic filter. It does not prove safety or correctness.
  4. 4. How should you treat text written inside an uploaded image?

    Uploaded content can try to steer the model, so it must not be treated as your instructions.

Summary

  • Content becomes a list of parts such as input_text, input_image and input_file.
  • Supply images by URL, data URL or file ID.
  • Detail and page images affect token use.
  • Check file rules and limits, and validate important facts.
  • Minimize personal data and treat file content as untrusted.

Next: Image Generation and Editing

Dein Fortschritt wird in diesem Browser gespeichert. Kein Konto nötig.