LMU AI Docs
Open API

GPT Image API

Call gpt-image-2 through the LMU AI OpenAI Images-compatible API for text-to-image, image editing, parameters, Base64 saving, model lookup, and error fixes.

LMU AI provides an OpenAI Images-compatible API for text-to-image and image editing / image-to-image using gpt-image-2.

Base URL

OpenAI SDK:

https://api.lmuai.com/v1

When writing HTTP requests by hand, use the full endpoints:

POST https://api.lmuai.com/v1/images/generations
POST https://api.lmuai.com/v1/images/edits

1. API overview

MethodPathContent-TypeDescription
GET/v1/modelsQuery the models available to your current API key
POST/v1/images/generationsapplication/jsonGPT text-to-image, synchronous response
POST/v1/images/editsmultipart/form-dataGPT image editing / image-to-image, synchronous response

No GPT multi-item batch API yet

/v1/images/batches currently supports only Gemini and cannot accept gpt-image-2. To generate multiple GPT images, have the client send requests one at a time and manage concurrency and RPM yourself.

The production environment currently has no async image job endpoint enabled either, so rely on the two synchronous APIs on this page.

2. Authentication

Authorization: Bearer YOUR_API_KEY

Do not put your API key in browser front-end code, public repositories, URL query strings, or logs. We recommend calling from your own server.

3. Query models

curl https://api.lmuai.com/v1/models \
  -H "Authorization: Bearer YOUR_API_KEY"

Look for the image model in the response's data[].id, for example:

{
  "object": "list",
  "data": [
    {"id": "gpt-image-2", "object": "model"}
  ]
}

The model list is determined by the group your API key belongs to. Different API keys on the same site may return different models.

4. Text-to-image

POST /v1/images/generations

curl https://api.lmuai.com/v1/images/generations \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "A red ceramic mug, centered on a light-gray studio background, soft side lighting, no text",
    "n": 1,
    "size": "1024x1024",
    "quality": "low",
    "output_format": "png"
  }'

Python SDK

from openai import OpenAI
import base64

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://api.lmuai.com/v1",
)

result = client.images.generate(
    model="gpt-image-2",
    prompt="A red ceramic mug, light-gray studio background, soft side lighting, no text",
    size="1024x1024",
    quality="low",
)

item = result.data[0]

if item.b64_json:
    with open("gpt-output.png", "wb") as f:
        f.write(base64.b64decode(item.b64_json))
elif item.url:
    print(item.url)
else:
    raise RuntimeError("No valid image in the response")

JavaScript

import OpenAI from "openai";
import fs from "node:fs";

const client = new OpenAI({
  apiKey: process.env.LMU_API_KEY,
  baseURL: "https://api.lmuai.com/v1",
});

const result = await client.images.generate({
  model: "gpt-image-2",
  prompt: "A red ceramic mug, light-gray studio background, soft side lighting, no text",
  size: "1024x1024",
  quality: "low",
  output_format: "png",
});

const item = result.data?.[0];
if (item?.b64_json) {
  fs.writeFileSync("gpt-output.png", Buffer.from(item.b64_json, "base64"));
} else if (item?.url) {
  console.log(item.url);
} else {
  throw new Error("No valid image in the response");
}

5. Text-to-image parameters

FieldTypeRequiredDescription
modelstringRecommendedCurrently gpt-image-2
promptstringYesImage description
nintegerNoNumber of images; the available range is determined by the model and upstream channel
sizestringNoRequested size, e.g. 1024x1024; the actual pixel dimensions follow the returned image
qualitystringNoQuality tier, e.g. low, medium, high; subject to model capabilities
backgroundstringNoBackground setting, e.g. transparent background; subject to model capabilities
output_formatstringNopng, jpeg, webp, etc.; subject to model capabilities
output_compressionintegerNoCompression quality for formats such as JPEG / WebP
response_formatstringNoResponse-format compatibility parameter; clients should still check both b64_json and url
moderationstringNoContent-moderation parameter; subject to model capabilities
streambooleanNoToggle for streaming image responses; for normal server-side calls we recommend non-streaming
partial_imagesintegerNoNumber of partial images in streaming scenarios; subject to model capabilities

size is not a guaranteed crop

Different upstream accounts and image backends may map or normalize size to their capabilities. Even if you request 1024x1024, the actual image pixels may differ. When you need a fixed ratio or pixel size, read the output file dimensions and crop or resize on your side.

6. Image editing / image-to-image

POST /v1/images/edits

GPT image editing uses multipart/form-data:

curl https://api.lmuai.com/v1/images/edits \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "model=gpt-image-2" \
  -F "prompt=Keep the mug's shape, composition, and lighting; change the mug from red to green; no text" \
  -F "image=@./input.png" \
  -F "size=1024x1024" \
  -F "quality=low" \
  -F "output_format=png"

Python SDK:

from openai import OpenAI
import base64

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://api.lmuai.com/v1",
)

with open("input.png", "rb") as image_file:
    result = client.images.edit(
        model="gpt-image-2",
        image=image_file,
        prompt="Keep the subject and composition; change the background to a neon street on a rainy night",
        size="1024x1024",
        quality="low",
    )

item = result.data[0]
if item.b64_json:
    with open("gpt-edited.png", "wb") as f:
        f.write(base64.b64decode(item.b64_json))

If the model and channel support mask editing, you can add:

-F "mask=@./mask.png"

The edits endpoint also accepts parameters such as input_fidelity, background, output_format, and output_compression; the exact effect depends on model capabilities.

7. Response format

A typical GPT image response:

{
  "created": 1760000000,
  "data": [
    {
      "b64_json": "iVBORw0KGgoAAA..."
    }
  ],
  "background": "opaque",
  "output_format": "png",
  "quality": "low",
  "size": "1024x1024",
  "model": "gpt-image-2",
  "usage": {
    "input_tokens": 48,
    "output_tokens": 186,
    "total_tokens": 234
  }
}

Clients should perform three levels of validation:

  1. Whether the HTTP status code is 2xx;
  2. Whether data is a non-empty array;
  3. Whether a non-empty b64_json or url exists in data[].

When you get HTTP 200 but no valid image field, treat it as a business-level failure.

8. Common errors

HTTPCommon causeRecommended action
400Bad request body, image format, parameter, or modelCheck the JSON / multipart, field names, and model ID
401Invalid API keyCheck the Bearer header and do not add spaces around the key
403The group your API key belongs to does not have image generation enabledContact the admin to check the group's image permissions
404Wrong path, or the image API is not supported for the current groupConfirm you are using /v1/images/generations or /v1/images/edits
429Concurrency, RPM, or upstream quota limitsUse exponential backoff and lower concurrency and RPM
5xxThe upstream or API relay is temporarily unavailableLog the request ID and retry a limited number of times

When troubleshooting, save the request ID from the response headers and provide it to the admin; do not send your full API key.

9. Differences from other image APIs

NeedRecommended doc
Gemini native text-to-image, image-to-image, 1K / 2K / 4KGemini Image API
GPT text-to-image and editingThis page
Grok text-to-image and editingGrok Image API
Submit multiple Gemini prompts at onceGemini Batch Image API

Last updated:

On this page