# YouTube API upload: free checker and upload example

Resources for the APIWings guide [How to upload videos with the YouTube API: quotas and OAuth](https://apiwings.com/blog/youtube-api-upload-video). Free to use (MIT licence). Rules checked against Google's and YouTube's documentation on 30 November 2026.

## Files

| File | What it is |
|---|---|
| `youtube-upload-check.mjs` | Checker in JavaScript (Node 18+). `node youtube-upload-check.mjs plan.json` |
| `youtube_upload_check.py` | The same checker in Python 3.9+, no dependencies. `python youtube_upload_check.py plan.json` |
| `youtube-upload-rules.json` | Every rule with its source URL. Both checkers read it from the same folder |
| `example-plan.json` | Worked example: a fictional app (Postwell) with six planned uploads and 20 problems |
| `example-plan-fixed.json` | The same plan after the fixes: no errors or warnings |
| `make-examples.py` | Rebuilds the two example plans |
| `youtube-test-cases.json` | 1,619 test cases: 179 written by hand from the docs, 1,440 generated |
| `make-test-cases.mjs` | Rebuilds the test cases (and checks every hand-written case against the JS checker) |
| `test-youtube-check.mjs`, `test_youtube_check.py` | Run all cases: `1619 of 1619 cases pass` in both languages |
| `youtube-upload-example.mjs` | Upload example: checks, resumable upload with status checks and resume, thumbnail, playlist |
| `test-upload-example.mjs` | Runs the upload example and the curl walkthrough against the mock: `34 of 34 upload scenarios pass` |
| `youtube-mock-server.mjs` | Local mock of YouTube's upload endpoints and Google's token endpoint, written from the docs. `node youtube-mock-server.mjs 8080` |
| `youtube-upload-walkthrough.sh` | The seven steps with curl (bash + curl + python3): OAuth code exchange, session, file, status check and resume, video ID, processing, thumbnail |
| `youtube-api-upload-video-cheat-sheet.pdf` | One-page cheat sheet |

## The plan format

```json
{
  "app": { "requested_scopes": ["youtube.upload"], "features": ["upload", "thumbnails"],
           "oauth": { "user_type": "external", "publishing_status": "in_production", "verification": "verified" },
           "ui": { "privacy_choice_shown": true, "upload_notice_shown": true }, "quota": { "videos_insert_per_day": 100, "other_units_per_day": 10000 } },
  "uploads": [{
    "id": "launch", "channel": { "id": "UC...", "verified": true }, "upload_at": "2026-12-01T16:00:00Z",
    "video": { "file": "launch.mp4", "mime": "video/mp4", "bytes": 52000000, "seconds": 95, "width": 1920, "height": 1080 },
    "intended_format": "long",
    "resource": { "snippet": { "title": "...", "description": "...", "tags": ["..."], "categoryId": "28" },
                  "status": { "privacyStatus": "unlisted", "selfDeclaredMadeForKids": false },
                  "paidProductPlacementDetails": { "hasPaidProductPlacement": false } },
    "thumbnail": { "file": "launch.jpg", "format": "jpg", "bytes": 400000, "width": 1280, "height": 720 },
    "origin": { "generated_by": "person" }
  }]
}
```

- `resource` is the video resource exactly as you would send it to `videos.insert`; the checker does not change it.
- `app.features`: `upload`, `thumbnails`, `playlists`, `read_status`. `app.quota` only if YouTube raised yours.
- `app.ui.upload_notice_shown`: whether the screen with the upload button shows the notice required by section 9.1 of the YouTube API Services Terms of Service. `false` is an error.
- `channel.verified`: whether the channel's account is phone-verified (`true`, `false` or leave it out if unknown).
- Optional per upload: `intended_format` (`short` or `long`), `upload_chunk_bytes`, `playlist_id`, `confirm_processing`, `notify_subscribers`, `refresh_token_issued_at` (checked in Testing mode), `origin.approved_by`, `origin.realistic_synthetic`.

Each upload gets `no_issues_found`, `warnings` or `blocked`, the list of issues with their source, `expected_format` (`short`, `long` or `unknown`), its quota day in Pacific Time, `estimated_requests` (`videos_insert_calls`, `other_quota_units`, `status_checks`, `upload_requests` and `http_requests`) and the session request it would send. Quota is added up per Pacific Time day across the whole plan, because the quota belongs to the project, not to each channel. The Pacific day is computed with US daylight saving rules in code, with no time zone library.

## What a clean result means

No documented rule is broken. It is not an approval: the checker cannot see your real quota, the channel's own upload limit, whether the account is verified today, whether a category exists in the channel's region, or what YouTube decides about copyright and duplicates.

## Upload example

```
YOUTUBE_ACCESS_TOKEN=... node youtube-upload-example.mjs example-plan-fixed.json 1-ana-lentil-recipe --dry-run
```

Remove `--dry-run` to send. Tested only against `youtube-mock-server.mjs`, written from YouTube's documentation, never against YouTube: try it on a test channel with a private video first. File paths in the plan are relative to the plan file. The access token comes from your OAuth flow; refreshing it is up to your app.

- After a lost connection or a 500 to 504, it asks the session for its status (`Content-Range: bytes */size`) and resumes from the byte YouTube reports; a finished upload returns the same video, so a lost final answer does not lead to a second upload while the session is alive.
- A 404 means the session expired. It starts a new session only when no video can exist (the last byte was never sent, or YouTube answered it with 308 or 5xx). If the last bytes went out, no answer came back and the session expired, it stops with `outcome_unknown`: check the channel's uploads (`channels.list` → uploads playlist → `playlistItems.list`) before uploading again. Store the session URI before sending bytes.
- It stops without retrying on `quotaExceeded` (resets at midnight Pacific Time), `uploadLimitExceeded` (the channel's own limit) and metadata errors; retries 429 honouring `Retry-After` (up to `YOUTUBE_MAX_WAIT_MS`).
- For a Short with a thumbnail, or with `confirm_processing`, it polls `videos.list` until processing succeeds before `thumbnails.set`. A failed thumbnail or playlist call does not undo the upload.
- It reports the privacy status YouTube applied, which can differ from the one requested.
- Each request or chunk is read into memory: use `upload_chunk_bytes` (a multiple of 262,144) for large files.

## Sources

The `sources` block of `youtube-upload-rules.json` lists every page used. Values that are our reading, marked in the guide: the 256 GB limit taken as 256,000,000,000 bytes (the smaller reading), asking for `selfDeclaredMadeForKids` every time, `youtube.readonly` for processing checks, and counting the session `PUT` requests as HTTP requests only (Google does not document whether they use quota). Not legal advice.
