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

# Authentication

> How to authenticate API requests to the Ansvisor server.

## API keys (Public Metrics API)

The versioned `/api/v1/*` endpoints on the **web app** authenticate with long-lived Ansvisor API keys (prefix `ans_`), created under **Settings → MCP & API Keys** in the dashboard:

```bash theme={null}
curl "https://app.ansvisor.com/api/v1/brands" \
  -H "Authorization: Bearer ans_..."
```

This is the right choice for external integrations — Looker Studio, Sheets, scripts, and the [MCP server](https://docs.ansvisor.com/guides/mcp-server.md). See the [Metrics API reference](https://docs.ansvisor.com/api-reference/metrics.md) for the endpoint list.

## App sign-in (OAuth) for the MCP server

AI apps such as Claude and ChatGPT can connect to the MCP endpoint, `https://app.ansvisor.com/api/mcp`, by signing the person in instead of with an API key. The web app is the authorization server (OAuth 2.1 with PKCE `S256`, as the MCP authorization spec 2025-11-25 has it), with the issuer `https://app.ansvisor.com`:

* An app finds it from the endpoint's `401` (`WWW-Authenticate: Bearer resource_metadata="https://app.ansvisor.com/.well-known/oauth-protected-resource/api/mcp", scope="mcp:read mcp:write"`), then `/.well-known/oauth-authorization-server`.
* It registers with a Client ID Metadata Document or by dynamic client registration (`POST /api/oauth/register`), sends the person to `/api/oauth/authorize`, and redeems the code at `/api/oauth/token`.
* Scopes: `mcp:read` (every `list_` and `get_` tool) and `mcp:write` (every other tool), which the person can leave out on the consent page.
* Access tokens (`ans_oat_…`) last an hour. Refresh tokens (`ans_ort_…`) last 30 days and rotate on every use. Both are bound to the MCP endpoint (RFC 8707 `resource`).
* A token acts as the person who allowed it, with their role and brand access. They see and disconnect it in **Settings → MCP & API Keys → Connected apps**; an app revokes its own at `/api/oauth/revoke` (RFC 7009).

These tokens work at `/api/mcp` only. The Metrics API (`/api/v1/*`), the REST routes under `/api/mcp/…` and the server's `/api/*` refuse them with `401`. On Ansvisor Cloud, app sign-in needs a paid plan; API keys work on every plan. The [MCP server guide](https://docs.ansvisor.com/guides/mcp-server.md#app-sign-in-oauth) has the full flow, lifetimes and errors.

## Bearer token

All `/api/*` endpoints on the Ansvisor server require a Supabase JWT bearer token in the `Authorization` header:

```bash theme={null}
curl https://api.your-domain.com/api/health \
  -H "Authorization: Bearer <SUPABASE_JWT>"
```

## Getting a token

The cleanest way is via the Supabase JS client in your own backend code:

```ts theme={null}
import { createClient } from "@supabase/supabase-js";

const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY);
const {
  data: { session },
} = await supabase.auth.signInWithPassword({
  email,
  password,
});

const token = session.access_token;
```

The web app does this automatically — every server action and fetch attaches the current session token transparently.

## Cron endpoints

A handful of internal endpoints under `/api/internal/*` (used by Vercel Cron and the Stripe success callback) authenticate via a shared `CRON_SECRET` instead of user tokens:

```bash theme={null}
curl -X POST https://api.your-domain.com/api/internal/daily-tracking \
  -H "Authorization: Bearer $CRON_SECRET"
```

The same secret must be configured on both sides (Vercel env + server env).

## Public endpoints

Three endpoints don't require any auth:

* `GET /t.js` — tracking pixel script
* `POST /track/{trackingCode}` — tracking pixel beacon (the tracking code identifies the brand; rate-limited)
* `GET /` — basic uptime check, returns `{ "status": "ok", "service": "aeo-server", "mode": "cloud" | "self-hosted", "timestamp": "..." }`

> [!NOTE]
>
> The `/api/health` endpoint IS auth-protected — by design, it returns the
> authenticated user's ID. For uptime monitoring, use `GET /` instead.

> [card] [Continue: Brands API](https://docs.ansvisor.com/api-reference/brands.md)
>
> CRUD endpoints for managing brands programmatically.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.