# Autenticacion

Todos los endpoints de la API de ReallyQuickEmails usan el mismo metodo de autenticacion: **Bearer Token** con tu Secret Key.

***

## Bearer Token

Envia tu **Secret Key** (`sk_proj_...`) en el header `Authorization`:

```
Authorization: Bearer sk_proj_tu_secret_key
```

Este patron funciona para **todos** los endpoints:

* `POST /v1/send-email`
* `POST /v1/send-template-email`
* `POST /v1/send-batch`
* `POST /domains/register`
* `GET /domains/:domain/dns-records`
* `POST /domains/:domain/verify`
* `GET /domains/:domain/status`
* `GET /domains?domain=`
* `POST /domains/:domain/recreate`
* `DELETE /domains/:domain`
* `PUT /domains/:domain/sender`
* `POST /domains/verify-email`
* `GET /domains/verify-email/status`

### Ejemplo

```bash
curl -X POST https://api.reallyquickemails.com/v1/send-email \
  -H "Authorization: Bearer sk_proj_tu_secret_key" \
  -H "Content-Type: application/json" \
  -d '{
    "recipient_email": "cliente@ejemplo.com",
    "sender_email": "ventas@tudominio.com",
    "subject": "Confirmacion de pedido",
    "html_body": "<h1>Pedido confirmado</h1>"
  }'
```

### Como funciona

1. El servidor extrae la Secret Key del header
2. Busca el proyecto correspondiente en la base de datos
3. Si la key es valida, el `projectId` se deriva automaticamente — no necesitas enviarlo

***

## Donde encontrar tu Secret Key

1. Ingresa al [dashboard de ReallyQuickEmails](https://app.reallyquickemails.com).
2. Selecciona tu proyecto.
3. Ve a **Configuracion** > **API Keys**.
4. Copia tu **Secret Key** (comienza con `sk_proj_`).

***

## Respuestas de error

**Key faltante o formato incorrecto (401):**

```json
{
  "error": "Missing or invalid API key. Use: Authorization: Bearer sk_proj_..."
}
```

**Key invalida (401):**

```json
{
  "error": "Invalid API key"
}
```

***

## Errores comunes

| Codigo | Causa                                                 | Solucion                                           |
| ------ | ----------------------------------------------------- | -------------------------------------------------- |
| `401`  | Falta el header `Authorization`                       | Agrega `Authorization: Bearer sk_proj_...`         |
| `401`  | Formato incorrecto (sin "Bearer " o sin "sk\_proj\_") | Asegurate de usar `Bearer sk_proj_...` con espacio |
| `401`  | Key invalida o revocada                               | Genera una nueva desde Configuracion > API Keys    |
| `500`  | Error de servicio de autenticacion                    | Reintenta en unos segundos                         |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://reallyquickemails.gitbook.io/reallyquickemails-docs/guias/authentication.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
