Inference Logoinference.sh

Sessions

Manage stateful app sessions outside of POST /run.

Sessions concept · Sessions developer guide

Sessions are created automatically when you pass "session": "new" to Run Task. Use this API to list active sessions, inspect state, extend idle timeouts, or end sessions explicitly.


Authentication

Requires the apps:read scope for read endpoints and apps:execute for ending sessions or keepalive.


List Sessions

GET /sessions

Returns all active sessions for your team.

bash
1curl https://api.inference.sh/sessions \2  -H "Authorization: Bearer inf_your_key" \3  -H "X-API-Version: 2"

Get Session

GET /sessions/{id}

FieldDescription
idSession ID
app_idBound app
app_version_idPinned version
worker_idWorker holding the session lease
statusactive, ended, or expired
expires_atIdle expiration time (sliding window resets on each call)
idle_timeoutConfigured idle timeout in seconds
call_countNumber of runs in this session
task_idCurrent or last task, if any

Keepalive

POST /sessions/{id}/keepalive

Resets the idle timer without running the app. Returns the updated session object.

Requires apps:execute.

bash
1curl -X POST "https://api.inference.sh/sessions/sess_abc123/keepalive" \2  -H "Authorization: Bearer inf_your_key" \3  -H "X-API-Version: 2"

End Session

DELETE /sessions/{id}

Releases the worker lease and marks the session ended. Returns 204 No Content.

Requires apps:execute.

From the CLI: belt session end <id> (see CLI setup).


Errors

CodeHTTPDescription
SESSION_NOT_FOUND404Unknown session ID
SESSION_EXPIRED410Idle timeout elapsed
SESSION_ENDED410Session was ended
WORKER_LEASED409Worker bound to another session
APP_MISMATCH400session used with a different app
VERSION_MISMATCH400App version changed since session creation

Full handling examples: Sessions developer guide — Error handling.


Next

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.