Skip to main content
POST
/
images
/
generations
Create image generation
curl --request POST \
  --url https://dimilinks.com/v1/images/generations \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "prompt": "<string>",
  "model": "gpt-image-2",
  "n": 1,
  "size": "<string>",
  "output_format": "<string>",
  "output_compression": 123,
  "background": "<string>",
  "moderation": "<string>",
  "wait_for_result": true,
  "image_urls": "<string>",
  "mask_url": "<string>",
  "response_format": "<string>",
  "user": "<string>"
}
'
import requests

url = "https://dimilinks.com/v1/images/generations"

payload = {
    "prompt": "<string>",
    "model": "gpt-image-2",
    "n": 1,
    "size": "<string>",
    "output_format": "<string>",
    "output_compression": 123,
    "background": "<string>",
    "moderation": "<string>",
    "wait_for_result": True,
    "image_urls": "<string>",
    "mask_url": "<string>",
    "response_format": "<string>",
    "user": "<string>"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: JSON.stringify({
    prompt: '<string>',
    model: 'gpt-image-2',
    n: 1,
    size: '<string>',
    output_format: '<string>',
    output_compression: 123,
    background: '<string>',
    moderation: '<string>',
    wait_for_result: true,
    image_urls: '<string>',
    mask_url: '<string>',
    response_format: '<string>',
    user: '<string>'
  })
};

fetch('https://dimilinks.com/v1/images/generations', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => "https://dimilinks.com/v1/images/generations",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => json_encode([
    'prompt' => '<string>',
    'model' => 'gpt-image-2',
    'n' => 1,
    'size' => '<string>',
    'output_format' => '<string>',
    'output_compression' => 123,
    'background' => '<string>',
    'moderation' => '<string>',
    'wait_for_result' => true,
    'image_urls' => '<string>',
    'mask_url' => '<string>',
    'response_format' => '<string>',
    'user' => '<string>'
  ]),
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer <token>",
    "Content-Type: application/json"
  ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://dimilinks.com/v1/images/generations"

	payload := strings.NewReader("{\n  \"prompt\": \"<string>\",\n  \"model\": \"gpt-image-2\",\n  \"n\": 1,\n  \"size\": \"<string>\",\n  \"output_format\": \"<string>\",\n  \"output_compression\": 123,\n  \"background\": \"<string>\",\n  \"moderation\": \"<string>\",\n  \"wait_for_result\": true,\n  \"image_urls\": \"<string>\",\n  \"mask_url\": \"<string>\",\n  \"response_format\": \"<string>\",\n  \"user\": \"<string>\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://dimilinks.com/v1/images/generations")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"prompt\": \"<string>\",\n  \"model\": \"gpt-image-2\",\n  \"n\": 1,\n  \"size\": \"<string>\",\n  \"output_format\": \"<string>\",\n  \"output_compression\": 123,\n  \"background\": \"<string>\",\n  \"moderation\": \"<string>\",\n  \"wait_for_result\": true,\n  \"image_urls\": \"<string>\",\n  \"mask_url\": \"<string>\",\n  \"response_format\": \"<string>\",\n  \"user\": \"<string>\"\n}")
  .asString();
require 'uri'
require 'net/http'

url = URI("https://dimilinks.com/v1/images/generations")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"prompt\": \"<string>\",\n  \"model\": \"gpt-image-2\",\n  \"n\": 1,\n  \"size\": \"<string>\",\n  \"output_format\": \"<string>\",\n  \"output_compression\": 123,\n  \"background\": \"<string>\",\n  \"moderation\": \"<string>\",\n  \"wait_for_result\": true,\n  \"image_urls\": \"<string>\",\n  \"mask_url\": \"<string>\",\n  \"response_format\": \"<string>\",\n  \"user\": \"<string>\"\n}"

response = http.request(request)
puts response.read_body
{
  "task_id": "img_xxx",
  "data": [],
  "created": 1777080000
}
{
  "error": {
    "message": "<string>",
    "type": "invalid_request_error",
    "code": "<string>"
  }
}
{
  "error": {
    "message": "<string>",
    "type": "invalid_request_error",
    "code": "<string>"
  }
}
{
  "error": {
    "message": "<string>",
    "type": "invalid_request_error",
    "code": "<string>"
  }
}
{
  "error": {
    "message": "<string>",
    "type": "invalid_request_error",
    "code": "<string>"
  }
}
gpt-image-2 is the DimiLinks image generation model. It supports text-to-image and image-to-image workflows, with up to nine reference images supplied through image_urls.
We recommend adding ?async=true. Synchronous mode waits for image generation to finish before returning and is more likely to be interrupted by a gateway or client timeout.

Request URL

POST https://dimilinks.com/v1/images/generations?async=true
Content-Type: application/json
Authorization: Bearer <DIMILINKS_API_KEY>

