Tasks

Run apps and manage tasks.


Run Task

POST /run

Run an app. By default the call returns as soon as the task is created (status 1, received, output null). Pass "wait": true to hold the connection until the task finishes, or "stream": true for Server-Sent Events. Without either, poll GET /tasks/:id until status is terminal (10 completed, 11 failed, 12 cancelled).

Request

FieldTypeRequiredDescription
appstringYesApp identifier (namespace/name@version)
inputobjectYesInput data matching app schema
setupobjectNoSetup parameters
functionstringNoFunction to call on a multi-function app
waitbooleanNotrue holds the connection until the task reaches a terminal state and returns the final result. Default false
streambooleanNotrue returns an SSE stream of task updates. Takes precedence over wait. See Streaming
infrastringNo"cloud", "private", or "private_first" (default "cloud" when omitted)
workersstring[]NoPrivate worker IDs to run on. With infra: "private", every ID must be a worker of your workspace
webhookstringNoURL to receive a POST when the task completes
sessionstringNo"new" to start a session, or existing session ID
session_timeoutnumberNoSession idle timeout in seconds (1-3600, only with session: "new")
run_atstringNoRFC 3339 timestamp to schedule the task for later

Example:

json
1{2  "app": "infsh/flux",3  "input": {4    "prompt": "A sunset over mountains"5  },6  "wait": true,7  "setup": {8    "model": "schnell"9  }10}

Response

FieldTypeDescription
idstringTask ID
short_idstringShort task ID
statusnumberStatus code. See Status codes
status_textstringStatus name (received, running, completed, ...)
outputobjectOutput data, null until the task completes. Internal pricing field output_meta is stripped — app authors still set it in app code; see Output metadata.
errorstringError message (if failed)
egressobjectOptional. Bytes the task's sandbox sent and received through the engine's egress gateway (bytes_out, bytes_in). Omitted when the task did not run behind that gateway or the engine has not reported totals yet.
session_idstringSession ID (if using sessions)
run_atstringScheduled time (if run_at was set)
created_atstringISO timestamp
updated_atstringISO timestamp

With wait: true, a failed or cancelled task answers 422 with code task_failed or task_cancelled and the task under meta.task. A cancelled task carries output there when its app returned a result (see Cancel task).

Example (wait: true):

json
1{2  "id": "task_abc123",3  "short_id": "abc123",4  "status": 10,5  "status_text": "completed",6  "output": {7    "image": { "uri": "https://..." }8  },9  "created_at": "2024-01-15T10:30:00Z",10  "updated_at": "2024-01-15T10:30:04Z"11}

Unknown input fields

Most app input schemas leave additionalProperties unset, so validation accepts top-level keys the function does not declare, and the app ignores them: page_size sent to a function that takes max_results runs with the default page size.

The task still runs. When input has top-level keys the function's schema does not declare, and the schema does not allow extra keys (additionalProperties set to true or a schema), the response's messages (see Response format) carry a warning:

FieldValue
levelwarning
codeunknown_input_fields
messageFor example ignored input field(s) the function does not take: page_size. It takes: max_results, query.
meta.fieldsThe ignored keys
meta.functionThe function the task runs
json
1"messages": [2  {3    "level": "warning",4    "code": "unknown_input_fields",5    "message": "ignored input field(s) the function does not take: page_size. It takes: max_results, query.",6    "meta": { "fields": ["page_size"], "function": "list_files" }7  }8]

Errors

These apply to both POST /run and POST /apps/run (same handler).

