Run apps and manage tasks.
Run Task
POST /run
Run an app and optionally wait for completion.
Request
| Field | Type | Required | Description |
|---|---|---|---|
app | string | Yes | App identifier (namespace/name@version) |
input | object | Yes | Input data matching app schema |
setup | object | No | Setup parameters |
infra | string | No | "cloud" or "private" |
workers | string[] | No | Specific worker IDs |
Example:
json
1{2 "app": "infsh/flux",3 "input": {4 "prompt": "A sunset over mountains"5 },6 "setup": {7 "model": "schnell"8 }9}Response
| Field | Type | Description |
|---|---|---|
id | string | Task ID |
status | number | Status code |
input | object | Input data |
output | object | Output data (when complete) |
error | string | Error message (if failed) |
created_at | string | ISO timestamp |
Example:
json
1{2 "id": "task_abc123",3 "status": 9,4 "input": { "prompt": "A sunset..." },5 "output": {6 "image": { "uri": "https://..." }7 },8 "created_at": "2024-01-15T10:30:00Z"9}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"Cancel Task
POST /tasks/:id/cancel
Cancel a running task.
Response
json
1{2 "id": "task_abc123",3 "status": 11,4 "cancelled": true5}Task Status Codes
| Status | Code | Description |
|---|---|---|
| Received | 1 | Task received |
| Queued | 2 | Waiting for worker |
| Scheduled | 3 | Assigned to worker |
| Preparing | 4 | Setting up environment |
| Serving | 5 | Loading model |
| Setting Up | 6 | Task initialization |
| Running | 7 | Executing |
| Uploading | 8 | Uploading results |
| Completed | 9 | Done |
| Failed | 10 | Error occurred |
| Cancelled | 11 | Cancelled |
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 }'Run without waiting
bash
1curl -X POST "https://api.inference.sh/run?wait=false" \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 }'