Inference Logoinference.sh

Tasks

Run apps and manage tasks.


Run Task

POST /run

Run an app and optionally wait for completion.

Request

FieldTypeRequiredDescription
appstringYesApp identifier (namespace/name@version)
inputobjectYesInput data matching app schema
setupobjectNoSetup parameters
infrastringNo"cloud" or "private"
workersstring[]NoSpecific 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

FieldTypeDescription
idstringTask ID
statusnumberStatus code
inputobjectInput data
outputobjectOutput data (when complete)
errorstringError message (if failed)
created_atstringISO 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

StatusCodeDescription
Received1Task received
Queued2Waiting for worker
Scheduled3Assigned to worker
Preparing4Setting up environment
Serving5Loading model
Setting Up6Task initialization
Running7Executing
Uploading8Uploading results
Completed9Done
Failed10Error occurred
Cancelled11Cancelled

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  }'

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.