StatusCodeDescription
400validation_errorWith infra: "private", a workers entry that is not a worker of your workspace: workers not found in team <username>: …. Another workspace's worker reads the same as a typo
404not_foundApp ref does not exist
404SESSION_NOT_FOUNDSession ID does not exist (when reusing session)
403forbiddenNo permission to run the app
403blocked_by_usage_policyThe app (or its publisher) is outside your workspace usage policy. Checked before balance — a blocked app returns this even when credits are zero, not payment_required.
402payment_requiredInsufficient balance for a run the usage policy already allows, or the workspace's spending is locked, on hold, or suspended (free runs included)
402payment_method_requiredA run certain to cost $0 when the balance would refuse it and the workspace has no saved payment method. meta.billing_page names the page that adds one. See Billing: free runs
409APP_MISMATCHSession is bound to a different app
409VERSION_MISMATCHSession is bound to a different app version
410SESSION_EXPIREDSession timed out (when reusing an existing session ID)
410SESSION_ENDEDSession was explicitly ended
410app_retiredApp has been retired — error.message includes the app's status_message
412(plain JSON)Missing setup requirements: {"satisfied": false, "errors": [...]} with the same errors as check, not problem+json
422validation_errorInvalid input — for example an unknown function on a multi-function app. The data array lists field errors; unknown-function errors include available function names in the message.
503app_maintenanceApp is temporarily unavailable — error.message includes the app's status_message; response includes Retry-After: 3600

When the app ref is wrong, the response is not_found without suggestions; use Search or Store apps to discover apps.


Get Task

GET /tasks/:id

Get task status and output.

Response

Same as Run Task response.

Example:

bash
1curl https://api.inference.sh/tasks/task_abc123 \2  -H "Authorization: Bearer inf_your_key"

List Tasks

POST /tasks/list

List your tasks with cursor-based pagination. Requires the apps:read scope.

Request

FieldTypeDescription
limitnumberMax results per page (default 10)
cursorstringPagination cursor from a previous response
directionstring"next" or "prev" (default "next")
filtersarrayFilter objects (field, operator, value)
sortarraySort objects (field, dir)

Filter by status — use an integer code or a status name from Task status codes (received, queued, dispatched, preparing, serving, setting_up, running, cancelling, uploading, completed, failed, cancelled, rejected):

json
1{2  "limit": 20,3  "filters": [4    { "field": "status", "operator": "eq", "value": 10 }5  ]6}

String names are accepted and converted server-side (for example "completed" is equivalent to 10):

json
1{2  "limit": 20,3  "filters": [4    { "field": "status", "operator": "eq", "value": "completed" }5  ]6}

For in / not_in operators, each array element may be an integer or a recognized status name. Unrecognized status strings return 400 with code invalid_filter.

Filter by app:

json
1{2  "limit": 20,3  "filters": [4    { "field": "app_id", "operator": "eq", "value": "app_xyz789" }5  ]6}

Response

FieldTypeDescription
itemsarrayTask objects (same shape as Get Task)
next_cursorstringCursor for the next page
prev_cursorstringCursor for the previous page
has_nextbooleanMore results available
has_previousbooleanPrevious page available

Example:

bash
1curl -X POST https://api.inference.sh/tasks/list \2  -H "Authorization: Bearer inf_your_key" \3  -H "Content-Type: application/json" \4  -d '{"limit": 10}'

From the CLI: belt task list (alias belt task ls). See CLI setup.


Queue stats

GET /tasks/queue-stats

Returns queue depth for your workspace: how many tasks are waiting for workers, scheduled for later, or actively running. Requires the apps:read scope. Counts are scoped to tasks you can see (same visibility rules as List Tasks).

Use this to monitor backlog before scaling workers or alerting on capacity. See also Queued longer than expected?.

Response

FieldTypeDescription
total_queuednumberTasks in Queued status
with_run_atnumberQueued tasks with run_at in the future (scheduled)
ready_to_runnumberQueued tasks ready to dispatch now
in_progressnumberTasks in active execution statuses (dispatched through uploading)
by_apparrayBreakdown by app
by_app_functionarrayBreakdown by app, version, and function

Each breakdown entry:

FieldTypeDescription
app_idstringApp ID
app_namestringnamespace/name when available
version_idstringApp version ID
functionstringFunction name (when set)
countnumberQueued tasks in this group
with_run_atnumberSubset with future run_at
in_progressnumberSubset actively running

Example:

