> ## Documentation Index
> Fetch the complete documentation index at: https://docs.boson.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Image input

> Send images on user messages, or stream the frames of a camera or a screen, so the model can answer questions about what they show.

A user message can carry images next to its text. The model sees them with the rest of the conversation, so the user can ask about a photo, a screenshot, or a document, by text or by voice.

`higgs-realtime-1.5` accepts images. `higgs-realtime` does not: an image sent to it is rejected with an `error` (`code: "image_input_not_supported"`).

## Send an image

Add the image as an `input_image` part of a `user` message in [`conversation.item.create`](https://docs.boson.ai/api-reference/realtime/client-events#conversation-item-create). `image_url` is the image as a base64 data URL:

```json theme={null}
{
  "type": "conversation.item.create",
  "item": {
    "type": "message",
    "role": "user",
    "content": [
      {"type": "input_image", "image_url": "data:image/jpeg;base64,..."},
      {"type": "input_text", "text": "What is the total on this receipt?"}
    ]
  }
}
```

Adding an item does not start a response. Either send `response.create`, or add the image alone and let the user ask about it out loud: with turn detection on, the reply to their next spoken turn sees the image.

This script sends an image file with a question and prints the reply. It needs Python 3.10 or later and the `websockets` package:

```python theme={null}
import asyncio
import base64
import json
import os
import sys
import websockets

async def ask_about_image(path, question):
    with open(path, "rb") as f:
        image_url = "data:image/jpeg;base64," + base64.b64encode(f.read()).decode()

    async with websockets.connect(
        "wss://api.boson.ai/v1/realtime",
        additional_headers={"Authorization": f"Bearer {os.environ['BOSON_API_KEY']}"},
        max_size=None,
    ) as ws:
        await ws.send(json.dumps({
            "type": "session.update",
            "session": {
                "model": "higgs-realtime-1.5",
                "output_modalities": ["text"]
            }
        }))

        # The image and the question, in one user message
        await ws.send(json.dumps({
            "type": "conversation.item.create",
            "item": {"type": "message", "role": "user",
                     "content": [{"type": "input_image", "image_url": image_url},
                                 {"type": "input_text", "text": question}]}
        }))
        await ws.send(json.dumps({"type": "response.create"}))

        async for msg in ws:
            event = json.loads(msg)
            if event["type"] == "response.output_text.done":
                print("Assistant:", event["text"])
            elif event["type"] == "error":
                print("Error:", event["error"])
            elif event["type"] == "response.done":
                break

asyncio.run(ask_about_image(sys.argv[1], sys.argv[2]))
```

```bash theme={null}
python ask_about_image.py receipt.jpg "What is the total on this receipt?"
```

The script asks for a text reply to keep it short. Leave `output_modalities` out and the reply is spoken, as in the [quickstart](https://docs.boson.ai/models/higgs-realtime/quickstart.md#hear-a-reply-in-python).

## Formats and limits

| | |
| - | - |
| Format | JPEG, PNG, or WebP, as a base64 data URL. The image bytes decide the format, so the MIME type in the URL does not have to match. A web URL is not accepted. |
| Size | At most 20 MB (the decoded image, not its base64 text) and 50 megapixels per image. |
| Resolution | The model looks at about one megapixel. A larger image is resized to that when its item is created, so sending more pixels adds upload time and nothing else. |
| Images per response | A response sees the 8 most recent images of the conversation, or the 32 most recent when you [stream video frames](#stream-video-frames). Older ones stay in the conversation but are no longer sent to the model; the text of their messages still is. |
| Message size | A single WebSocket message may be at most 32 MB. A larger one closes the connection with code `1009`. |

An image over a megapixel adds nothing the model can use. Downscale camera photos and screenshots on the client before you send them: the upload is faster, and on a phone connection the difference is seconds.

## Stream video frames

To let the model watch a camera or a screen, send its frames as images and set `image.input.mode` to `"video"` in `session.update`:

```json theme={null}
{
  "type": "session.update",
  "session": {
    "model": "higgs-realtime-1.5",
    "image": { "input": { "mode": "video" } }
  }
}
```

Then send each frame as its own `conversation.item.create`, with one `input_image` part and no text, in the order the frames were captured. The events are the ones you use for a single picture: the mode changes how the server hands the images to the model, not what you send.

| `image.input.mode` | Use it for | Images a response sees |
| - | - | - |
| `"image"` (default) | Single pictures whose detail matters: a photo, a screenshot, a document. | The 8 most recent |
| `"video"` | Consecutive frames of a camera or a screen. | The 32 most recent |

* **Turn it on to stream video.** Without it every frame is taken as a full picture. That fills the conversation's context quickly, and a response sees only the 8 most recent frames.
* **A frame takes much less context than a picture.** That is why a response can see four times as many. In return the model gets less detail from each frame, so small text may be lost: keep `"image"` when one picture has to be read closely.
* **Send at most one frame per second.** A response sees the 32 most recent frames, so at one frame per second that is about the last half minute. Sending faster shortens what the model can look back on.
* **Send frames at one size.** The model takes consecutive frames of the same size together. Frames of different sizes are still accepted.
* **The mode covers the whole session.** It applies to every image in the conversation, the ones sent before you set it included. You can change it in any `session.update`, and the change applies from the next response. `"image": null` restores the default.
* **The ack reports it.** `session.created` and `session.updated` carry the mode in force as `session.image.input.mode`, the default included.
* **`higgs-realtime` takes no images.** Its `session.created` carries no `image`, and setting a mode on it, `"image"` included, fails the `session.update`. Any value other than `"image"` or `"video"` fails it too.

## Events and errors

`conversation.item.added` and `conversation.item.done` carry the image part without its data (`"image_url": null`), so the image is not sent back to you. [`conversation.item.retrieve`](https://docs.boson.ai/api-reference/realtime/client-events#conversation-item-retrieve) returns it as the server holds it, which for a resized image is the resized JPEG.

An image that cannot be used is not added to the conversation. The server answers with an `error` of `type: "invalid_request_error"` and the session stays open:

| `code` | When |
| - | - |
| `image_input_not_supported` | The session's model does not accept images, or the session has not been configured yet. |
| `invalid_value` | `image_url` is not a base64 data URL, or its data is not a readable image. |
| `image_format_not_supported` | The image is not JPEG, PNG, or WebP. |
| `image_size_limit_exceeded` | The image is over 20 MB or over 50 megapixels. |

See [`conversation.item.create`](https://docs.boson.ai/api-reference/realtime/client-events#image-input) in the API reference for the field list.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.