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
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")

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)
session_idstringSession ID (if using sessions)
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  }'

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.


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.

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  "id": "task_abc123",3  "status": 9,4  "output": { "image": { "uri": "https://..." } },5  "error": "",6  "session_id": null,7  "created_at": "2024-01-15T10:30:00Z",8  "updated_at": "2024-01-15T10:30:05Z"9}
FieldTypeDescription
idstringTask ID
statusnumberTerminal status code (9=completed, 10=failed, 11=cancelled)
outputobjectTask output (when completed)
errorstringError message (when failed)
session_idstringSession ID (if using sessions)
created_atstringISO timestamp
updated_atstringISO timestamp

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.