# AGY Video API

**Status on 10 November 2026: deployed; authenticated HTTPS API is live.**

Base URL: `https://video.winds-os.com/agy-api/v1`

Verification: 29 local tests pass. Three independent AGY analysis/native-goal
receipt sessions completed automatically and closed their owned workers. The
HTTPS lifecycle passed fresh analysis, feedback/re-analysis, stale-approval
rejection, explicit idempotent approval, native-goal proof, output verification,
authenticated byte-range download and close with retained files.
The final targeted-ownership build passed another HTTPS lifecycle; 120 local
health checks during active work had a maximum observed response time of
0.019 seconds. This is test evidence, not a future latency guarantee.

The production-path HTTP test used an explicitly authorised byte-for-byte copy
of an existing video fixture. It did not render a new creative video, contact a
media provider, or establish creative/reference fidelity for a future request.
Real creative jobs still need their own production and quality review.

This is a trusted-administrator API for native Antigravity CLI video jobs.
Creating a session runs analysis only. Generation requires a separate,
authenticated approval of the current plan with `yolo: true`. Approval starts
the actual native AGY `/goal` in the same recorded conversation with
`--dangerously-skip-permissions`; it is not a substitute assistant-managed goal.

## 1. Sign in and create a fresh analysis session

Use the existing video-site username/password. No passwords or tokens are
included in this guide. Keep the cookie jar private and do not commit it.

```bash
umask 077
SITE='https://video.winds-os.com'
API="$SITE/agy-api/v1"

curl --fail-with-body -c cookies.txt \
  -H 'Content-Type: application/json' \
  --data '{"username":"YOUR_USERNAME","password":"YOUR_PASSWORD"}' \
  "$SITE/api/session"

curl --fail-with-body -b cookies.txt "$API/health"

curl --fail-with-body -b cookies.txt \
  -H 'Content-Type: application/json' \
  -H 'Idempotency-Key: create-example-video-001' \
  --data '{
    "name":"My reference recreation",
    "asset_id":"ebca3c9eee9540d0b82725cd242ce234",
    "brief":"Preserve the reference visual style, camera, pacing and scene progression. Improve animation and clarity without adding new instructional content. Use supplied audio. Code plus FFmpeg only, server rendering, no paid media APIs.",
    "target":{"width":1080,"height":1920,"fps":60,"preview":false},
    "model":"gemini-4-argon-high",
    "max_seconds":14400,
    "max_repairs":3
  }' "$API/sessions"
```

Replace the example asset ID with your uploaded video asset ID. Alternatively
omit `asset_id` and pass `reference_url` containing a direct, publicly
accessible HTTPS video URL. Provide exactly one. Login-protected external URLs,
HTML/YouTube pages, private network URLs, arbitrary filesystem paths and custom
CLI flags are not supported input shortcuts. Upload/import those videos to the
existing video app first, then use the asset ID.

The response is HTTP202 with a server-generated `id`, private `folder`,
`state: "analysis_queued"` and polling fields. Save `id` as `SESSION_ID`:

```bash
SESSION_ID='REPLACE_WITH_RETURNED_ID'
curl --fail-with-body -b cookies.txt "$API/sessions/$SESSION_ID"
curl --fail-with-body -b cookies.txt "$API/sessions"
```

Poll until `state` becomes `awaiting_approval`. That response includes the actual
analysis, `plan_version`, `plan_sha256`, reference hash and `approval_required`.
Do not approve blindly; read the approach and its evidence limitations first.
Authentication failure returns401 and cannot create a job or process.

### Phone-rendered Three.js sessions

For the Video Workflow coordinator, send `"renderer":"phone"` when creating a
session and use `"target":{"width":1080,"height":1920,"fps":30,"preview":true}`.
The alternative `"server"` remains the default for existing API clients. Renderer
is pinned in the plan; phone targets are 30fps with 720/1080 portrait, landscape
or square dimensions. Unsupported phone targets return422 before creating a job.
The maker receives a bounded phone helper in goal.json. It snapshots a scene
with assets/vendor dependencies and assets/sound.m4a, waits for the paired phone,
and copies the verified phone video into the session output folder. It does not
fall back to a CPU final render when the phone is unavailable. Close stops only
that project's owned phone submissions; other phone jobs are preserved.
This option does not authorize paid image/video providers through this code-only API.

## 2. Approve the current plan and start native `/goal` with YOLO

Copy the current plan version and hash from GET/session. This separate call is
the explicit authorisation to execute generated code without tool prompts.

