Skip to Content
agentic-yt

Jobs and long-polling

How downloads, clips and frames run, how to wait for them in one request, and how to list and cancel them.

Three operations produce files, and all three return a job:

OperationCreates
POST /v1/videos/{id}/downloada video or audio file
POST /v1/videos/{id}/clipa section of one
POST /v1/videos/{id}/framesstill images

Everything else in the API answers inline.

The job object

{
  "id": "0b6f6c1e-9d0a-4f43-8a39-0a2f5f3f6f11",
  "type": "download",
  "status": "running",
  "progress": 42,
  "video_id": "dQw4w9WgXcQ",
  "params": { "kind": "video", "format": "mp4", "quality": "720p", "audio_bitrate": 128 },
  "result": null,
  "error": null,
  "cache_hit": false,
  "poll_url": "https://api.agentic-yt.crafter.run/v1/jobs/0b6f6c1e-9d0a-4f43-8a39-0a2f5f3f6f11",
  "created_at": "2026-11-26T14:04:41.000Z",
  "started_at": "2026-11-26T14:04:42.000Z",
  "finished_at": null
}
FieldNotes
statusqueued → running → succeeded, failed or canceled. The last three are terminal.
progress0–100.
paramsYour request body, normalised: defaults filled in, times in seconds.
result{ "assets": [...] } once succeeded; otherwise null.
error{ code, message, hint } once failed; otherwise null.
cache_hittrue when nothing had to be fetched or transcoded.
poll_urlWhere to ask about this job again.

Each asset has url, bytes, mime, filename, its own cache_hit, expires_at (when the signed url stops working) and, for frames, timestamp.

Status codes

A job-creating POST answers:

  • 200 when the job it returns is terminal — it was a cache hit, or it finished within wait.
  • 202 when the job is still queued or running.

A failed job is a 200

GET /v1/jobs/{id} on a job that failed returns HTTP 200 with status: "failed" and the reason under error. The request to read the job succeeded; the job did not. Always check status, not only the HTTP code.

Waiting: wait

Add ?wait=N (0–60 seconds, default 0) to a job-creating POST or to GET /v1/jobs/{id}, and the server holds the request until the job is terminal or N seconds pass, whichever is first.

That turns the usual create-then-poll loop into one call when the work is quick or cached:

curl -X POST "https://api.agentic-yt.crafter.run/v1/videos/dQw4w9WgXcQ/download?wait=60" \
  -H "Authorization: Bearer $AGENTIC_YT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"kind":"audio"}'

And into a loop with no sleep when it is not:

job=$(curl -s -X POST "$API/v1/videos/$VIDEO/download?wait=60" -H "Authorization: Bearer $AGENTIC_YT_TOKEN" \
        -H "Content-Type: application/json" -d '{}')

until echo "$job" | jq -e '.status | IN("succeeded","failed","canceled")' >/dev/null; do
  job=$(curl -s "$(echo "$job" | jq -r .poll_url)?wait=60" -H "Authorization: Bearer $AGENTIC_YT_TOKEN")
done

echo "$job" | jq -r 'if .status == "succeeded" then .result.assets[].url else .error end'

Each request returns the moment the job finishes, so there is no wasted time and no polling interval to tune. Set your HTTP client's timeout above wait — 75 seconds for wait=60.

The CLI does all of this for you: ayt download, clip and frames wait by default, and ayt jobs get <id> --wait waits on an existing job.

Cache hits

If the file you asked for already exists, the POST returns a finished job immediately: status: "succeeded", cache_hit: true, result.assets populated, HTTP 200 — even with wait=0. Nothing is queued. See Caching.

The same request twice

If you send a request identical to one of your own jobs that is still queued or running, you get that job back rather than a second one. An agent that retries a timed-out POST therefore does not start duplicate work — retrying is safe.

Concurrency

An account can have at most 3 jobs in flight. A fourth is refused with rate_limited: wait for one to finish (long-poll it), then retry. Cache hits do not count — they never enter the queue.

Listing jobs

ayt jobs list --status running --json

GET /v1/jobs returns your jobs newest first:

ParameterDefaultNotes
status—queued, running, succeeded, failed or canceled.
type—download, clip or frames.
limit201–100.
cursor—next_cursor from the previous response.

Useful after a crash: an agent that lost track of what it started can list running jobs instead of starting them again.

Getting one job

ayt jobs get <id> --json
ayt jobs get <id> --wait -o ./out/      # wait, then save its files

GET /v1/jobs/{id} returns the job, with fresh asset URLs. An unknown id — or a job that belongs to another account — is not_found.

Canceling

ayt jobs cancel <id>

DELETE /v1/jobs/{id} cancels a queued or running job and returns it. It is idempotent: canceling a job that already finished returns it unchanged, so there is no race to worry about.

When a job fails

error on the job is the same { code, message, hint } body as an HTTP error — handle it with the same code. The usual ones are video_unavailable, youtube_blocked, too_long and account_required; Errors has the response to each. To retry, send the original POST again: it creates a new job.

On this page