# agentic-yt — full documentation > Every page of https://agentic-yt.crafter.run/docs in one file. API base URL: https://api.agentic-yt.crafter.run. CLI: `agentic-yt`, alias `ayt`. --- # Agent skills Source: https://agentic-yt.crafter.run/docs/agent-skills Install the agentic-yt skill so your agent already knows the commands, the JSON shapes and the error playbook. A skill is a folder of instructions an agent loads when a task calls for it. The agentic-yt skill is how an agent goes from "I could probably shell out to something" to knowing exactly which command answers which question. ## Install ```bash npx skills add crafter-station/agentic-yt ``` Run it in the project your agent works in. It works with any agent that reads the skills format — Claude Code, Codex, Cursor and others — and puts the skill where that agent looks for it. The skill drives the CLI, so the agent's environment also needs: ```bash npm install -g agentic-yt # the ayt command export AGENTIC_YT_TOKEN=ayt_pat_… # or run `ayt login` once ``` ## What the skill teaches - **When to reach for it.** Any task that mentions a YouTube URL, a video's content, a channel's uploads, "what does this video say", "get me the audio", "show me the frame at…". - **Which command answers which question.** `ayt search` to find, `ayt video` to describe, `ayt transcript` to read, `ayt download` / `clip` / `frames` to produce files — and that a transcript is almost always cheaper than a download when the goal is understanding. - **To pass `--json`.** And to read results from stdout only. - **That any URL is an id.** No parsing, no `resolve` call first. - **The job model.** `download`, `clip` and `frames` block by default; `--no-wait` and `ayt jobs get --wait` for long work; a repeat request is a cache hit. - **The error playbook.** For each `error.code`: retry, change the request, or stop and ask the human. The same table as [Errors](https://agentic-yt.crafter.run/docs/errors). - **The limits.** Maximum duration, quality cap, three concurrent jobs, the daily quota — so it clips instead of downloading four hours, and does not fan out twenty downloads at once. - **What needs a human.** Signing in, and connecting a YouTube account. The agent is told to stop and ask rather than work around either. ## Without the skill Everything the skill says is also in these docs, in a form agents can fetch: - [`/llms.txt`](https://agentic-yt.crafter.run/llms.txt) — an index of every page with a one-line description. - [`/llms-full.txt`](https://agentic-yt.crafter.run/llms-full.txt) — every page in one file. - [`/openapi.json`](https://api.agentic-yt.crafter.run/openapi.json) — the machine-readable contract, if the agent would rather call the API directly. Pointing an agent at `llms.txt` in its system prompt is a reasonable substitute when you cannot install files into its environment. ## Writing your own instructions If you maintain your own prompt instead, the three rules that prevent most wasted turns are: 1. Always `--json`; never scrape the human-readable output. 2. On failure, read `error.code` and `error.hint` before doing anything else. 3. Prefer `transcript` over `download`, and `clip` over a full download, whenever the task allows. --- # Authentication Source: https://agentic-yt.crafter.run/docs/authentication Personal access tokens, ayt login, and the AGENTIC_YT_TOKEN environment variable. Every operation except `GET /v1/health` and the two CLI-login endpoints needs a **personal access token** in the `Authorization` header: ```http Authorization: Bearer ayt_pat_… ``` A token is `ayt_pat_` followed by 43 URL-safe characters (32 random bytes). It carries your whole account: its daily quota, its jobs and, if you connected one, its YouTube account. There are no scopes. The server stores only the SHA-256 hash of a token. The plaintext is shown **once**, when it is created, and cannot be recovered afterwards — if you lose it, revoke it and make another. ## Getting a token ### From the dashboard [Dashboard → Tokens](https://agentic-yt.crafter.run/dashboard/tokens) → name it → **Create token** → copy it. Name tokens after where they live (`ci`, `claude-code on laptop`); the list shows each token's prefix and when it was last used, which is how you find the one to revoke. ### With `ayt login` ```bash ayt login ``` This is a device-code flow, for machines where pasting a secret is awkward: 1. The CLI calls `POST /v1/cli/device` and receives a `user_code` like `BCDF-2345`, a secret `poll_token`, and a `verification_url`. 2. It prints the code and opens `verification_url_complete` — the dashboard's `/cli` page with the code pre-filled. If no browser can be opened (`--no-browser`, SSH), open the URL yourself. 3. You sign in to the dashboard, check the code matches the one in your terminal, and approve. 4. The CLI, which has been calling `POST /v1/cli/device/token` every couple of seconds, receives the new token on its next poll — exactly once — and saves it. Codes expire after ten minutes and work once. The token created this way appears on the tokens page like any other, named after the client, and revoking it there signs that machine out. `ayt login --token ayt_pat_…` stores a token you already have without the browser round-trip. `ayt logout` forgets the saved token locally; it does **not** revoke it on the server. ## Where the CLI looks for a token In order: 1. `AGENTIC_YT_TOKEN` in the environment. 2. The saved profile in `~/.agentic-yt/config.json` (mode `0600`), written by `ayt login`. | Variable | Purpose | | --- | --- | | `AGENTIC_YT_TOKEN` | Personal access token. Beats the saved one. | | `AGENTIC_YT_URL` | API base URL. Default `https://api.agentic-yt.crafter.run`. | | `AGENTIC_YT_PROFILE` | Which saved profile to use; `--profile` beats it. | | `AGENTIC_YT_CONFIG` | Path of the config file. | For an agent, prefer the environment variable: it survives a fresh container and never touches disk. ## Who am I? ```bash ayt whoami # account, token source, profile, API URL — exit code 3 if not signed in ayt me --json # the full GET /v1/me response ``` `GET /v1/me` returns the account (`id`, `email`, `role`, `daily_quota`), the token making the request, the state of the connected YouTube account, and the limits that apply — a cheap first call for an agent to confirm its credential works before starting real work. ## When it fails A missing, malformed or revoked token answers `401` with code [`unauthorized`](https://agentic-yt.crafter.run/docs/errors#unauthorized). Retrying will not help; the agent needs a human to run `ayt login` or supply a new token. > **The dashboard is not the API** The dashboard signs humans in with Clerk and reads the database directly. A Clerk session is not a credential for `api.agentic-yt.crafter.run`, and a personal access token does not sign you in to the dashboard. Operations covered: startDeviceLogin, pollDeviceLogin, getMe --- # Caching and freshness Source: https://agentic-yt.crafter.run/docs/caching What is cached, for how long, how to tell a cache hit, and how to ask for fresh data. The first request for something does the work. Every later request for the same thing is answered from the cache — for you, and for everyone else. This is the main reason agentic-yt is fast, and the main reason it is gentle on YouTube. ## What is cached, and for how long | What | Kept for | Keyed by | | --- | --- | --- | | Video metadata — title, description, chapters, tags | 7 days | video | | Video counters — views, likes, comment count | 1 hour | video | | Transcripts | 30 days | video, language, kind | | Downloads | until evicted | video, kind, format, quality | | Clips | until evicted | video, kind, format, quality, start–end | | Frames | until evicted | video, timestamp, format, width | Files have no expiry date. When space is needed, the least recently *used* are removed first; a file that keeps being asked for stays. ## How to tell Every cached surface says whether it was a hit: - **Video metadata** — `cache.hit`, plus `cache.stable_fetched_at` and `cache.counters_fetched_at`, so you can see how old each half is. - **Transcripts** — `cache_hit`. - **Jobs** — `cache_hit` on the job (true only if *everything* was cached) and on each asset. A job that is a full cache hit comes back `succeeded` straight from the `POST`, with HTTP `200`. It is never queued, does not count toward your [concurrent jobs](https://agentic-yt.crafter.run/docs/limits), and uses no quota. ## What counts as "the same" Requests are normalised before they are compared, so equivalent requests share a cache entry: - `"1:30"`, `90`, `90.0` and `"1m30s"` are the same time. - An omitted `format` and the default `format` are the same. - `quality: "best"` and `quality: "1080p"` are the same, because `best` is capped at 1080p. - A YouTube URL and the bare id it contains are the same video. - Audio as `wav` ignores `audio_bitrate`, so every bitrate shares one WAV. A different quality, format, bitrate, range, timestamp or width is a different file. > **Align your requests to hit the cache** If several agents (or several runs of one) work on the same videos, agree on parameters. Everyone asking for `720p` MP4 shares one file; one agent asking for `480p` makes a second. The defaults are the best meeting point — omit what you do not need to control. ## Asking for fresh data Only video metadata has a bypass: ```bash ayt video --fresh # GET /v1/videos/{id}?fresh=true ``` It refetches both halves from YouTube and updates the cache for everyone. Use it when a stale view count would be wrong for the task — not by default, since it is slower and can be refused where the cached answer cannot. Transcripts and files have no bypass: a published video's captions and streams do not meaningfully change. ## Asset URLs expire; assets do not The `url` on an asset is signed and stops working at `expires_at` (up to 7 days after it was issued). The file is still cached. To get a working URL again, `GET` the job, or repeat the request that made it — a cache hit, with a fresh URL. Do not store asset URLs as permanent links. Store the request (video id plus parameters) or the job id. ## Shared and private The cache is **shared across accounts** by default. That is safe because a cache entry is identified only by public facts — the video and the output parameters — and holds only what YouTube serves anyone. The exception is anything fetched using a [connected YouTube account](https://agentic-yt.crafter.run/docs/guides/youtube-account). Those results are stored **privately**, keyed to the account that owns the cookies, and are never served to anyone else. If you request a public video with `use_account: true`, you get a private copy and do not benefit from, or contribute to, the shared one — a reason to leave `use_account` unset unless you need it. ## Quota **Cache hits are free.** The [daily quota](https://agentic-yt.crafter.run/docs/limits) counts only requests that had to reach YouTube. A transcript you (or anyone) already fetched, a file that already exists, metadata still inside its freshness window — none of them use quota, and none of them take one of your three job slots. Every response says which it was in the `X-Cache` header: `hit` or `miss`. --- # CLI reference Source: https://agentic-yt.crafter.run/docs/cli Every agentic-yt (ayt) command, its flags, output modes and exit codes. The CLI is installed as `agentic-yt` with the alias `ayt`. Both names run the same program. ```bash npm install -g agentic-yt # or: npx agentic-yt ayt --help # every command ayt --help # one command's flags ``` ## Conventions - **References.** Every `` is a bare id or any YouTube URL — `watch?v=`, `youtu.be/`, shorts, embeds, playlist links, `@handle`. Quote URLs so the shell does not eat `&` and `?`. - **Times.** `--start`, `--end` and `--at` accept seconds (`90`), a clock (`1:30`, `00:01:30.5`) or YouTube-style units (`1m30s`). - **Streams.** Results go to stdout; progress and messages go to stderr. Piping stdout is always safe. ## Global flags | Flag | Effect | | --- | --- | | `--json` | Print exactly one JSON document on stdout — the API response, unmodified. Errors too: `{"error":{"code","message","hint"}}`. | | `--profile ` | Use a named profile from the config file. | | `-y`, `--yes` | Answer yes to confirmation prompts. Required when there is no TTY. | | `-V`, `--version` | Print the version. | Global flags are accepted before or after the subcommand: `ayt --json video ` and `ayt video --json` are the same. > **For agents: always pass --json** Without it the CLI prints tables meant for people, and their layout is not a contract. With it, the output has the same field names as the [API reference](https://api.agentic-yt.crafter.run/docs). ## Flags shared by `download`, `clip` and `frames` These three create a [job](https://agentic-yt.crafter.run/docs/jobs). By default they **block until the file is on your disk**. | Flag | Effect | | --- | --- | | `-o`, `--output ` | Where to write. A file name, or a directory (the server-provided filename is used). Default: the current directory. | | `--no-wait` | Print the job and exit immediately. Follow it with `ayt jobs get --wait`. | | `--url-only` | Wait for the job, then print the asset URL(s) instead of downloading. | | `--timeout ` | Stop waiting after this long (default 30). The job keeps running. | | `--account` | Use your connected YouTube account. The result is private to you. | | `--no-account` | Never use your connected YouTube account, even as a fallback. | ## Commands ### Signing in ```bash ayt login # approve a code in the browser ayt login --token ayt_pat_… # store a token you already have ayt login --no-browser # print the URL instead of opening it ayt logout # forget the saved token (does not revoke it) ayt whoami # account, token source, profile, API URL ``` See [Authentication](https://agentic-yt.crafter.run/docs/authentication). ### Looking things up ```bash ayt search [--type video|channel|playlist] [--limit N] [--cursor C] ayt video [--fresh] ayt formats ayt thumbnail [--quality default|medium|high|standard|maxres] [-o file] ayt transcript [--lang en] [--translate-to es] [--format json|srt|vtt|txt] [-o file] ayt languages ayt comments [--sort top|new] [--limit N] [--cursor C] ayt channel [--videos [--sort new|popular] [--limit N] [--cursor C]] ayt playlist [--videos [--limit N] [--cursor C]] ayt resolve ayt health ``` Lists return `next_cursor`; pass it back as `--cursor` for the next page. `--limit` is 1–100, default 20. ### Producing files ```bash ayt download [--audio] [--format F] [--quality Q] [--bitrate K] ayt clip --start