```bash
curl --fail-with-body -b cookies.txt \
  -H 'Content-Type: application/json' \
  -H 'Idempotency-Key: approve-example-video-001' \
  --data '{"plan_version":1,"plan_sha256":"REPLACE_WITH_CURRENT_HASH","yolo":true}' \
  "$API/sessions/$SESSION_ID/approve"
```

The response initially says `goal_queued`. Only report the goal active when
GET/session reaches `generating` with `native_goal.native_goal: true` and the
verified conversation/user-step receipt. A process launch or a plain text
mention of `/goal` does not count. Stale plans, changed references and an
already-approved/running session return409 rather than creating duplicates.

The server handles first-use trust only for its own exact job directory,
waits for the loaded live composer and native command menu, confirms selection
and the current request, and checks persisted native-goal evidence. Restored
history or a past `GOAL_COMPLETE` message is never treated as current readiness.
It does not fall back to ordinary chat or blindly resubmit an uncertain goal.

Fresh sessions do not reuse another project's conversation. Feedback/revisions
within one session retain its recorded AGY conversation. Models currently
allowed by this API are `gemini-4-argon-high`, `gemini-4-argon-medium` and
`gemini-3.8-flash-high`; actual provider availability can still block a run.
The shared AGY Google account must already be logged in on the server. This API
does not sign accounts in/out, accept Google tokens, or change global settings.

## 3. Feedback, status and incremental events

```bash
curl --fail-with-body -b cookies.txt \
  -H 'Content-Type: application/json' \
  -H 'Idempotency-Key: feedback-example-video-001' \
  --data '{"text":"Make the captions easier to read without hiding character movement."}' \
  "$API/sessions/$SESSION_ID/feedback"

curl --fail-with-body -b cookies.txt "$API/sessions/$SESSION_ID"
curl --fail-with-body -b cookies.txt "$API/sessions/$SESSION_ID/events?after=0"
```

Events return `next_cursor`; pass it as the next `after` value to receive only
new events. These are polling events, not an SSE stream or an automatic
WhatsApp notification subscription. Raw terminal contents, private reasoning,
process ownership markers and authentication secrets are not exposed.

Feedback before approval invalidates the old plan and requests re-analysis.
During an active generation it is queued, not injected into a concurrent
writer or used to interrupt a render. After that run completes, queued
feedback requests a revised analysis and another explicit approval before a
new full run. The response distinguishes `queued`, `delivering`, `applied` and
`cancelled` feedback. Previous output revisions remain available. Feedback is
scoped to this video/session, not every future video or a global template.

`progress_percent` is deliberately null unless meaningful measured progress is
implemented; elapsed time is not a reliable completion percentage. Inspect
state, heartbeat, runtime_alive, deadline, errors and verified outputs instead.

## 4. Retrieve the final video, then close a session

```bash
curl --fail-with-body -b cookies.txt "$API/sessions/$SESSION_ID/outputs"

# Replace 0 with the desired output index returned by the API.
curl --fail-with-body -b cookies.txt \
  "$API/sessions/$SESSION_ID/outputs/0" -o final.mp4

curl --fail-with-body -b cookies.txt \
  -H 'Content-Type: application/json' \
  -H 'Idempotency-Key: close-example-video-001' \
  --data '{}' "$API/sessions/$SESSION_ID/close"
```

Output download URLs require the same authentication; do not assume they are
public sharing links. Byte-range requests support playback. Each result has
actual metadata, SHA-256, size, full-decode evidence and a review status.
`completed` means the file passed technical delivery verification, not human
approval or guaranteed creative/reference fidelity. `human_approved` remains
false; perceptual review claims must be checked separately.

Close returns202/`closing`; poll until `closed`. It stops only owned workers,
invalidates further approval/feedback execution and retains input, source,
conversation history and output files. It does not delete data, log out Google,
kill unrelated sessions or automatically adopt/close the existing standalone
video build. A closed API session cannot be reopened through this v1 API;
create a fresh session if required. Its retained AGY history can still be
resumed manually by a trusted server operator outside this API.

## 5. States, retries, limits and recovery

