> ## Documentation Index
> Fetch the complete documentation index at: https://docs.vidjutsu.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication

> Using, rotating, and recovering your API key

<Info>
  Need to get your first API key? See [Get your API key](/get-api-key).
</Info>

## Using your key

Pass your API key as a Bearer token in the `Authorization` header on every request:

```bash theme={null}
curl https://api.vidjutsu.ai/v1/usage \
  -H "Authorization: Bearer $VIDJUTSU_API_KEY"
```

If you're using the CLI, your key is stored in `~/.vidjutsu/config.json` and sent automatically.

## Storing your key safely

Your key is a secret. Treat it like a password.

| Do                                                      | Don't                    |
| ------------------------------------------------------- | ------------------------ |
| Store in environment variables                          | Commit to git            |
| Use `.env` files (add to `.gitignore`)                  | Share in Slack/email     |
| Use your platform's secrets manager (Vercel, AWS, etc.) | Hardcode in source files |

```bash theme={null}
# .env
VIDJUTSU_API_KEY=vj_live_...
```

For a portable credentials file:

```bash theme={null}
vidjutsu auth --export
# Writes ~/.vidjutsu/credentials.json
```

## Rotating your key

If your key is compromised, rotate it immediately. The old key is invalidated instantly.

```bash theme={null}
curl -X POST https://api.vidjutsu.ai/v1/api_keys/rotate \
  -H "Authorization: Bearer $VIDJUTSU_API_KEY"
```

The response contains your new key. Store it securely — the old one no longer works.

## Recovering a lost key

If you lost your key, recover it via email verification:

<Tabs>
  <Tab title="CLI">
    ```bash theme={null}
    vidjutsu auth --recover <your_email>
    # Check your email for a 6-digit code
    ```

    ```bash theme={null}
    vidjutsu auth --verify --email <your_email> --code 847291
    ```
  </Tab>

  <Tab title="API">
    Request a verification code:

    ```bash theme={null}
    curl -X POST https://api.vidjutsu.ai/v1/auth/verify/request \
      -H "Content-Type: application/json" \
      -d '{ "email": "<your_email>" }'
    ```

    Confirm the code to get your key back:

    ```bash theme={null}
    curl -X POST https://api.vidjutsu.ai/v1/auth/verify/confirm \
      -H "Content-Type: application/json" \
      -d '{ "email": "<your_email>", "code": "847291" }'
    ```
  </Tab>
</Tabs>
