Tasks
For instructions on how to authenticate to use this endpoint, see API overview.
Endpoints
GET | |
POST | |
GET | |
GET | |
POST | |
POST | |
GET | |
PATCH | |
PATCH | |
POST |
Retrieve tasks runs connection token
Generate a JWT token for direct connection to the sandbox. Valid for 24 hours.
Required API key scopes
task:writePath parameters
- idstring
- task_idstring
Response
Example request
GET /api /projects /:project_id /tasks /:task_id /runs /:id /connection_tokenExample response
Status 200 Connection token for direct sandbox connection
Status 403 PostHog Desktop access is required
Status 404 Task run not found
Status 429 Organization reached its PostHog Desktop usage limit
Status 503 PostHog Desktop access could not be verified
Retrieve tasks runs connection token
Generate a JWT token for direct connection to the sandbox. Valid for 24 hours.
Required API key scopes
task:writePath parameters
- idstring
- task_idstring
Response
Example request
GET /api /projects /:project_id /tasks /:task_id /runs /:id /connection_tokenExample response
Status 200 Connection token for direct sandbox connection
Status 403 PostHog Desktop access is required
Status 404 Task run not found
Status 429 Organization reached its PostHog Desktop usage limit
Status 503 PostHog Desktop access could not be verified
Create tasks runs heartbeat
Tell the server that a local run is still alive. The client that drives a local run calls this about every 5 minutes while it holds the run open. A heartbeat reopens a local run that the server had completed. Cloud runs report their own heartbeats, so this endpoint refuses them, along with failed and cancelled runs and runs of a finished task.
Required API key scopes
task:writePath parameters
- idstring
- task_idstring
Example request
POST /api /projects /:project_id /tasks /:task_id /runs /:id /heartbeatExample response
Status 204 Heartbeat recorded
Status 404 Run not found
Status 409 The run cannot take heartbeats
Create tasks runs heartbeat
Tell the server that a local run is still alive. The client that drives a local run calls this about every 5 minutes while it holds the run open. A heartbeat reopens a local run that the server had completed. Cloud runs report their own heartbeats, so this endpoint refuses them, along with failed and cancelled runs and runs of a finished task.
Required API key scopes
task:writePath parameters
- idstring
- task_idstring
Example request
POST /api /projects /:project_id /tasks /:task_id /runs /:id /heartbeatExample response
Status 204 Heartbeat recorded
Status 404 Run not found
Status 409 The run cannot take heartbeats
Retrieve tasks runs logs
Fetch the logs for a task run as JSONL. If the run resumes from another (state.resume_from_run_id), each ancestor's log is concatenated first (oldest ancestor → ... → this run) so resume consumers see a single continuous history. A resumed Pi run includes the earlier runs of its task session the same way, each preceded by a pi_run_started entry that names its run. For a live presence-gated run, the request marks the stream as watched before it reads the log, so events after the snapshot reach the live stream. Pass tail_bytes to read only the latest turns first, add before to page back through older turns, or add start to read every entry after the ones a client holds. X-Log-Origin names the first run of the chain: indexes from responses with different origins do not match. A Pi run returns its full log without the X-Log headers. Pass view=thread to drop the duplicate tool response copy that a rendered conversation does not use.
Required API key scopes
task:readPath parameters
- idstring
- task_idstring
Query parameters
- beforeinteger
- startinteger
- tail_bytesinteger
- viewstringDefault:
fullOne of:"full""thread"
Example request
GET /api /projects /:project_id /tasks /:task_id /runs /:id /logsExample response
Status 200 Log content in JSONL format
Status 404 Task run not found
Retrieve tasks runs logs
Fetch the logs for a task run as JSONL. If the run resumes from another (state.resume_from_run_id), each ancestor's log is concatenated first (oldest ancestor → ... → this run) so resume consumers see a single continuous history. A resumed Pi run includes the earlier runs of its task session the same way, each preceded by a pi_run_started entry that names its run. For a live presence-gated run, the request marks the stream as watched before it reads the log, so events after the snapshot reach the live stream. Pass tail_bytes to read only the latest turns first, add before to page back through older turns, or add start to read every entry after the ones a client holds. X-Log-Origin names the first run of the chain: indexes from responses with different origins do not match. A Pi run returns its full log without the X-Log headers. Pass view=thread to drop the duplicate tool response copy that a rendered conversation does not use.
Required API key scopes
task:readPath parameters
- idstring
- task_idstring
Query parameters
- beforeinteger
- startinteger
- tail_bytesinteger
- viewstringDefault:
fullOne of:"full""thread"
Example request
GET /api /projects /:project_id /tasks /:task_id /runs /:id /logsExample response
Status 200 Log content in JSONL format
Status 404 Task run not found
Retrieve tasks runs preview
Redirects to the PostHog dev stack running inside this run's sandbox. A fresh sandbox access token is minted on every request and carried only in the redirect target, so it is never persisted or returned in a response body. When the run has no preview, or its sandbox has stopped, this renders a short HTML page instead.
Required API key scopes
task:writePath parameters
- idstring
- task_idstring
Example request
GET /api /projects /:project_id /tasks /:task_id /runs /:id /previewExample response
Status 200 HTML page explaining that the preview is not ready yet or has ended
Status 302 Redirect to the sandbox preview with a freshly minted access token
Status 403 Refused during read-only impersonation
Status 404 Task run not found
Retrieve tasks runs preview
Redirects to the PostHog dev stack running inside this run's sandbox. A fresh sandbox access token is minted on every request and carried only in the redirect target, so it is never persisted or returned in a response body. When the run has no preview, or its sandbox has stopped, this renders a short HTML page instead.
Required API key scopes
task:writePath parameters
- idstring
- task_idstring
Example request
GET /api /projects /:project_id /tasks /:task_id /runs /:id /previewExample response
Status 200 HTML page explaining that the preview is not ready yet or has ended
Status 302 Redirect to the sandbox preview with a freshly minted access token
Status 403 Refused during read-only impersonation
Status 404 Task run not found
Create tasks runs relay message
Queue a Slack relay workflow to post a run message into the mapped Slack thread.
Required API key scopes
task:writePath parameters
- idstring
- task_idstring
Request parameters
- textstring
- message_idstring | null
- text_partsarray
- trace_idstring | null
Response
Example request
POST /api /projects /:project_id /tasks /:task_id /runs /:id /relay_messageExample response
Status 200 Relay accepted
Status 404 Run not found
Create tasks runs relay message
Queue a Slack relay workflow to post a run message into the mapped Slack thread.
Required API key scopes
task:writePath parameters
- idstring
- task_idstring
Request parameters
- textstring
- message_idstring | null
- text_partsarray
- trace_idstring | null
Response
Example request
POST /api /projects /:project_id /tasks /:task_id /runs /:id /relay_messageExample response
Status 200 Relay accepted
Status 404 Run not found
Create tasks runs resume in cloud
Resume an existing task run in a cloud sandbox. Terminates any existing workflow and starts a new one.
Required API key scopes
task:writePath parameters
- idstring
- task_idstring
Response
Example request
POST /api /projects /:project_id /tasks /:task_id /runs /:id /resume_in_cloudExample response
Status 200 Run resumed in cloud
Status 400 Run already active or workflow failed
Status 403 PostHog Desktop access is required, or Pi cloud runtime is disabled
Status 409 The task is done, or it already has a run in progress
Status 429 Team is over its posthog_code usage limit
Status 503 PostHog Desktop access could not be verified
Create tasks runs resume in cloud
Resume an existing task run in a cloud sandbox. Terminates any existing workflow and starts a new one.
Required API key scopes
task:writePath parameters
- idstring
- task_idstring
Response
Example request
POST /api /projects /:project_id /tasks /:task_id /runs /:id /resume_in_cloudExample response
Status 200 Run resumed in cloud
Status 400 Run already active or workflow failed
Status 403 PostHog Desktop access is required, or Pi cloud runtime is disabled
Status 409 The task is done, or it already has a run in progress
Status 429 Team is over its posthog_code usage limit
Status 503 PostHog Desktop access could not be verified
Retrieve tasks runs session logs
Fetch session log entries for a task run with optional filtering by timestamp, event type, and limit.
Required API key scopes
task:readPath parameters
- idstring
- task_idstring
Query parameters
- afterstring
- event_typesstring
- exclude_typesstring
- limitintegerDefault:
1000 - offsetintegerDefault:
0
Example request
GET /api /projects /:project_id /tasks /:task_id /runs /:id /session_logsExample response
Status 200 Filtered log events as JSON array
Status 404 Task run not found
Retrieve tasks runs session logs
Fetch session log entries for a task run with optional filtering by timestamp, event type, and limit.
Required API key scopes
task:readPath parameters
- idstring
- task_idstring
Query parameters
- afterstring
- event_typesstring
- exclude_typesstring
- limitintegerDefault:
1000 - offsetintegerDefault:
0
Example request
GET /api /projects /:project_id /tasks /:task_id /runs /:id /session_logsExample response
Status 200 Filtered log events as JSON array
Status 404 Task run not found
Update tasks runs set output
Update the output field for a task run (e.g., PR URL, commit SHA, etc.)
Required API key scopes
task:writePath parameters
- idstring
- task_idstring
Request parameters
- output
Response
Example request
PATCH /api /projects /:project_id /tasks /:task_id /runs /:id /set_outputExample response
Status 200 Run with updated output
Status 404 Run not found
Update tasks runs set output
Update the output field for a task run (e.g., PR URL, commit SHA, etc.)
Required API key scopes
task:writePath parameters
- idstring
- task_idstring
Request parameters
- output
Response
Example request
PATCH /api /projects /:project_id /tasks /:task_id /runs /:id /set_outputExample response
Status 200 Run with updated output
Status 404 Run not found
Update tasks runs set summary
Replace the running summary for a task run, and optionally its slug tags.
Required API key scopes
task:writePath parameters
- idstring
- task_idstring
Request parameters
- summarystring
- tagsarray
Response
Example request
PATCH /api /projects /:project_id /tasks /:task_id /runs /:id /set_summaryExample response
Status 200 Run with updated task summary
Status 404 Run not found
Update tasks runs set summary
Replace the running summary for a task run, and optionally its slug tags.
Required API key scopes
task:writePath parameters
- idstring
- task_idstring
Request parameters
- summarystring
- tagsarray
Response
Example request
PATCH /api /projects /:project_id /tasks /:task_id /runs /:id /set_summaryExample response
Status 200 Run with updated task summary
Status 404 Run not found
Create tasks runs start
Start an existing cloud run after any initial run-scoped attachments have been uploaded.
Required API key scopes
task:writePath parameters
- idstring
- task_idstring
Request parameters
- pending_user_messagestring
- pending_user_artifact_idsarray
Response
Example request
POST /api /projects /:project_id /tasks /:task_id /runs /:id /startExample response
Status 200 Task with updated latest run
Status 400 Invalid start payload
Status 403 PostHog Desktop access is required, or Pi cloud runtime is disabled
Status 404 Task run not found
Status 409 The task is done
Status 429 Team is over its posthog_code usage limit
Status 503 PostHog Desktop access could not be verified
Create tasks runs start
Start an existing cloud run after any initial run-scoped attachments have been uploaded.
Required API key scopes
task:writePath parameters
- idstring
- task_idstring
Request parameters
- pending_user_messagestring
- pending_user_artifact_idsarray
Response
Example request
POST /api /projects /:project_id /tasks /:task_id /runs /:id /start




