Image Generation

View as Markdown

Image Generation

Mesh API exposes a standalone OpenAI-compatible image generation endpoint at POST /v1/images/generations, supporting models from OpenAI (gpt-image-*) and Vertex AI (Imagen).

Images can also be generated through POST /v1/chat/completions by setting the image modality on a chat request. The standalone /v1/images/generations endpoint below is the OpenAI-compatible path.

Endpoint

POST /v1/images/generations

Parameters

FieldTypeDescription
promptstringText description of the image. Required.
modelstringModel ID (e.g., openai/gpt-image-1, vertex/imagen-3). Required.
nintegerNumber of images to generate (1–10). Default: 1.
sizestringDimensions or aspect ratio (e.g., 1024x1024, 1792x1024). Default: auto.
qualitystringRendering quality: low, medium, high (GPT image) or hd, standard (DALL·E), or auto. Default: auto.
output_formatstringEncoding for the returned image: png, jpeg, or webp. OpenAI only.
response_formatstringurl or b64_json.
backgroundstringtransparent, opaque, or auto.
moderationstringModeration level: low or auto.
output_compressionintegerCompression level 0–100 (for jpeg/webp).
partial_imagesintegerNumber of partial images to stream, 0–3.
streambooleanEnable SSE keep-alive / native streaming. Default: false.

Streaming

Setting stream: true returns a text/event-stream response that prevents the connection from closing during long-running generations.

The stream always ends with data: [DONE].

Keep-alive chunk sequence

data: {"id":"img-...","object":"image.chunk","created":...,"model":"...","data":[],"status":"processing"}
: ping
: ping
data: {"id":"...","object":"image.chunk","created":...,"data":[{"url":"..."}]}
data: [DONE]

Response

1{
2 "created": 1715356800,
3 "data": [
4 {
5 "url": "https://...",
6 "revised_prompt": "..."
7 }
8 ],
9 "background": "opaque",
10 "output_format": "webp",
11 "quality": "high",
12 "size": "1024x1024",
13 "usage": {
14 "prompt_tokens": 100,
15 "completion_tokens": 1000,
16 "total_tokens": 1100
17 }
18}

background, output_format, quality, size, and usage are only present when the upstream provider returns them. Vertex AI (Imagen) does not return token usage. Vertex AI always returns b64_json regardless of response_format.

Examples

Standard generation

$curl -X POST https://api.meshapi.ai/v1/images/generations \
> -H "Authorization: Bearer YOUR_MESH_API_KEY" \
> -H "Content-Type: application/json" \
> -d '{
> "model": "openai/gpt-image-1",
> "prompt": "A watercolor of a fox in a snowy forest",
> "n": 1,
> "size": "1024x1024",
> "quality": "high",
> "output_format": "webp"
> }'

Streaming

$curl -X POST https://api.meshapi.ai/v1/images/generations \
> -H "Authorization: Bearer YOUR_MESH_API_KEY" \
> -H "Content-Type: application/json" \
> -d '{
> "model": "openai/gpt-image-1",
> "prompt": "A watercolor of a fox in a snowy forest",
> "stream": true
> }'

Image editing

POST /v1/images/edits

Edit or transform an existing image. This is a multipart/form-data request — send the source image file plus the fields below. The operation determines the transform:

operationDescription
editPrompt-guided edit of the input image.
remove_backgroundRemove the image background.
upscaleIncrease resolution.
outpaintExtend the image beyond its original borders.
inpaintFill a masked region (supply a mask).
mixBlend multiple reference images.
reframeRecompose to a new aspect ratio.

Common form fields: image (the source file), prompt, model, operation, mask, and reference_images. If the selected model does not support the requested operation, the endpoint returns 501 Not Implemented.