Before you begin

  • An account and a key. Register in the console, then create a key on the API Keys page. Keep it in a server-side secret or environment variable. Never put it in browser or mobile code.
  • Balance. Image requests are charged per image. Top up on the Wallet page if your balance is low.
  • A model ID. This guide uses kling/kling-v3-image-generation. Confirm it, and its current price, in Model Square.
  • Time. The request stays open while the image is generated, often for a minute or more. Give your HTTP client a timeout of at least 5 minutes.

Set your key once in the terminal you will use:

terminal · bash / zsh
export TOKENROC_API_KEY="your-api-key"

Send the request

Image generation uses its own route, not /v1/chat/completions. Send JSON with the model ID and a prompt. Model-specific options go inside a parameters object.

terminal · POST /v1/images/generations
curl https://api.tokenroc.com/v1/images/generations \
  --max-time 300 \
  -H "Authorization: Bearer $TOKENROC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "kling/kling-v3-image-generation",
    "prompt": "A single white ceramic mug on a light oak table, soft morning light, product photo",
    "n": 1,
    "parameters": {
      "resolution": "1k",
      "aspect_ratio": "1:1"
    }
  }'

The same request in Windows PowerShell:

terminal · PowerShell
$env:TOKENROC_API_KEY = "your-api-key"

$body = @{
  model      = "kling/kling-v3-image-generation"
  prompt     = "A single white ceramic mug on a light oak table, soft morning light, product photo"
  n          = 1
  parameters = @{ resolution = "1k"; aspect_ratio = "1:1" }
} | ConvertTo-Json -Depth 3

$response = Invoke-RestMethod -Method Post `
  -Uri "https://api.tokenroc.com/v1/images/generations" `
  -Headers @{ Authorization = "Bearer $env:TOKENROC_API_KEY" } `
  -ContentType "application/json" `
  -Body $body `
  -TimeoutSec 300

if ($response.error) { throw $response.error.message }
$response.data[0].url

Request fields

FieldRequiredAccepted values
modelYeskling/kling-v3-image-generation or kling/kling-v3-omni-image-generation.
promptYesUp to 2,500 characters.
nNoNumber of images, 1 to 9. Defaults to 1.
parameters.resolutionNo1k (default) or 2k. Omni also accepts 4k.
parameters.aspect_ratioNo1:1, 16:9, or 9:16. If omitted, the provider chooses.
image or imagesNoReference image URLs, as one string or an array. Up to 10 per request.

Omni has two more options, described under Choose a model. TokenRoc rejects a field a model does not support instead of ignoring it.

Read the response

There is no task ID to poll. TokenRoc waits for the provider to finish and returns the images in the same response. A successful response looks like this; values are shortened and the signed link is replaced:

response · 200 OKapplication/json
{
  "data": [
    {
      "url": "https://<provider-storage>/<image-file>?<signature>",
      "b64_json": "",
      "revised_prompt": ""
    }
  ],
  "created": 1790000000,
  "metadata": {
    "output": { "task_status": "SUCCEEDED", ... },
    "usage": { "image_count": 1, ... },
    ...
  }
}
  • data[].url is the image. There is one entry per image, in order, so n: 3 returns three entries.
  • created is the Unix time the request started.
  • metadata is the provider's own record of the job. usage.image_count is the number of images you are charged for, and it always equals the number of entries in data. Other fields in metadata come from the provider and can change, so do not build on them.
Save the image right away. The URL is a signed link to the provider's storage, and TokenRoc does not keep a copy. Download it, or copy it to your own storage, as soon as the response arrives. Do not publish the signed link.

To download it with cURL, paste the URL from data[0].url:

terminal · download
curl -L -o mug.png "PASTE_THE_URL_FROM_data[0].url"

Keep the file extension that appears at the end of the URL path, before the ?.

Choose a model

Both models take the same basic request. Start with the standard model unless you need 4K output or a related series of images.

Model IDResolutionImages per requestPrice, 24 Sep 2026
kling/kling-v3-image-generation1K (default) or 2K1 to 9 with n$0.0299 per image
kling/kling-v3-omni-image-generation1K (default), 2K, or 4K1 to 9 with n, or a series of 2 to 9$0.0299 per image at 1K or 2K; 4K is 2x

Omni series mode. Set parameters.result_type to series to get a set of related images from one prompt. Choose how many with parameters.series_amount, from 2 to 9 (default 4). Leave n out in series mode; sending both is rejected.

request body · Omni series
{
  "model": "kling/kling-v3-omni-image-generation",
  "prompt": "A four-panel story of a cat learning to fish",
  "parameters": {
    "result_type": "series",
    "series_amount": 4,
    "resolution": "1k",
    "aspect_ratio": "1:1"
  }
}

Model availability can change. Copy IDs from Model Square, or list the models your key can use with GET /v1/models.

What it costs

You pay for the images you receive:

formulaper request
cost = images returned (usage.image_count) x price per image x resolution factor
  • The resolution factor is 1 for 1K and 2K on both models, and 2 for Omni at 4K.
  • Reference images are not charged.
  • Your balance must cover the request before it starts. If the request fails, nothing is charged for it.
  • Model Square prices are rounded for display, so the amount in your usage log can differ slightly in the last decimal place.

Prices above were checked on 24 September 2026. Model Square always shows the current rate.

Errors and retries

Errors return an error object. The message ends with a request ID, which is the most useful thing to include if you contact support:

error responseapplication/json
{
  "error": {
    "message": "convert image request to ali kling image request failed: kling/kling-v3-image-generation: unsupported resolution \"4k\"; supported values are 1k and 2k (request id: ...)",
    "type": "new_api_error",
    "param": "",
    "code": "convert_request_failed"
  }
}
Check for error before reading data. When the provider reports that a generation failed, the response can carry an error object with type ali_error even though the HTTP status is 200. Decide what to do from error.code, not from the status alone.
What you seeMeaningWhat to do
HTTP 401The key is missing, wrong, or disabled.Check the Authorization: Bearer header and the key's status on the API Keys page.
insufficient_user_quota (403)Your balance does not cover the request.Top up on the Wallet page, then retry.
model_not_found (503)The model ID is wrong or not available to your key.Copy the ID again from Model Square. IDs are exact strings.
invalid_request or convert_request_failedA field is missing or out of range, such as an empty prompt, n above 9, or 4k on the standard model. The message names the field.Fix the request. Sending it again unchanged fails the same way, even when the status is 5xx.
error.type ali_errorThe provider could not generate the image, for example because of its content rules.Read the message, change the prompt or inputs, then retry. Nothing is charged.
bad_response with aliAsyncTaskWait timeoutThe provider did not finish within TokenRoc's wait of about three minutes.Retry once later. Nothing is charged for the failed request.
HTTP 429Too many requests at once.Wait, then retry with exponential backoff.

If your own client times out before TokenRoc responds, you do not receive the images from that request. Raise the client timeout rather than sending many parallel copies. The status page shows whether the TokenRoc gateway is responding. It does not report the health of each individual model.

Check usage

  • Usage Logs list each request with its model and charge. Filter by model to find image requests.
  • The Wallet page shows your balance and top-ups.
  • Model Square shows current per-image prices.

Next steps

  • Try the same prompt on kling/kling-v3-omni-image-generation by changing only model.
  • Create video from a prompt with the video generation guide.
  • Read the API quickstart for text models and the endpoint list.

Stuck? Contact TokenRoc with the model ID, the time of the request, and the request ID from the error message. Never send your API key or a signed image link.