bash
1curl https://api.inference.sh/tasks/queue-stats \2  -H "Authorization: Bearer inf_your_key"
json
1{2  "total_queued": 12,3  "with_run_at": 2,4  "ready_to_run": 10,5  "in_progress": 4,6  "by_app": [7    {8      "app_id": "app_xyz789",9      "app_name": "myteam/image-gen",10      "count": 8,11      "with_run_at": 0,12      "in_progress": 313    }14  ],15  "by_app_function": []16}

Get Task Status

GET /tasks/:id/status

Lightweight status poll without fetching full task input, output, or logs. Useful when you only need to know whether a task is still running.

Response

FieldTypeDescription
idstringTask ID
statusnumberStatus code
updated_atstringISO timestamp of last update

Example:

bash
1curl https://api.inference.sh/tasks/task_abc123/status \2  -H "Authorization: Bearer inf_your_key"

Get Task Logs

GET /tasks/:id/logs

Returns execution logs and status events for a task without the full task payload.

Response

FieldTypeDescription
task_idstringTask ID
statusnumberCurrent status code
eventsarrayStatus transition events
logsarrayLog entries (log_type, content)

Log types

log_typeNameTypical content
0buildContainer image build output
1runApp runtime stdout/stderr
2serveModel serving logs
3setupSetup-phase initialization
4taskTask-level messages

Example:

bash
1curl https://api.inference.sh/tasks/task_abc123/logs \2  -H "Authorization: Bearer inf_your_key"

From the CLI: belt task get <id> -f streams status until complete; belt task logs <id> -f tails live logs (filter with --type setup). See CLI setup.

JavaScript SDK: client.tasks.getLogs('task_abc123')


Get Task Timings

GET /tasks/:id/timings

Returns a timing breakdown derived from status events — total duration, phase groups, and per-transition timings.

Response

FieldTypeDescription
task_idstringTask ID
statusnumberCurrent status code
total_durationstringHuman-readable total duration
total_duration_msnumberTotal duration in milliseconds
groupsarrayHigh-level phases (label, start_at, end_at, duration, duration_ms)
eventsarrayPer-status transitions with durations

Example:

bash
1curl https://api.inference.sh/tasks/task_abc123/timings \2  -H "Authorization: Bearer inf_your_key"

From the CLI: belt task timings <id>. See CLI setup.

JavaScript SDK: client.tasks.getTimings('task_abc123')


Get Task Telemetry

GET /tasks/:id/telemetry

Returns time-series resource samples collected while the task ran on a worker (CPU, RAM, GPU, and volume usage). Samples are recorded by the engine during execution and stored in TimescaleDB.

Requires the same access as Get Task (apps:read scope). Long runs may return up to 100 downsampled points so responses stay bounded.

Response

Array of telemetry records under data:

FieldTypeDescription
idstringSample record ID
timestampstringISO timestamp when the sample was taken
task_idstringTask ID
task_seqnumberMonotonic sequence within the task
app_idstringApp that ran
app_version_idstringApp version
engine_idstringEngine that hosted the worker
worker_idstringWorker that executed the task
system_infoobjectWorker CPU, RAM, GPU, and volume metrics at this sample
engine_resourcesobjectEngine-level CPU, RAM, GPU, and volume metrics at this sample

Each system_info / engine_resources object includes:

Nested fieldDescription
cpusPer-CPU usage (usage, normalized_usage, core metadata)
ramMemory totals and usage percentages
gpusGPU memory, temperature, and driver metadata (when present)
volumesDisk volume size and usage

Example:

bash
1curl https://api.inference.sh/tasks/task_abc123/telemetry \2  -H "Authorization: Bearer inf_your_key"

JavaScript SDK:

typescript
1const { data: samples } = await client.tasks.getTelemetry('task_abc123');

Telemetry is most useful for debugging resource-heavy apps (large models, GPU runs, or disk-heavy pipelines). For phase durations without resource metrics, use Get Task Timings.

→ Observability · SDK overview — inspect and observability


Task egress

Finished tasks may include an egress object on the task DTO returned by GET /tasks/:id, POST /run (when you wait for completion), List Tasks, and task streams. It summarizes how much data the task's sandbox moved through the engine's egress gateway — outbound (bytes_out) and inbound (bytes_in) internet traffic in bytes.

