Access OpenAI's latest image generation model through the TokenHub unified API. Fully OpenAI-compatible, with synchronous response (no polling required), multiple sizes up to 4K, quality levels, and PNG/JPEG/WebP output formats. Supports both text-to-image (t2i) and image-to-image editing (i2i, multi-image composition & inpainting). This guide walks you through the complete integration.
th-xxxxxxxxxxxx...)https://tokenhub.store/api/v1All requests require an API Key in the header:
Authorization: Bearer th-your-api-keyPOST/images/generationsText-to-image. Generate images from a text prompt.
POST/images/editsImage-to-image editing. Supports single-image edits, multi-image composition, and optional inpainting with a mask.
| Tier | Price | Resolution range |
|---|---|---|
| 1K | $0.125 / image | Longest side ≤ 1536 px (e.g. 1024×1024, 1024×1536) |
| 2K | $0.250 / image | Longest side ≤ 2048 px (e.g. 2048×2048) |
| 4K | $0.500 / image | Longest side > 2048 px (e.g. 4096×4096) |
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| model | string | Required | — | Model ID. Use "openai/gpt-image-2" (or short form "gpt-image-2"). |
| prompt | string | Required | — | Text prompt describing the image to generate. |
| n | integer | Optional | 1 | Number of images to generate (1–10). |
| size | string | Optional | 1024x1024 | Output dimensions. Options: 1024x1024, 1536x1024, 1024x1536, 2048x2048, 2048x1152, 3840x2160, 2160x3840, auto. |
| quality | string | Optional | auto | Generation quality. Options: auto, low, medium, high. Higher quality consumes more tokens. |
| format | string | Optional | png | Output image format. Options: png, jpeg, webp. |
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| image | file / string | array | Required | — | Input image(s) to edit. Accepts file(s) via multipart, or URL / base64 data URI in JSON. Provide multiple to compose them into one output. |
| mask | file / string | Optional | — | Optional inpainting mask. Transparent areas will be regenerated; opaque areas are preserved. |
| input_fidelity | string | Optional | low | How closely to preserve the input. Options: low, high. Use high to keep identity/layout; use low for bolder transformations. |
| output_format | string | Optional | png | Alias of 'format' for the edit endpoint. Options: png, jpeg, webp. |
| output_compression | integer | Optional | 100 | Compression level 0–100 (only for jpeg / webp). |
curl -X POST https://tokenhub.store/api/v1/images/generations \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-image-2",
"prompt": "A serene Japanese garden at sunset, koi pond reflections, cherry blossoms, soft cinematic lighting, ultra-detailed"
}'Response:
{
"created": 1740000000,
"data": [
{
"url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
}
]
}# pip install openai
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://tokenhub.store/api/v1",
)
result = client.images.generate(
model="openai/gpt-image-2",
prompt="A majestic dragon flying over snowy mountains at dawn, epic fantasy art, ultra-detailed",
n=1,
size="1536x1024",
quality="high",
)
image_url = result.data[0].url
print("Image URL:", image_url[:80], "...")// npm install openai
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "YOUR_API_KEY",
baseURL: "https://tokenhub.store/api/v1",
});
const result = await client.images.generate({
model: "openai/gpt-image-2",
prompt: "A majestic dragon flying over snowy mountains at dawn, epic fantasy art, ultra-detailed",
n: 1,
size: "1536x1024",
quality: "high",
});
console.log("Image URL:", result.data[0].url.slice(0, 80), "...");Sign up for TokenHub and start using the GPT-Image-2 API now
© 2026 TokenHub · support@tokenhub.store