This is a deterministic, click-by-click guide to creating and restricting a Google Cloud
API key for oytc. It is written so that a person — or a computer-use agent — can follow
it without guessing. All URLs are direct deep links into the Google Cloud console.
The key is free. The YouTube Data API v3 has a default free quota (10,000 units/day for
most endpoints plus a separate bucket of 100 search.list calls/day) and oytc performs
read-only requests, so no billing account is required.
Never paste your key into files, shell commands, or chat. The only supported ways to give it to
oytcare the no-echooytc loginprompt, piping intooytc login, or theOYTC_API_KEYenvironment variable.
- A Google Account. Create one at https://accounts.google.com/signup if needed.
- A browser signed in to that account. If you are signed in to multiple accounts, confirm the account avatar in the top-right corner of the console before proceeding.
- Open the project creation page directly: https://console.cloud.google.com/projectcreate
- First-time console users may see a terms-of-service dialog. Check the agreement box and click Agree and continue.
- In the Project name field, type a name, e.g.
oytc. (The auto-generated project ID below it is fine; you never need to type it again for this guide.) - Leave Location / Organization as
No organizationunless you know otherwise. - Click the Create button.
- Wait for the notification bell (top right) to show "Create project: oytc" finished, then click SELECT PROJECT in that notification — or pick the project from the project selector dropdown at the top-left of the page (next to the "Google Cloud" logo).
To reuse an existing project instead: open https://console.cloud.google.com/projectselector2/home/dashboard and click the project's name in the list.
- Open the API's library page directly:
https://console.cloud.google.com/apis/library/youtube.googleapis.com
- Confirm the project selector in the top bar shows your project. If not, click it and choose the project, then re-open the URL.
- Alternative navigation: https://console.cloud.google.com/apis/library → type
YouTube Data API v3in the search field → click the YouTube Data API v3 card.
- Click the blue Enable button.
- If you instead see Manage and API Enabled, the API is already on; continue.
- Wait for the redirect to the API's overview page (URL contains
/apis/api/youtube.googleapis.com).
- Open the credentials page directly: https://console.cloud.google.com/apis/credentials
- Click + Create credentials near the top of the page.
- Select API key from the dropdown menu.
- A "API key created" dialog appears showing the key string (starts with
AIza…).- Click the copy icon next to the key and store it temporarily in a password manager or keep the dialog open. Do not paste it into a plain-text file.
- Recent console versions may show a key creation flow with a restriction step instead of a plain dialog; if a restriction form appears now, jump to Step 4's settings, apply them in that form, then save and copy the key.
- Click Close (or Edit API key to jump straight to Step 4).
Restricting the key means a leaked key can only spend your YouTube quota, not call other (potentially billable) Google APIs on your project.
- On https://console.cloud.google.com/apis/credentials, in the API Keys table,
click the name of the key you just created (default name:
API key 1). - Optional: change Name to
oytcso future-you knows what it is for. - Scroll to the API restrictions section.
- Select the Restrict key radio button.
- Click the Select APIs dropdown, type
YouTubein its filter box, and check YouTube Data API v3. Click OK to close the dropdown.- If YouTube Data API v3 is not listed, you skipped Step 2 — enable the API first, then reload this page.
- Leave everything else and click Save at the bottom.
The Application restrictions section (None / Websites / IP addresses / Android apps / iOS apps) controls where the key may be used from:
- None (recommended for a laptop CLI): the key works from any network. This is the practical choice for a CLI that roams between home, office, and mobile networks. The API restriction above is your main protection; also keep the key out of files and history.
- IP addresses: strongest option if you only run
oytcfrom hosts with stable public IPs (e.g. one server or a fixed egress IP). Enter each IP/CIDR. On a laptop with DHCP/VPN/mobile networks this will lock you out whenever your IP changes — expect403 forbiddenerrors fromoytcuntil you update the list. - Websites / Android / iOS: designed for browser and mobile apps; they key off HTTP
referrers or app signatures that a CLI does not send. Do not use these for
oytc— they will simply block every request.
If you cannot decide: choose None, keep the API restriction from Step 4, and rotate the key (Step 7) if you ever suspect exposure.
Run:
oytc loginPaste the key at the YouTube Data API key: prompt (input is not echoed) and press Enter.
oytc validates the key with a cheap i18nLanguages.list request and writes it atomically
to the platform config path with 0600 permissions. For non-interactive setups, pipe it:
some-secret-manager get youtube-api-key | oytc loginA freshly created or freshly restricted key can take a few minutes to propagate. If validation fails immediately after creation with
keyInvalidoraccessNotConfigured, wait 2–5 minutes and retry.
Now delete the key from wherever you temporarily stashed it (clipboard managers included).
oytc status --checkExpected output ends with Remote check: valid (or "valid": true in JSON mode). Then
try a real query:
oytc video get dQw4w9WgXcQ- Rotate: on https://console.cloud.google.com/apis/credentials, click the key name, then
the Regenerate key button; re-run
oytc loginwith the new value. The old value keeps working for a short overlap window, then dies. - Revoke: on the same credentials page, click the trash icon in the key's row and confirm.
- Remove from this machine:
oytc logout.
| Symptom | Cause / fix |
|---|---|
API key validation failed … accessNotConfigured |
YouTube Data API v3 is not enabled on the key's project. Redo Step 2, wait a few minutes, retry. |
API key validation failed … keyInvalid |
Typo/truncation in the pasted key, or the key was just created and hasn't propagated. Re-copy carefully; wait and retry. |
403 … requests from this client are blocked or IP errors |
Application restriction mismatch — you set IP/website restrictions that don't match your machine. Set application restrictions to None (Step 4 trade-offs) or update the allowed IPs. |
quotaExceeded (exit code 5) |
Daily quota exhausted. Search has its own 100 calls/day bucket. Wait for the midnight-Pacific reset or request more quota via the YouTube API quota extension form. |
status shows Source: OYTC_API_KEY when you expected the file |
The environment variable outranks auth.json. unset OYTC_API_KEY to fall back to the saved key. |
Key works in the browser test but not in oytc |
Check oytc status for which key is actually active; check for API restrictions excluding YouTube Data API v3. |
| Console pages look different from this guide | Google periodically redesigns the console. The stable anchors are the direct URLs above and the labels "Create credentials", "API key", "Restrict key". Google's current canonical docs: API key docs and YouTube Data API getting started. |
| Operation | Cost |
|---|---|
Most list reads (videos, channels, playlists, comments, …) |
1 unit |
search.list |
1 call from the dedicated 100 calls/day search bucket |
videoTrainability.get (oytc video trainability) |
free, no key needed |
Default allocation: 10,000 units/day combined for non-search endpoints, plus the search bucket. See quota costs.