# Auth.md

Videxu makes 30 to 45 second explainer videos from a website. Programs reach it three ways, all over the same account:

- REST API: `https://api.videxu.com/v1` ([OpenAPI](https://api.videxu.com/openapi.json))
- Remote MCP server: `https://api.videxu.com/mcp` (Streamable HTTP, JSON responses; tools are listed by `tools/list`)
- CLI: `videxu`, a Python package that uses the REST API (see below)

Prices and checkout links need no credential: `GET /v1/pricing`, `POST /v1/checkout`. Everything about an account (videos left, the videos themselves, making a new video) needs one of the credentials below. Payment always happens on Shopify's checkout page, by a person; no credential can buy anything.

## Permissions

- `read`: the account's videos left, plan and videos, with download links.
- `write`: also make new videos. Each new video uses one of the account's videos left. There is a limit of 10 new videos per account every 24 hours.

## Option 1: an API key from the account owner

The account owner signs in at [app.videxu.com](https://app.videxu.com) and creates a key under "API, MCP & CLI". A key is read-only unless the owner ticks "Can make videos". The key is shown once.

Send it on every REST or MCP request:

```text
Authorization: Bearer <VIDEXU_API_KEY>
```

Keep keys in the client's secret storage. Never put them in prompts, URLs, logs or screenshots. The owner deletes a key on the same dashboard page; deleted keys stop working at once.

## Option 2: OAuth 2.1 for apps (Claude, ChatGPT and other MCP clients)

The [authorization-server metadata](https://api.videxu.com/.well-known/oauth-authorization-server) lists every endpoint. In short:

1. Register the app (redirect URIs: https, or http only to localhost; public clients only):

   ```http
   POST /oauth/register HTTP/1.1
   Host: api.videxu.com
   Content-Type: application/json

   {"client_name":"<APP_NAME>","redirect_uris":["https://your.app/oauth/callback"],"token_endpoint_auth_method":"none"}
   ```

   Success is HTTP 201 with `client_id`.
2. Send the person to `https://app.videxu.com/oauth/authorize` with `response_type=code`, an S256 `code_challenge`, `state` and `scope` (`read` or `read write`). They sign in to Videxu and click Allow or Deny.
3. Exchange the code at `POST https://api.videxu.com/oauth/token` (`grant_type=authorization_code`, `code`, `redirect_uri`, `client_id`, `code_verifier`). Access tokens last one hour.
4. Renew with `grant_type=refresh_token`. Refresh tokens rotate on every use and last 30 days. Reusing an old refresh token ends the connection.
5. Revoke with `POST https://api.videxu.com/oauth/revoke` and `token=<token>`.

The [protected-resource metadata](https://api.videxu.com/.well-known/oauth-protected-resource/mcp) for the MCP server names this authorization server. A request without a valid token gets HTTP 401 with a `WWW-Authenticate` header that points to it. The owner disconnects apps on the dashboard.

## Option 3: agent registration approved by the owner (service_auth)

For an agent working for an existing Videxu account. It doesn't create an account, grant videos or buy anything.

1. With the person's permission, register. `scope` is `read` or `read write`:

   ```http
   POST /agent/identity HTTP/1.1
   Host: api.videxu.com
   Content-Type: application/json

   {"type":"service_auth","login_hint":"<THEIR_VIDEXU_EMAIL>","scope":"read write","agent_name":"<YOUR_AGENT_NAME>"}
   ```

   Success is HTTP 201 with `claim_token`, `expires_in` (600 seconds), `interval` (5) and `claim` (`user_code`, `verification_uri`). Store `claim_token` privately in the agent client's secret storage.

   The same flow also accepts `{"type":"identity_assertion","assertion_type":"verified_email","email":"<THEIR_VIDEXU_EMAIL>"}`. Either way the email counts as verified only after the account owner signs in and types the code.
2. Show the person `claim.verification_uri` and the 6-digit `claim.user_code`. They sign in to Videxu, type the code and approve or decline. Never approve for them.
3. Poll for the credential, at most every 5 seconds:

   ```http
   POST /oauth/token HTTP/1.1
   Host: api.videxu.com
   Content-Type: application/x-www-form-urlencoded

   grant_type=urn%3Aworkos%3Aagent-auth%3Agrant-type%3Aclaim&claim_token=<CLAIM_TOKEN>
   ```

   Responses:
   - `authorization_pending`: wait and poll again.
   - `slow_down`: wait longer between polls.
   - `access_denied`, `expired_token` or `invalid_grant`: stop.
4. After approval, the response is HTTP 200 with `access_token` (one hour), `refresh_token` (30 days, rotates on use), `token_type: Bearer` and `scope`. Tokens are handed out once. Store them in secret storage and send `Authorization: Bearer <ACCESS_TOKEN>` on REST and MCP requests. Renew with `grant_type=refresh_token` as in option 2.

To get a new code and link for the same request, before it expires, `POST https://api.videxu.com/agent/identity/claim` with `claim_token` and `email`.

## The CLI

Download [videxu-1.0.0-py3-none-any.whl](https://videxu.com/downloads/videxu-1.0.0-py3-none-any.whl) (Python 3.9 or newer, no other dependencies), then:

```text
python -m pip install ./videxu-1.0.0-py3-none-any.whl
videxu login
videxu account
videxu make --notes "What this video should say"
videxu videos
videxu download <video id>
```

`videxu login` asks for an API key without showing it and keeps it in your user config folder. In scripts, set `VIDEXU_API_KEY` instead. Add `--json` for machine-readable output.

## Errors

- `401`: the credential is missing, deleted, expired or revoked. Stop and ask the owner for a new one.
- `402 no_videos_left`: the account has no videos left. Offer the person a checkout link (`POST /v1/checkout`); they pay on Shopify.
- `403 insufficient_scope`: the credential is read-only. Ask the owner for one that can make videos.
- `429`: too many requests, or the 10-videos-per-24-hours limit. Try again later.

Questions: support@videxu.com
