How to Generate Images from Text Prompts

Validated on 27 Apr 2026 • Last edited on 27 Apr 2026

Inference provides a single control plane for managing inference workflows. It includes a Model Catalog where you can view available foundation models, including both DigitalOcean-hosted and third-party commercial models, compare model capabilities and pricing, use routing to match inference requests to the best-fit model, and run inference using serverless or dedicated deployments.

The following cURL, Python OpenAI, Gradient Python SDK, and PyDo examples show how to generate an image from a text prompt. Include your model access key and the following in your request:

  • model: The model ID of the image generation model you want to use. Get the model ID using /v1/models or on the available models page.

  • prompt: The text prompt to generate the image from.

  • n: The number of images to generate. Must be between 1 and 10.

  • size: The desired dimensions of the generated image. Supported values are 256x256, 512x512, and 1024x1024.

Make sure to always specify n and size when generating images.

Send a POST request to the /v1/images/generations endpoint using your model access key.

The following example request sends a prompt to the openai-gpt-image-1 model to generate an image of a baby sea otter floating on its back in calm blue water, with an image size of 1024x1024:

curl -X POST https://inference.do-ai.run/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $MODEL_ACCESS_KEY" \
  -d '{
    "model": "openai-gpt-image-1",
    "prompt": "A cute baby sea otter floating on its back in calm blue water",
    "n": 1,
    "size": "1024x1024"
  }'

The response includes a JSON object with a Base64 image string and other details such as image format and tokens used:

{
    "background": "opaque",
    "created": 1770659857,
    "data": [
        {
            "b64_json": "iVBORw0KGgoAAAANSUhEU...
        }
    ],
    "output_format": "png",
    "quality": "medium",
    "size": "1024x1024",
    "usage": {
        "input_tokens": 20,
        "input_tokens_details": {
            "text_tokens": 20
        },
        "output_tokens": 1056,
        "total_tokens": 1076
    }
}

If you want to save the image as a file, pipe the image string to a file using jq and base64:

curl -X POST https://inference.do-ai.run/v1/images/generations \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $MODEL_ACCESS_KEY" \
  -d '{
    "model": "openai-gpt-image-1",
    "prompt": "A cute baby sea otter floating on its back in calm blue water",
    "n": 1,
    "size": "1024x1024"
  }' | jq -r '.data[0].b64_json' | base64 --decode > sea_otter.png

An image named sea_otter.png is created in your current directory after a few seconds.

from openai import OpenAI
from dotenv import load_dotenv
import os, base64

load_dotenv()

client = OpenAI(
    base_url="https://inference.do-ai.run/v1/",
    api_key=os.getenv("MODEL_ACCESS_KEY"),
)

result = client.images.generate(
    model="openai-gpt-image-1",
    prompt="A cute baby sea otter, children’s book drawing style",
    size="1024x1024",
    n=1
)

b64 = result.data[0].b64_json
with open("sea_otter.png", "wb") as f:
    f.write(base64.b64decode(b64))

print("Saved sea_otter.png")
from gradient import Gradient
from dotenv import load_dotenv
import os, base64

load_dotenv()

client = Gradient(model_access_key=os.getenv("MODEL_ACCESS_KEY"))

result = client.images.generations.create(
    model="openai-gpt-image-1",
    prompt="A cute baby sea otter, children's book drawing style",
    size="1024x1024",
    n=1
)

b64 = result.data[0].b64_json
with open("sea_otter.png", "wb") as f:
    f.write(base64.b64decode(b64))

print("Saved sea_otter.png")
from pydo import Client
from dotenv import load_dotenv
import os, base64

load_dotenv()

client = Client(token=os.getenv("MODEL_ACCESS_KEY"))

result = client.inference.create_image(
    body={
        "model": "openai-gpt-image-1",
        "prompt": "A cute baby sea otter, children's book drawing style",
        "size": "1024x1024",
        "n": 1,
    }
)

b64 = result["data"][0]["b64_json"]
with open("sea_otter.png", "wb") as f:
    f.write(base64.b64decode(b64))

print("Saved sea_otter.png")

We can't find any results for your search.

Try using different keywords or simplifying your search terms.