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

# Autenticacion

> Aprende como autenticarte con la API de InnovaTrading

## API Keys

Todas las solicitudes a la API requieren autenticacion usando un Bearer token en el header `Authorization`.

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

## Obtener tu API Key

<Info>
  Durante el periodo beta, puedes usar cualquier string con **10 o mas caracteres** como tu API key.
  Esto te permite empezar a probar inmediatamente sin registro.
</Info>

**Ejemplos de API keys validas:**

* `mi_clave_test_123` (18 chars)
* `desarrollador_2024` (18 chars)
* `abcdefghij` (10 chars - minimo)

<Warning>
  **Proximamente:** Panel de gestion de API keys. Por ahora, elige una clave unica que te identifique.
</Warning>

## Usando tu API Key

<CodeGroup>
  ```bash cURL theme={null}
  curl https://api.innova-trading.com/api/external/bars \
    -H "Authorization: Bearer mi_clave_test_123"
  ```

  ```python Python theme={null}
  import requests

  API_KEY = "mi_clave_test_123"

  response = requests.get(
      "https://api.innova-trading.com/api/external/bars",
      params={"symbol": "EURUSD", "timeframe": 60},
      headers={"Authorization": f"Bearer {API_KEY}"}
  )
  ```

  ```javascript JavaScript theme={null}
  const API_KEY = "mi_clave_test_123";

  const response = await fetch(
    "https://api.innova-trading.com/api/external/bars?symbol=EURUSD&timeframe=60",
    {
      headers: { Authorization: `Bearer ${API_KEY}` }
    }
  );
  ```
</CodeGroup>

## Buenas Practicas de Seguridad

<CardGroup cols={2}>
  <Card title="Nunca expongas en codigo cliente" icon="eye-slash">
    Las API keys solo deben usarse del lado del servidor. Nunca las incluyas en JavaScript frontend.
  </Card>

  <Card title="Usa variables de entorno" icon="lock">
    Guarda tu API key en variables de entorno, no en el codigo fuente.
  </Card>

  <Card title="Usa claves unicas" icon="key">
    Elige un string unico para identificar tus solicitudes.
  </Card>

  <Card title="Mantenla secreta" icon="user-secret">
    No compartas tu API key publicamente (ej: en repos de GitHub).
  </Card>
</CardGroup>

## Variables de Entorno

<CodeGroup>
  ```bash .env theme={null}
  INNOVA_API_KEY=mi_clave_test_123
  ```

  ```python Python theme={null}
  import os

  API_KEY = os.environ.get("INNOVA_API_KEY")
  ```

  ```javascript JavaScript theme={null}
  const API_KEY = process.env.INNOVA_API_KEY;
  ```
</CodeGroup>

## Respuestas de Error

### 401 No Autorizado

API key faltante o invalida:

```json theme={null}
{
  "error": "unauthorized",
  "message": "Missing Authorization header"
}
```

```json theme={null}
{
  "error": "unauthorized",
  "message": "Invalid API key"
}
```

<Note>
  Las API keys deben tener al menos 10 caracteres. Claves mas cortas seran rechazadas.
</Note>

### 403 Prohibido

API key valida pero sin acceso al recurso solicitado:

```json theme={null}
{
  "error": "forbidden",
  "message": "Symbol XAUUSD not allowed for your API key",
  "allowed_symbols": ["EURUSD", "GBPUSD", "USDJPY"]
}
```

## Simbolos y Timeframes Disponibles

Por defecto, todas las API keys tienen acceso a:

| Simbolos                       | Timeframes              |
| ------------------------------ | ----------------------- |
| EURUSD, GBPUSD, USDJPY, XAUUSD | 1m, 5m, 15m, 1H, 4H, 1D |

## Limite de Solicitudes

Las API keys tienen limite para prevenir abuso:

| Limite                       | Valor |
| ---------------------------- | ----- |
| Solicitudes/Hora             | 100   |
| Barras maximas por solicitud | 1,000 |

Cuando excedes el limite, recibiras:

```json theme={null}
{
  "error": "rate_limit_exceeded",
  "message": "Too many requests. Please wait before retrying.",
  "retry_after": 60
}
```

<Tip>
  Usa backoff exponencial cuando alcances el limite. Comienza con 1 segundo de espera y duplicalo con cada reintento.
</Tip>