FieldTypeDescription
bytes_outnumberBytes sent from the sandbox to the internet through the gateway
bytes_innumberBytes received from the internet through the gateway

The engine reports these totals when the task reaches a terminal state (Completed or Failed). The field is omitted when:

  • The task ran on an engine without the egress_gateway capability, or
  • The engine has not reported egress for that task yet (for example, a run still in progress).

Egress counts how much left and entered the sandbox. It is not a per-host access log.

Tasks of apps that use an upstream proxy count the bytes that went through the proxy the same way.

Example (completed task on an engine with the egress gateway):

json
1{2  "id": "task_abc123",3  "status": 10,4  "egress": {5    "bytes_out": 1048576,6    "bytes_in": 5242887  }8}

JavaScript SDK: TaskDTO.egress is typed as TaskEgress (@inferencesh/sdk ≥ v0.32.0).

Python SDK: TaskDTO["egress"] is typed as TaskEgress in inferencesh.types (inferencesh ≥ v0.34.0).


Cancel Task

POST /tasks/:id/cancel

Cancel a running task. By default the platform requests a graceful stop (apps with an on_cancel hook can clean up first).

Request body (optional)

FieldTypeDescription
forcebooleanIf true, skip the graceful stop and end the run immediately
timeoutnumberMilliseconds the app gets to stop on its own before the run is ended for it (default 10000)

Either way the worker is free for the next task when the call returns. An app that stops on its own keeps its loaded state; one that is ended for it is restarted, so the next task on that worker runs setup() again. See Graceful cancellation.

A cancelled task ends with status 12 (cancelled), never 10. If the app returned a result while stopping, or had returned one that was still uploading when the cancel arrived, the task stays at 8 (cancelling) until the upload finishes, then ends cancelled with that result as output, billed like any other result. A task with no result to upload ends cancelled with output null.

Example (graceful):

bash
1curl -X POST https://api.inference.sh/tasks/task_abc123/cancel \2  -H "Authorization: Bearer inf_your_key"

Example (force kill):

bash
1curl -X POST https://api.inference.sh/tasks/task_abc123/cancel \2  -H "Authorization: Bearer inf_your_key" \3  -H "Content-Type: application/json" \4  -d '{"force": true}'

Response

json
1{2  "id": "task_abc123",3  "status": 12,4  "cancelled": true5}

Delete Task

DELETE /tasks/:id

Delete a finished task. Requires the apps:execute scope.

A task that is still queued or running answers 409 conflict. Cancel it first, or wait for it to finish.

Query parameters

ParameterTypeDescription
filesbooleanIf true, also delete the task's input and output files. Default false: the files stay in your workspace

With files=true the files are deleted even when another task, flow or chat still uses them. Their URLs stop resolving. Files you cannot delete are skipped, as in Delete Task Files; they do not stop the task from being deleted.

Example (task only):

bash
1curl -X DELETE https://api.inference.sh/tasks/task_abc123 \2  -H "Authorization: Bearer inf_your_key"

Example (task and its files):

bash
1curl -X DELETE "https://api.inference.sh/tasks/task_abc123?files=true" \2  -H "Authorization: Bearer inf_your_key"

CLI equivalent: belt task delete <task-id> (add --files to delete its files too, --yes to skip the confirmation prompt).


Attach Task Files

POST /tasks/:id/files

Create platform file records for a task and link them to it as output files. Requires the apps:execute scope and write access to the task.

Workers call this while a task runs to register uploads; the caller then PUTs the bytes to each upload_url, as with Upload File. Files attached here appear in List Task Files even when the task's output never names their URLs.

The body is the same as POST /files: a files array of partial file descriptors.

bash
1curl -X POST https://api.inference.sh/tasks/task_abc123/files \2  -H "Authorization: Bearer inf_your_key" \3  -H "Content-Type: application/json" \4  -d '{"files":[{"uri":"","filename":"image.png","content_type":"image/png","size":102400}]}'

