Перейти к содержимому
Документация:Task API

API

Task API

Create image, video and music generations as tasks, follow them to a final status, and understand what each one costs.

Эта страница пока не переведена. Показана английская версия.

A task is one generation request: an image, a video or a song. Generation takes from seconds to minutes, so the API is asynchronous. You create a task, get it back at once with the status queued, and then either poll it or let a webhook tell you when it ends.

Method and pathWhat it does
POST /v1/tasksCreate a task
GET /v1/tasks/{id}Get a task
GET /v1/tasksList tasks, newest first
POST /v1/tasks/{id}/cancelCancel a task that is still queued

Create a task

POST /v1/tasks with a JSON body:

FieldTypeDescription
modelstringrequiredThe model ID, such as google/veo-3.1-fast. See the model reference.
inputobjectrequiredThe model's parameters. Each model has its own; the model reference lists them. Parameters you leave out take the model's defaults.
callback_urlstringoptionalAn https URL that Minu calls once when the task ends. See Webhooks.
metadataobjectoptionalYour own data, for example an order ID. It is returned with the task and in webhooks. At most 4,000 characters of JSON.
curl https://api.minu.ai/v1/tasks \
  -H "Authorization: Bearer $MINU_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: order-8421-video" \
  -d '{
    "model": "google/veo-3.1-fast",
    "input": {
      "prompt": "A slow dolly shot through a bamboo forest in morning fog"
    },
    "callback_url": "https://your-app.example/hooks/minu",
    "metadata": { "order_id": "8421" }
  }'

The response has status 200 and is the task object, with "status": "queued".

The request is checked before anything is reserved: the model must exist and be allowed for your key, input must match the model's parameters, and your available balance must cover the price. A request that fails a check gets an error and creates no task.

Retry safely with Idempotency-Key

A network error can leave you not knowing whether a task was created. Send an Idempotency-Key header with a value that is unique to the request, up to 200 characters, and retry with the same value:

  • The same key with the same body returns the task that was created the first time. It is not run or charged twice.
  • The same key with a different body is refused with 409 idempotency_conflict.

Keys are scoped to your organization. Use a fresh value, such as a UUID or your own order ID, for every new request.

The task object

JSON
{
  "id": "task_1k8r2m4p0a7c9e3g5j6n8q2s",
  "object": "task",
  "model": "google/veo-3.1-fast",
  "status": "succeeded",
  "input": { "prompt": "A slow dolly shot through a bamboo forest in morning fog" },
  "outputs": [
    { "index": 0, "type": "video", "url": "https://…", "mime": "video/mp4", "bytes": 5120733 }
  ],
  "error": null,
  "estimated_cost_usd": "0.250000",
  "cost_usd": "0.250000",
  "metadata": { "order_id": "8421" },
  "created_at": 1796169600,
  "started_at": 1796169602,
  "completed_at": 1796169671
}
FieldTypeDescription
idstringIdentifier of the task, starting with task_.
objectstringAlways "task".
modelstringThe model ID.
statusstringSee Statuses.
inputobjectThe parameters the task runs with: yours, plus the model's defaults for the ones you left out.
outputsarrayThe results that were delivered. Empty until the task ends. See Outputs.
errorobject or nullcode and message when the task did not succeed. See task errors.
estimated_cost_usdstringThe amount reserved from your balance when the task was created.
cost_usdstring or nullThe amount charged. null while the task is in progress.
metadataobject or nullWhat you sent in metadata.
created_atintegerWhen the task was created, in Unix seconds.
started_atinteger or nullWhen generation started.
completed_atinteger or nullWhen the task reached its final status.

Outputs

Each entry of outputs is one delivered result:

FieldDescription
indexPosition of the result, from 0.
typeimage, video, audio or text.
urlWhere to download the file. null for a text output.
mime, bytesMedia type and size of the file.
textThe text itself, for a text output.

An output can carry more facts about the result beside these, depending on the model, such as a duration, a title or lyrics. Read the fields you know and ignore the rest.

Files are served from Minu's storage and are kept for 14 days by default; an organization's owner or admin can set the retention between 1 and 30 days in the console. Download what you need to keep.

Statuses

StatusFinalMeaning
queuednoAccepted and waiting for a free slot.
runningnoBeing generated.
finalizingnoGenerated; the results are being stored.
succeededyesEvery requested result was delivered.
partially_succeededyesSome of the requested results were delivered. You are charged for those only.
failedyesNo result. Not charged. error says why.
canceledyesCanceled before it started. Not charged.
expiredyesDid not finish in time. Not charged.

Get a task

Shell
curl https://api.minu.ai/v1/tasks/task_1k8r2m4p0a7c9e3g5j6n8q2s \
  -H "Authorization: Bearer $MINU_API_KEY"

Returns the task object, or 404 not_found when no task with that ID belongs to your organization.

When you poll, a request every two to five seconds is plenty. Polling requests count against your rate limit; with many tasks in flight, a webhook is the better tool.

List tasks

Shell
curl "https://api.minu.ai/v1/tasks?limit=20&status=succeeded" \
  -H "Authorization: Bearer $MINU_API_KEY"
Query parameterDescription
limitTasks per page, 1 to 100. Default 20.
beforeThe id of the last task of the previous page. Returns the tasks created before it.
statusOnly tasks with this status.
modelOnly tasks of this model.
JSON
{
  "object": "list",
  "data": [
    { "id": "task_1k8r2m4p0a7c9e3g5j6n8q2s", "object": "task", "status": "succeeded" }
  ],
  "has_more": true
}

Each entry of data is a full task object (shortened here). Tasks come newest first. While has_more is true, pass the last id as before to get the next page.

Cancel a task

Shell
curl -X POST https://api.minu.ai/v1/tasks/task_1k8r2m4p0a7c9e3g5j6n8q2s/cancel \
  -H "Authorization: Bearer $MINU_API_KEY"

Only a task that is still queued can be canceled. It becomes canceled, its reserved amount is released, and nothing is charged. Once a task has started it runs to its end, and the call answers 409 not_cancelable.

How tasks are billed

  1. At creation, the price is reserved. estimated_cost_usd is taken out of your available balance but not yet charged. If the available balance cannot cover it, the request is refused with 402 insufficient_balance and no task is created.
  2. When the task ends, you are charged for what was delivered. cost_usd is the amount charged; anything reserved beyond it is released.

What "delivered" means depends on how the model is priced:

  • Models priced per image, per video or per second charge each delivered result on its own. Ask for four images and receive three, and the task is partially_succeeded with cost_usd at three images.
  • Models priced per request, such as songs, charge the request in full once it delivers a result.

A task that is failed, canceled or expired has cost_usd of "0.000000". There is no refund step, because nothing was charged.

GET /v1/balance shows the effect at any moment:

JSON
{
  "object": "balance",
  "currency": "usd",
  "balance_usd": "49.750000",
  "reserved_usd": "0.250000",
  "available_usd": "49.500000"
}

available_usd is balance_usd less reserved_usd, and is what new requests can spend.

Waiting and time limits

  • Concurrency. Each organization runs a limited number of tasks at once. Further tasks stay queued until a slot is free. The queue is bounded: when it is full, POST /v1/tasks answers 429 queue_full with a Retry-After header.
  • Time limits. Every model has a time limit. A task that does not finish within it becomes expired, with the error code timeout. A task that waits in the queue too long without getting a slot becomes failed, with the error code capacity_timeout. Neither is charged.

If the default limits do not fit your workload, talk to us.