| State | Meaning / required action |
|---|---|
| analysis_queued | Waiting for the single supervised execution slot. |
| analysing | Reference download/inspection and read-only AGY plan are running. |
| awaiting_approval | Review `analysis`; explicit current-plan approval is required. |
| goal_queued | Approval recorded; generation is queued, not yet proven running. |
| starting_goal | CLI is starting; native goal acknowledgement is being checked. |
| generating | Native goal accepted and running. |
| verifying | Goal declared completion; actual media validation is running. |
| completed | Technical output verified; still needs human/creative review. |
| blocked | An operation failed, timed out or became uncertain; evidence retained. |
| closing / closed | Worker termination requested / confirmed; files retained. |

All mutation requests require an `Idempotency-Key` of8-160 printable ASCII
characters. Use a new key for each different operation. Retry the exact same
request with the same key after a network timeout; it returns the original
response without repeating the operation. Reusing a key with a changed body or
different route returns409. An old idempotent response may describe the old
state; GET/session gives current state.

Limits: one active job at a time (analysis or generation); additional jobs
queue. Reference download cap512MiB, duration cap600seconds, HTTPS/port443 only,
bounded redirects and public DNS addresses only. Analysis deadline is300seconds
plus a30-second shutdown margin after download. Each download is capped at180
seconds. Approved generation max_seconds accepts60-14400seconds (default14400).
At most50retained session records and20pending feedback entries per session.
Request JSON cap1MiB; dimensions must be even,240-3840; FPS24-60.

Each job is restricted to two available CPU cores and8GiB per-file writes, with
one renderer worker requested in the maker instructions. The supervisor and an
independent per-job watchdog enforce elapsed deadlines. The requested
max_repairs value (1-3) is passed to AGY; individual internal model repair cycles
are not independently countable by this v1 API and are not falsely claimed as
a hard OS-enforced limit. The wall-clock bound is enforced independently.

YOLO is not an OS sandbox. This API runs trusted administrator jobs under the
existing server account. It is not a multi-tenant untrusted-code service and
does not claim a hard RAM isolation boundary. API auth secrets are removed from
child environments. Do not submit secrets in briefs or expose this API without
authentication. Existing local skills, instructions and asset licences still
apply; code-only cannot guarantee every reference style is feasible.

Controller restarts retain the private registry and persistent job terminals.
Recovery reconciles existing processes before doing anything, rather than
blindly starting another render. Missing/uncertain workers become blocked.
The independent watchdog remains responsible for their deadline during an API
restart. Stop/close API sessions explicitly before intentionally decommissioning
the service. GET requests and status checks never start or resume generation.

Worker ownership uses exact launch-time PID/start-time records and descendant
tracking, not scans of unrelated processes' environments. The independent
watchdog uses the same recorded roots. Keep render workers attached to the job;
arbitrary detached/daemonised services are not a supported job pattern.

| HTTP status | Meaning |
|---|---|
| 200 /202 | Read succeeded / mutation accepted, possibly still queued. |
| 401 /403 | Login required / cross-origin mutation rejected. |
| 404 | Unknown session or output. |
| 409 | Stale approval, changed reference, duplicate conflicting request or wrong lifecycle state. |
| 413 /422 /429 | Size limit / invalid input or media / capacity limit. |

Operations/source: `/home/usr1/Code/agy-video-api`; service
`agy-video-api.service`; private data under `runtime/`. No API passwords or
private runtime records belong in Git or the public file server.

## Reuse an existing approved Video Workflow approach

The application Build reference sample action can provide source_plan with
text, source_id, reference_sha256 and approved:true. Approved text supports up to128000 characters; the complete proposal is retained without truncation. This imports the already
human-approved approach verbatim; reference bytes are checked before any AGY
process starts. AGY only acknowledges it in a fresh recorded conversation.
The API still exposes the exact current plan/version/hash as awaiting_approval,
and a separate authenticated approve call is required to start its native goal.
The app binds that approval to the operator's Build action and refuses to approve
a changed plan or different reference. Feedback-generated plans still require review.
Optional target.duration pins an approved excerpt length instead of forcing the
original reference duration; the final file is checked against this approved target.


## Continue a saved phone build after its processing deadline

With the phone reconnected, an authenticated operator can POST to
`/sessions/{id}/resume` with `continue_saved_work:true`, `plan_version` and
`plan_sha256`. This is explicit continuation authorization, not an automatic
extension. The API checks the unchanged approval/reference, live paired phone,
saved scene/audio and absence of another execution or pending phone render.
It keeps the same conversation and approved plan, pins the saved scene hashes,
and creates a new output revision with a fresh execution window using the
existing max_seconds. The native goal renders the saved scene first and then
checks the actual output. Startup-only recovery still accepts an empty object.