Response: FileDTO[], the same shape as Upload File.

StatusDescription
400Invalid JSON body
403No write access to the task
500Any other failure, including a task that does not exist

There is no SDK helper for this endpoint.


List Task Files

GET /tasks/:id/files

List the files a task consumed and produced. Requires the apps:read scope.

Use this to get the file IDs behind the URLs in a task's input and output, for example to delete one file with DELETE /files/:id.

Files are found from the platform URLs in the task's input and output and from the files linked to the task, including uploads attached with POST /tasks/:id/files that output never names. Files you cannot read (for example another workspace's file named in an input by its public URL) are left out.

Query parameters

ParameterTypeDescription
rolestringinput or output to list one side only. Omit for both. Any other value answers 400 validation_error

Response

json
1[2  {3    "id": "8k2m4n6p8q0r2s4t6v8w0x2y4z",4    "created_at": "2026-10-07T08:31:12Z",5    "role": "input",6    "uri": "https://cloud.inference.sh/t/1a2b3c4d/5e6f7g8h.png",7    "filename": "photo.png",8    "content_type": "image/png",9    "size": 10240010  },11  {12    "id": "9l3n5p7q9r1s3t5v7w9x1y3z5a",13    "created_at": "2026-10-07T08:31:15Z",14    "role": "output",15    "uri": "https://cloud.inference.sh/t/1a2b3c4d/9i0j1k2l.png",16    "filename": "result.png",17    "content_type": "image/png",18    "size": 24576019  }20]
FieldDescription
idFile ID, as DELETE /files/:id takes it
roleinput if the task consumed the file, output if it produced it. A file the app passes through from input to output is an input
uriThe URL that appears in the task's input or output

Only files stored on inference.sh are listed. An input you passed as a URL on your own storage is not a file here and does not appear.

CLI equivalent: belt task files <task-id> (add --role input or --role output, --json for the raw payload).


Delete Task Files

DELETE /tasks/:id/files

Delete a finished task's files and keep the task. Requires the apps:execute scope.

The task record stays, with its input and output unchanged; the file URLs in them stop resolving. A task that is still queued or running answers 409 conflict.

A file is deleted even when another task, flow or chat still uses it. If you reuse one uploaded input across several tasks, pass role=output to keep it.

Query parameters

ParameterTypeDescription
rolestringinput or output to delete one side only. Omit for both. Any other value answers 400 validation_error

Example:

bash
1curl -X DELETE https://api.inference.sh/tasks/task_abc123/files \2  -H "Authorization: Bearer inf_your_key"

Response

json
1{2  "deleted": ["8k2m4n6p8q0r2s4t6v8w0x2y4z", "9l3n5p7q9r1s3t5v7w9x1y3z5a"],3  "skipped": []4}
FieldDescription
deletedIDs of the files that were deleted
skippedFiles left in place, each with an id and a reason: forbidden (the file belongs to another workspace) or failed (the delete did not go through; call again to retry)

The call is safe to repeat: files already deleted are not listed again.

CLI equivalent: belt task delete-files <task-id> (add --role output to keep the inputs, --yes to skip the confirmation prompt).


Infrastructure routing

The infra field controls which workers the scheduler considers:

ValueBehavior
cloudCloud workers only (default when infra is omitted on POST /run)
privateYour workspace's private workers only
private_firstTry private workers first; fall back to cloud if none are available

private_first is useful when you prefer your own hardware but still want runs to succeed when private capacity is offline or busy. The scheduler ranks private workers ahead of cloud workers for matching tasks.

With infra: "private" and a workers list, every ID is checked at submit against your workspace's workers, and an unknown ID returns 400 validation_error instead of queuing a task that cannot run. If none of the listed workers is online, the task fails with none of the listed workers is online.

Apps may restrict which infra types they allow (for example cloud-only store apps). If the chosen infra is not permitted, the task fails immediately. If no worker is available yet, the task stays Queued until capacity appears or the queue expires.

→ Workers · Using private workers


Stream Task Updates

GET /tasks/:id/stream

