# How to send base64 images to Assistant API?

**URL:** <https://community.openai.com/t/how-to-send-base64-images-to-assistant-api/752440>\
**Category:** API\
**Tags:** gpt-4, chat-with-images, assistants-api, gpt-4o\
**Created:** [May 15, 2024, 8:45am UTC](https://community.openai.com/t/how-to-send-base64-images-to-assistant-api/752440 "2024-05-15T08:45:39Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![henning\_cf](https://sea2.discourse-cdn.com/openai1/user_avatar/community.openai.com/henning_cf/32/148756_2.png) [@henning\_cf](https://community.openai.com/u/henning_cf)\
**Post date:** [May 16, 2024, 7:25am UTC](https://community.openai.com/t/how-to-send-base64-images-to-assistant-api/752440/6 "2024-05-16T07:25:12Z")

</div>

One way to send images to the Chat API is via encoding it to base64 and creating a conversation turn as shown below, with the field `{"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{base64_image}"}}`.

> [@henning\_cf](#):
>
> ```auto
> image_bytes = io.BytesIO()
> image.save(image_bytes, format=format)
> base64_image = base64.b64encode(image_bytes.getvalue()).decode(
> "utf-8")
> 
> prompt_turns: list[dict[str, str]] = []
> [...]
> turn = {
> "role": "user",
> "content": [
> {"type": "text", "text": instruction},
> {
> "type": "image_url",
> "image_url": {
> "url": f"data:image/jpeg;base64,{base64_image}",
> "detail": "low"
> },
> },
> ],
> prompt_turns.append(turn)
> 
> ```

However, that doesn’t seem to work for the Assistant API.

Based on your previous comment (not the reference to the API docs), I would assume that file upload is the way for using images in the Assistant API like this

```auto
oai_file = oai_client.files.create(file=open(image_path, "rb"), purpose="vision")
turn = {
                "role": "user",
                "content": [
                    {"type": "text", "text": prompt.instruction},
                    {"type": "image_file", "image_file": {"file_id": oai_file.id}},
                ],
            }

```

---

_[View the full topic](https://community.openai.com/t/how-to-send-base64-images-to-assistant-api/752440)._
