Skip to main content

Using Nano-Banana through Chat Completions API

You can generate images (also known as Nano-Banana) through LLM format by using the gemini-2.5-flash-image-preview model.
If you want to send an image, send the Base64 of the image directly instead of the image URL.

Example

Generate image

curl https://api.mulerun.com/v1/chat/completions  \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <Your API Token>" \
  -d '{
    "model": "gemini-2.5-flash-image-preview",
    "stream": false,
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "text",
            "text": "Create a picture of mule"
          }
        ]
      }
    ]
  }'
You will receive the following response:
{
    "choices": [
        {
            "message": {
                "role": "assistant",
                "content": [
                    {
                        "image_url": {
                            "url": "iVBORw0KGgoAAAAN..."
                        },
                        "type": "image_url"
                    }
                ]
            },
            "index": 0,
            "finish_reason": "STOP"
        }
    ],
    "usage": {
        "audioTokens": null,
        "completion_tokens": 1290,
        "prompt_tokens": 6,
        "total_tokens": 1296,
        "cache_creation_input_tokens": null,
        "cache_read_input_tokens": null
    }
}
In the url field of image_url, you’ll get the Base64 encoded image data.

Generate image with image URL

IMAGE_BASE64=$(base64 < reference.png | tr -d '\n')

curl https://api.mulerun.com/v1/chat/completions  \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <Your API Token>" \
  -d @- <<EOF
{
  "model": "gemini-2.5-flash-image-preview",
  "stream": false,
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "Create a picture of a mule with a similar style"
        },
        {
          "type": "image_url",
          "image_url": {
            "url": "data:image/png;base64,${IMAGE_BASE64}"
          }
        }
      ]
    }
  ]
}
EOF
You will receive the following response:
{
    "choices": [
        {
            "message": {
                "role": "assistant",
                "content": [
                    {
                        "image_url": {
                            "url": "iVBORw0KGgoAAAA..."
                        },
                        "type": "image_url"
                    }
                ]
            },
            "index": 0,
            "finish_reason": "STOP"
        }
    ],
    "usage": {
        "audioTokens": null,
        "completion_tokens": 1290,
        "prompt_tokens": 1301,
        "total_tokens": 2591,
        "cache_creation_input_tokens": null,
        "cache_read_input_tokens": null
    }
}

Generate image with streaming mode

curl https://api.mulerun.com/v1/chat/completions  \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <Your API Token>" \
  -d '{
    "model": "gemini-2.5-flash-image-preview",
    "stream": true,
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "text",
            "text": "Create a picture of mule"
          }
        ]
      }
    ]
  }'
You will receive the following response:
data: {
    "choices": [
        {
            "index": 0,
            "delta": {
                "role": "assistant",
                "content": [
                    {
                        "image_url": {
                            "url": "iVBORw0KGgoAAAANSUhEUgAABAAAAAQACAIA..."
                        },
                        "type": "image_url"
                    }
                ]
            },
            "finish_reason": "STOP"
        }
    ],
    "usage": {
        "completion_tokens": 1290,
        "prompt_tokens": 6,
        "total_tokens": 1296
    }
}

data: {
    "id": "",
    "object": "chat.completion.chunk",
    "created": 0,
    "model": "gemini-2.5-flash-image-preview",
    "system_fingerprint": "",
    "choices": [],
    "usage": {
        "prompt_tokens": 13,
        "completion_tokens": 0,
        "total_tokens": 13,
        "prompt_tokens_details": {
            "cached_tokens": 0,
            "text_tokens": 0,
            "audio_tokens": 0,
            "image_tokens": 0
        },
        "completion_tokens_details": {
            "text_tokens": 0,
            "audio_tokens": 0,
            "reasoning_tokens": 0
        },
        "input_tokens": 0,
        "output_tokens": 0,
        "input_tokens_details": null
    }
}

data: [DONE]
In the url field of image_url, you’ll get the Base64 encoded image data.
I