Receive task status, logs, and output over Server-Sent Events (SSE) instead of polling GET /tasks/:id.

→ Streaming API

Use polling (GET /tasks/:id in a loop) when your environment cannot hold long-lived connections. The Python and JavaScript SDKs also support stream: false — see SDK polling.


Get Task Cost

GET /usage/tasks/:id/cost

Get the cost breakdown for a completed task.

Response

FieldTypeDescription
totalnumberTotal cost in microcents (1 microcent = $0.00000001)
discountnumberTotal discount applied in microcents (omitted if zero)
chargednumberAmount actually charged in microcents
refundednumberAmount refunded in microcents (omitted if zero)

Example:

bash
1curl https://api.inference.sh/usage/tasks/task_abc123/cost \2  -H "Authorization: Bearer inf_your_key"

Response:

json
1{2  "total": 50000,3  "charged": 500004}

See REST overview — response format.

Note: All values are in microcents. To convert to dollars: dollars = microcents / 100000000. For example, 50000 microcents = $0.0005.

Errors

StatusCodeDescription
403forbiddenYou don't have permission to access this task
404not_foundCost not found for this task

Task Status Codes

StatusCodeDescription
Received1Task received
Queued2Waiting for worker
Dispatched3Assigned to worker
Preparing4Setting up environment
Serving5Loading model
Setting Up6Task initialization
Running7Executing
Cancelling8Cancel requested; the app is stopping, or the result it returned is uploading
Uploading9Uploading results
Completed10Done
Failed11Error occurred
Cancelled12Cancelled. output holds what the app returned while stopping, if anything
Rejected13Refused before running: the workspace has no balance or no payment method. The input is kept; the run can be retried.

A rejected task is written only for a standalone run (POST /run, POST /apps/run). A flow step, an agent's model or tool call, or a graph node refused for payment gets no task; the run that asked reports the refusal. Rejected tasks send no webhook.

Task failure messages

When status is 11 (Failed), the error string describes the failure. App errors pass through from your code unchanged. Platform failures return short, retry-friendly messages without internal scheduler or worker details.

error valueMeaning
task interrupted, please retryTransient infrastructure issue (worker disconnect, engine reconnect, orphaned task)
task could not be dispatched, please retryCould not assign a worker when the task was submitted
task could not be processed after multiple attempts, please retryExceeded dispatch retry limit while stuck in Dispatched
task expired while waiting for available capacity, please retryQueued ~24 hours while matching workers stayed busy or leased
no online worker can run this appNo worker on a serving engine can run the task (GPU, VRAM, infra, or no engine online), or every matching cloud worker stayed held by another app's min_concurrency floor for 2 minutes after the block was first seen
none of the listed workers is onlineA private run pinned with workers, and none of those workers is online
no online engine has <capability>, which this task needsWorkers fit, but no online engine has a capability the task needs (for example the egress gateway); fails 2 minutes after the task was created
this app does not allow private workers / … cloud workers / … private or cloud workersThe task's infra is not allowed by the app
failed to prepare secrets for this app, please check your secret configurationMissing or invalid workspace secret
Missing requirements: …A required secret or credential was not found when the task was dispatched, for example add your {name} key to use this app. This includes a provider no key of yours covers and no platform key admits the run for: add your own key for that provider.
failed to set up this app's upstream proxyThe app's platform runtime policy names an egress proxy pool, but the scheduler could not build a dial URL (misconfigured pool URL or options). Not fixable from the workspace. See Upstream proxy.
session worker busy too longSession worker busy for ~30 seconds
session worker offlineSession's worker is no longer available
session expired or not foundInvalid session ID or idle timeout

→ Failed tasks and error messages · Troubleshooting


cURL Examples

Run and wait

bash
1curl -X POST https://api.inference.sh/run \2  -H "Authorization: Bearer inf_your_key" \3  -H "Content-Type: application/json" \4  -d '{5    "app": "infsh/flux",6    "input": {"prompt": "A sunset"},7    "wait": true8  }'

Run without waiting

Returns the task immediately. Poll GET /tasks/:id for the result.

