---
title: "Generate images"
method: POST
path: "/api/experimental/generate/image"
tags: ["generate"]
---

# Generate images

`POST /api/experimental/generate/image`

## Request

- Base URL: `https://opencode.ai` (the document declares no server; this is the origin it was published from)
- URL: `https://opencode.ai/api/experimental/generate/image`
- Auth: none required

Generate or edit images with an image model using the server's base configuration and return them as base64. Stateless: nothing is stored.

## Request body

- GenerateImageRequest
  - `model` ModelRef, required
    - `id` string, required
    - `providerID` string, required
    - `variant` string
  - `prompt` string, required
  - `images` GenerateFile[]
    - `data` string, required
    - `mime` string, required
    - `name` string
  - `n` integer
  - `aspect` string: Aspect ratio as width:height, for example 16:9
  - `resolution` union: Size tier such as 1K, 2K or 4K; 1K is about as many pixels as 1024x1024 at the requested aspect
    - '1K' | '2K' | '4K'
    - string

## Response `200`

GenerateImageResponse

- GenerateImageResponse
  - `data` GenerateImageResult, required
    - `images` GenerateImageOutput[], required
      - `type` 'image', required
      - `data` string, required
      - `mime` string, required
      - `name` string
    - `cost` number
    - `tokens` GenerateUsage: Token counts, when the provider reports them
      - `input` number
      - `output` number
    - `native` GenerateNative: Provider-specific data the shared fields do not cover

## Other responses

- `400`: InvalidRequestError
- `401`: UnauthorizedError
- `404`: ProviderNotFoundError | ModelNotFoundError | LocationNotFoundError
- `422`: UnsupportedModelError
- `502`: ProviderRequestError
- `503`: ServiceUnavailableError

## Changes

> 50 revisions in range; 1 not diffed.

- **2026-10-27** `d6d739fceba2`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/kaaass/apis/opencode/changes/api/experimental/generate/image/post.md)

---

[API](https://skmtc.dev/kaaass/apis/opencode.md) - [All operations](https://skmtc.dev/kaaass/apis/opencode/llms.txt) - [OpenAPI document](https://skmtc.dev/kaaass/apis/opencode/revisions/4e083d954707?raw)
