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

# Autenticación API

> Como autenticar requests a pan API

## API Key

El método principal de autenticación es usando una API key en el header `Authorization`:

```bash theme={null}
Authorization: Bearer pan_sk_tu_api_key
```

### Ejemplo

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET https://api.pan.tech/v1/yields \
    -H "Authorization: Bearer pan_sk_a1b2c3d4e5f6..."
  ```

  ```javascript JavaScript theme={null}
  fetch('https://api.pan.tech/v1/yields', {
    headers: {
      'Authorization': `Bearer ${process.env.PAN_API_KEY}`
    }
  })
  ```

  ```python Python theme={null}
  requests.get(
      'https://api.pan.tech/v1/yields',
      headers={'Authorization': f'Bearer {API_KEY}'}
  )
  ```
</CodeGroup>

### Formato de API Key

```
pan_sk_a1b2c3d4e5f6789012345678901234567890abcdef1234567890abcdef123456
```

* Prefijo: `pan_sk_`
* Longitud: 64 caracteres hexadecimales

### Obtener API Key

1. Registrate en [app.pan.tech](https://app.pan.tech)
2. Ve a **Settings > API Keys**
3. Click en **Create New Key**
4. Copia la key inmediatamente

<Warning>
  La API key solo se muestra una vez. Guardala de forma segura.
</Warning>

## X402 Protocol

Para endpoints de solo lectura, puedes usar el protocolo X402 de micropagos:

| Header            | Valor                 |
| ----------------- | --------------------- |
| `X-Payment-Proof` | Proof de pago en USDC |

### Endpoints Soportados

| Endpoint                | X402 |
| ----------------------- | ---- |
| GET /wallets/:userId    | Si   |
| GET /balances/:walletId | Si   |
| GET /yields             | Si   |
| GET /intents/:intentId  | Si   |
| POST /wallets           | No   |
| POST /intents           | No   |

### Costo

\$0.001 USD por request en USDC (Base, Ethereum, o Sei)

## Errores de Autenticación

### 401 Unauthorized

```json theme={null}
{
  "error": "UNAUTHORIZED",
  "message": "Invalid or missing API key"
}
```

**Causas:**

* API key no incluida
* API key mal formateada
* API key revocada

### 403 Forbidden

```json theme={null}
{
  "error": "FORBIDDEN",
  "message": "Wallet limit exceeded for your plan"
}
```

**Causas:**

* Límite de plan excedido
* Créditos agotados
* Acceso a recurso no permitido

## Mejores Practicas

<CardGroup cols={2}>
  <Card title="Usa variables de entorno" icon="lock">
    ```bash theme={null}
    export PAN_API_KEY=pan_sk_...
    ```
  </Card>

  <Card title="No commitees la key" icon="git">
    ```gitignore theme={null}
    .env
    .env.local
    ```
  </Card>

  <Card title="Rota periodicamente" icon="rotate">
    Crea nuevas keys cada 90 dias
  </Card>

  <Card title="Keys por entorno" icon="layer-group">
    Usa keys separadas para dev/staging/prod
  </Card>
</CardGroup>