bash
1curl -X POST https://api.inference.sh/run \2  -H "Authorization: Bearer inf_your_key" \3  -H "Content-Type: application/json" \4  -d '{5    "app": "infsh/flux",6    "input": {"prompt": "A sunset"}7  }'

Run with session

bash
1# Start a new session2curl -X POST https://api.inference.sh/run \3  -H "Authorization: Bearer inf_your_key" \4  -H "Content-Type: application/json" \5  -d '{6    "app": "my-app",7    "input": {"action": "init"},8    "session": "new"9  }'10# Response includes session_id: "sess_abc123"1112# Continue session13curl -X POST https://api.inference.sh/run \14  -H "Authorization: Bearer inf_your_key" \15  -H "Content-Type: application/json" \16  -d '{17    "app": "my-app",18    "input": {"action": "process"},19    "session": "sess_abc123"20  }'

Run with custom session timeout

bash
1# Start session with 5-minute idle timeout2curl -X POST https://api.inference.sh/run \3  -H "Authorization: Bearer inf_your_key" \4  -H "Content-Type: application/json" \5  -d '{6    "app": "my-app",7    "input": {"action": "init"},8    "session": "new",9    "session_timeout": 30010  }'

See Sessions Developer Guide for full documentation.

Session errors on run

When you pass an existing session ID to POST /run or POST /apps/run and the session has timed out, the API returns 410 Gone with code SESSION_EXPIRED. Start a new session with "session": "new".

Other session errors on run (SESSION_NOT_FOUND, SESSION_ENDED, APP_MISMATCH, VERSION_MISMATCH) are listed in Run Task errors above. WORKER_LEASED and other session-management errors are documented on the Sessions API. See also Sessions developer guide — Error handling.


Visibility

POST /tasks/{id}/visibility changes who can see a task. Requires apps:execute.

json
1{ "visibility": "team" }

Tasks have no share routes; to give named people access, share the app, flow or agent instead (see Visibility and sharing).


Webhooks

Get notified when a task completes by providing a webhook URL. When the task reaches a terminal state, a POST request is sent to your URL. A Rejected task never ran and sends no webhook.

Run with webhook

bash
1curl -X POST https://api.inference.sh/run \2  -H "Authorization: Bearer inf_your_key" \3  -H "Content-Type: application/json" \4  -d '{5    "app": "infsh/flux",6    "input": {"prompt": "A sunset"},7    "webhook": "https://your-server.com/webhook"8  }'

Webhook payload

Your endpoint receives a JSON POST with the task result:

json
1{2  "event": "task.completed",3  "timestamp": "2024-01-15T10:30:05Z",4  "data": {5    "id": "task_abc123",6    "short_id": "abc123",7    "status": 10,8    "status_text": "completed",9    "output": { "image": { "uri": "https://..." } },10    "created_at": "2024-01-15T10:30:00Z",11    "updated_at": "2024-01-15T10:30:05Z"12  }13}
FieldTypeDescription
eventstringtask.completed, task.failed, or task.cancelled
timestampstringWhen the webhook was sent (ISO 8601, UTC)
dataobjectThe task result, fields below

data fields:

FieldTypeDescription
idstringTask ID
short_idstringShort task ID
statusnumberTerminal status code (10=completed, 11=failed, 12=cancelled)
status_textstringStatus name (completed, failed, cancelled)
outputobjectTask output: of a completed task, or of a cancelled task whose app returned a result. null when there is none
errorstringError message. Present only when the task has one
session_idstringSession ID. Present only when the task ran in a session
created_atstringISO timestamp
updated_atstringISO timestamp
run_atstringScheduled start time (UTC). Present only for scheduled tasks

The webhook is sent when the task reaches a terminal status. Delivery is not retried: a failed request or a 4xx/5xx response is logged and dropped. The request times out after 10 seconds, and only public addresses are called.

we use cookies

we use cookies to ensure you get the best experience on our website. for more information on how we use cookies, please see our cookie policy.

by clicking "accept", you agree to our use of cookies.
learn more.