Text-to-image example

curl "https://dimilinks.com/v1/images/generations?async=true" \
  -H "Authorization: Bearer $DIMILINKS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "A cyberpunk poster of a cat, neon lighting, cinematic atmosphere",
    "n": 1,
    "size": "16:9",
    "resolution": "2k",
    "output_format": "png"
  }'

Image-to-image example

curl "https://dimilinks.com/v1/images/generations?async=true" \
  -H "Authorization: Bearer $DIMILINKS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2",
    "prompt": "Keep the person consistent and restyle the image as a cinematic beach portrait at sunset",
    "n": 1,
    "size": "16:9",
    "resolution": "4k",
    "image_urls": [
      "https://example.com/reference.png"
    ]
  }'

Asynchronous response

{
  "created": 1777080000,
  "task_id": "img_xxx",
  "data": []
}
After receiving task_id, call Retrieve image task to retrieve the result.

Synchronous response

Synchronous mode returns after the image is ready:
{
  "created": 1777080000,
  "task_id": "img_xxx",
  "data": [
    {
      "url": "/p/img/img_xxx/0?exp=1777166400000&sig=...",
      "file_id": "file_xxx"
    }
  ]
}

Result fields

data[].url is not always a public image URL. Support all three forms:
  • /p/img/...: a relative path. Prefix it with https://dimilinks.com before displaying or downloading it. The path requires no Bearer token because the URL includes a signature and expiration time.
  • https://...: a complete image URL that can be requested or displayed directly.
  • data:image/...;base64,...: a Data URL containing the image itself. A webpage can use it directly as <img src>; a server-side script must decode the base64 before saving it as a file.

Parameters

ParameterTypeDefaultDescription
modelstringgpt-image-2Model name.
promptstringRequiredGeneration or editing prompt.
ninteger1Number of images generated per request. The 1k tier is fixed at 1; 2k and 4k support up to 4.
sizestring1024x1024Aspect ratio such as 1:1 or 16:9, or exact WxH pixels such as 3840x2160.
resolutionstringEmptyResolution tier: 1k / 2k / 4k.
output_formatstringEmptyOutput format: png / jpeg / webp.
output_compressionintegerEmptyOutput compression quality for jpeg or webp.
backgroundstringEmptyBackground preference: auto / transparent / opaque.
moderationstringEmptyContent moderation level: auto / low.
userstringEmptyCaller-side user identifier for auditing.
wait_for_resultbooleantrueSet to false for asynchronous submission.
image_urlsstring | array | objectEmptyJSON reference-image field, with up to nine images.
mask_urlstringEmptyInpainting mask; requires at least one reference image.
response_formatstringEmptySet to b64_json to return base64 directly; not recommended as the default.

Enable asynchronous mode

Any one of the following enables asynchronous mode:
  • Query parameter: ?async=true
  • Query parameter: ?wait_for_result=false
  • Request header: Prefer: respond-async
  • Request body: "wait_for_result": false

Reference-image format

We recommend image_urls:
{
  "image_urls": [
    "https://example.com/ref.png",
    "data:image/png;base64,iVBORw0KGgo..."
  ]
}
The API also accepts reference_images, images, image, image_url, input_image, and input_images.

Reference-image limits

  • A request can include up to nine reference images.
  • Each reference image can be up to 20 MB.
  • HTTP(S) URLs, Data URLs, and raw base64 are supported.
  • Browser blob: URLs cannot be submitted directly. Upload the image to your server or convert it to a Data URL first.

Differences between resolution tiers

TierMaximum n per requestTypical timeDescription
1k1About 60 secondsEntry tier for previews or low-cost batch generation.
2k4About 120 secondsRecommended tier for most production image generation.
4k4About 180 secondsHigh-fidelity tier that also supports some extreme aspect ratios such as 21:9.
See the Pricing page in the console for current prices. Each resolution tier is priced independently.

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Query Parameters

async
boolean

Set to true to submit an async image task.

wait_for_result
boolean

Set to false to submit an async image task.

Body

application/json
prompt
string
required
model
string
default:gpt-image-2
n
integer
default:1

1k resolution allows n=1 only; 2k and 4k allow up to 4.

Required range: 1 <= x <= 4
size
string
Examples:

"1:1"

"16:9"

"3840x2160"

resolution
enum<string>
Available options:
1k,
2k,
4k
output_format
string
Examples:

"png"

"jpeg"

"webp"

output_compression
integer
background
string
Examples:

"auto"

"transparent"

"opaque"

moderation
string
Examples:

"auto"

"low"

wait_for_result
boolean
image_urls
mask_url
string
response_format
string
Example:

"b64_json"

user
string

Response

Image generation result or async submission

task_id
string
required
Example:

"img_xxx"

data
object[]
required
Example:
[]
created
integer
Example:

1777080000