Numination← Documentación

<<<<<<< HEAD

Numination · API Reference

v7.0.0 · Numi OT · "La IA para los que resuelven problemas"

Documentación completa de los ~75 endpoints de la API de Numination.


Tabla de contenidos


Introducción

URL base

Producción:   https://numination.app
Desarrollo:   http://localhost:8080

Convenciones

Estructura de respuesta

Éxito:

{
  "ok": true,
  "data": { ... }
}

Error:

{
  "ok": false,
  "error": "Mensaje legible",
  "code": "codigo_de_error",
  "requestId": "abc12345"
}

Headers comunes

Todas las respuestas incluyen:

Header Descripción
X-Request-Id ID único del request (para correlacionar logs)
X-RateLimit-Limit Límite del rate limit actual
X-RateLimit-Remaining Requests restantes en la ventana
X-RateLimit-Reset Segundos hasta que se resetee

Las respuestas de error incluyen:

Header Descripción
Retry-After Segundos a esperar antes de reintentar (solo 429/423)

Autenticación

Métodos soportados

  1. Google OAuth (Identity Services)
  2. GitHub OAuth
  3. Email + contraseña

Sesión

Todas las sesiones son JWT firmados guardados en cookie numination_session:

Set-Cookie: numination_session=<JWT>; HttpOnly; SameSite=Lax; Secure; Path=/

El JWT incluye:

{
  "sub": "user-uuid",
  "email": "user@example.com",
  "role": "student",
  "ver": 1,
  "jti": "abc123",
  "iat": 1728000000,
  "exp": 1730592000
}

Cómo autenticar requests

Desde el navegador:

fetch('/api/chats', {
  credentials: 'include',   // ← incluye cookies
})

Desde curl:

curl -b "numination_session=<JWT>" https://numination.app/api/chats

Desde Postman/Insomnia:

Endpoints que NO requieren auth


Formato de errores

Todos los errores siguen este formato:

{
  "ok": false,
  "error": "Mensaje humano en español",
  "code": "codigo_maquina",
  "requestId": "abc12345",
  "details": { "field": "email" }
}

Códigos de error

Auth:

Chats:

Memorias:

IA:

Límites:

Base de datos:

Validación:

Internos:


Rate limiting

Numination tiene 3 capas de rate limiting:

1 · Por IP (global)

2 · Por usuario (todos los endpoints)

3 · Cuotas de negocio (por plan)

Solo aplica a endpoints que consumen IA (/api/chat/stream).

Comportamiento al exceder

Rate limit (429):

{
  "ok": false,
  "error": "Llegaste al límite por minuto. Esperá un momento.",
  "code": "limit_minute",
  "retryAfter": 42
}

Cuota de negocio (429):

{
  "ok": false,
  "error": "Límite diario alcanzado (20 mensajes). Mejora tu plan para continuar.",
  "code": "limit_daily",
  "retryAfter": 86400
}

Strikes

Si golpeás el rate limit repetidamente:


Códigos de estado

Código Significado
200 OK
201 Creado
204 Sin contenido (OPTIONS)
400 Petición inválida
401 No autenticado
403 Sin permisos / injection
404 No encontrado
409 Conflicto (ej. email duplicado)
413 Payload demasiado grande
422 Entidad no procesable
423 Cuenta bloqueada
429 Rate limit
500 Error interno
502 Motor externo falló
503 Servicio no disponible
504 Timeout

Health & Version

GET /api/health

Estado completo del sistema.

Response 200:

{
  "ok": true,
  "service": "numination",
  "version": "7.0.0",
  "codename": "Numi-OT.01",
  "env": "production",
  "uptime": 12456,
  "priority": {
    "text": ["groq", "gemini", "nvidia"],
    "files": ["gemini", "nvidia", "groq"]
  },
  "models": {
    "GROQ": "openai/gpt-oss-120b",
    "GEMINI": "gemini-3.6-flash",
    "KIMI": "moonshotai/kimi-k3"
  },
  "keys": {
    "groq": true,
    "gemini_1": true,
    "gemini_2": true,
    "gemini_3": true,
    "nvidia": true
  },
  "geminiPool": [
    { "id": 1, "cooldown": false, "requests": 42, "errors": 0 },
    { "id": 2, "cooldown": false, "requests": 38, "errors": 0 },
    { "id": 3, "cooldown": true, "requests": 30, "errors": 2 }
  ],
  "database": {
    "connected": true,
    "ping": { "ok": true, "latencyMs": 17 }
  },
  "limits": {
    "ok": true,
    "latencyMs": 42,
    "failMode": "open"
  },
  "analytics": {
    "ok": true,
    "latencyMs": 38,
    "bufferSize": 3
  },
  "auth": {
    "session": true,
    "email": "user@example.com"
  },
  "runtime": {
    "node": "v24.21.0",
    "memory": { "rss": "97 MB", "heap": "23 MB" }
  },
  "ts": "2026-10-12T02:05:41.156Z"
}

GET /api/version

Versión mínima.

Response 200:

{
  "ok": true,
  "version": "7.0.0",
  "name": "Numination",
  "codename": "Numi-OT.01",
  "env": "production",
  "models": { ... }
}

GET /api/ping

Ping rápido.

Response 200:

{
  "ok": true,
  "pong": 1728000000000
}

Auth

POST /api/auth/signup

Crear cuenta con email + contraseña.

Body:

{
  "email": "user@example.com",
  "password": "Password123",
  "name": "Álvaro"
}

Validaciones:

Response 201:

{
  "ok": true,
  "user": {
    "id": "abc-123",
    "email": "user@example.com",
    "name": "Álvaro",
    "picture": null,
    "role": "student",
    "plan": "free",
    "provider": "email",
    "emailVerified": true,
    "hasPassword": true,
    "createdAt": "2026-10-12T02:00:00.000Z"
  }
}

Cookie numination_session se setea automáticamente.

Errores:

Ejemplo curl:

curl -X POST https://numination.app/api/auth/signup \
  -H "Content-Type: application/json" \
  -d '{
    "email": "test@example.com",
    "password": "Password123",
    "name": "Test"
  }' \
  -c cookies.txt

POST /api/auth/login

Iniciar sesión con email + contraseña.

Body:

{
  "email": "user@example.com",
  "password": "Password123",
  "remember": true
}

Response 200:

{
  "ok": true,
  "user": { ... }
}

Errores:

Rate limits:


POST /api/auth/google

Login con Google Identity Services.

Body:

{
  "credential": "<JWT de Google>",
  "remember": true
}

El credential es el ID token que entrega GIS en el frontend.

Response 200:

{
  "ok": true,
  "user": { ... }
}

Errores:


GET /api/auth/github

Inicia el flow OAuth de GitHub.

Response 302: redirect a https://github.com/login/oauth/authorize?...

Después del flow, redirige a /chat.html y setea la cookie.

Query params de error:


GET /api/auth/github/callback

Callback del flow OAuth. No llamar manualmente.


GET /api/auth/me

Usuario actual.

Response 200:

{
  "ok": true,
  "user": {
    "id": "abc-123",
    "email": "user@example.com",
    "name": "Álvaro",
    "picture": "https://...",
    "role": "student",
    "plan": "free",
    "provider": "google",
    "emailVerified": true,
    "hasPassword": false,
    "createdAt": "2026-10-10T19:43:29.092Z",
    "lastLoginAt": "2026-10-12T02:00:00.000Z"
  }
}

Si no hay sesión:

{
  "ok": false,
  "user": null
}

GET /api/auth/session

Info detallada de la sesión.

Response 200:

{
  "ok": true,
  "authenticated": true,
  "revoked": false,
  "issuedAt": "2026-10-12T02:00:00.000Z",
  "expiresAt": "2026-11-11T02:00:00.000Z",
  "ageSeconds": 245,
  "expiresInSeconds": 2591755,
  "fresh": true,
  "provider": "google",
  "jti": "abc123def456",
  "user": { ... }
}

fresh: true significa que la sesión tiene < 5 min, requerido para operaciones sensibles.


GET /api/auth/check

¿Hay sesión activa?

Response 200:

{ "authenticated": true }

GET /api/auth/providers

Proveedores de auth disponibles.

Response 200:

{
  "ok": true,
  "providers": {
    "google": { "enabled": true, "label": "Google" },
    "github": { "enabled": true, "label": "GitHub" },
    "email": { "enabled": true, "label": "Correo y contraseña" },
    "emailPasswordReset": { "enabled": true, "emailDelivery": true },
    "emailVerification": { "enabled": true, "emailDelivery": true }
  }
}

POST /api/auth/logout

Cerrar sesión.

Response 200:

{ "ok": true }

Limpia la cookie.


POST /api/auth/logout-all

Cerrar sesión en TODOS los dispositivos.

Response 200:

{
  "ok": true,
  "invalidatedAt": "2026-10-12T02:00:00.000Z"
}

Incrementa auth_version del usuario, invalidando todos los JWT anteriores.


POST /api/auth/change-password

Cambiar contraseña. Requiere sesión fresca (< 5 min).

Body:

{
  "currentPassword": "OldPass123",
  "newPassword": "NewPass456"
}

Response 200:

{ "ok": true }

Errores:


POST /api/auth/forgot-password

Pedir reset de contraseña. Envía email.

Body:

{ "email": "user@example.com" }

Response 200 (siempre, no revela si el email existe):

{ "ok": true }

Rate limit: 3/hora por email, 10/hora por IP.

El email tiene un link a /reset-password.html?token=<token>. El token expira en 1 hora.


POST /api/auth/reset-password

Aplicar el reset con el token.

Body:

{
  "token": "abc123...",
  "newPassword": "NewPass456"
}

Response 200:

{ "ok": true }

Errores:


PATCH /api/auth/profile

Actualizar perfil.

Body:

{ "name": "Nuevo Nombre" }

Response 200:

{
  "ok": true,
  "user": { ... }
}

Validaciones:


DELETE /api/auth/account

Eliminar cuenta. Requiere sesión fresca + confirmación textual.

Body:

{ "confirm": "ELIMINAR" }

Response 200:

{ "ok": true }

Borra el usuario, sus chats, mensajes y memorias en una transacción.


GET /api/auth/audit

Ver eventos de seguridad recientes.

Response 200:

{
  "ok": true,
  "events": [
    {
      "ts": "2026-10-12T02:00:00.000Z",
      "event": "login.ok",
      "email": "user@example.com",
      "ip": "1.2.3.4"
    }
  ]
}

Solo muestra los últimos 30 eventos del usuario actual.


Chats

GET /api/chats

Listar chats del usuario.

Query params:

Response 200:

{
  "ok": true,
  "chats": [
    {
      "id": "uuid-1",
      "title": "Mi primer chat",
      "mode": "chat",
      "created_at": "2026-10-10T19:44:51.512Z",
      "updated_at": "2026-10-10T21:04:57.871Z"
    },
    {
      "id": "uuid-2",
      "title": "Código React",
      "mode": "coder",
      "created_at": "2026-10-10T20:11:59.678Z",
      "updated_at": "2026-10-10T20:13:08.178Z"
    }
  ]
}

POST /api/chats

Crear chat nuevo.

Body:

{
  "title": "Mi chat",
  "mode": "chat"
}

Response 201:

{
  "ok": true,
  "chat": {
    "id": "uuid-new",
    "title": "Mi chat",
    "mode": "chat",
    "created_at": "2026-10-12T02:00:00.000Z",
    "updated_at": "2026-10-12T02:00:00.000Z"
  }
}

Modes válidos: chat, coder, reasoning


GET /api/chats/:id

Obtener un chat con TODOS sus mensajes.

Response 200:

{
  "ok": true,
  "chat": {
    "id": "uuid-1",
    "title": "Mi chat",
    "mode": "chat",
    "created_at": "2026-10-10T19:44:51.512Z",
    "updated_at": "2026-10-10T21:04:57.871Z",
    "messages": [
      {
        "id": "msg-1",
        "chat_id": "uuid-1",
        "role": "user",
        "content": "Hola",
        "provider": null,
        "created_at": "2026-10-10T19:44:51.512Z"
      },
      {
        "id": "msg-2",
        "chat_id": "uuid-1",
        "role": "ai",
        "content": "¡Hola! ¿En qué puedo ayudarte?",
        "provider": "groq",
        "created_at": "2026-10-10T19:44:53.012Z"
      }
    ]
  }
}

PATCH /api/chats/:id

Renombrar chat.

Body:

{ "title": "Nuevo título" }

Response 200:

{
  "ok": true,
  "chat": { "id": "uuid-1", "title": "Nuevo título", ... }
}

DELETE /api/chats/:id

Eliminar chat y todos sus mensajes.

Response 200:

{ "ok": true }

POST /api/chats/:id/messages

Guardar un mensaje (usado por el frontend).

Body:

{
  "message": {
    "role": "user",
    "content": "Hola"
  }
}

Response 200:

{
  "ok": true,
  "message": {
    "id": "msg-new",
    "chat_id": "uuid-1",
    "role": "user",
    "content": "Hola",
    "created_at": "2026-10-12T02:00:00.000Z"
  }
}

GET /api/chats/search

Buscar chats por título.

Query params:

Response 200:

{
  "ok": true,
  "chats": [ ... ]
}

Chat & IA

POST /api/chat/stream

Endpoint principal del chat. Envía un mensaje y recibe la respuesta en streaming SSE.

Body:

{
  "message": "Explícame la fotosíntesis",
  "role": "student",
  "history": [
    { "role": "user", "content": "Hola" },
    { "role": "assistant", "content": "¡Hola! ¿En qué puedo ayudarte?" }
  ],
  "file": null,
  "incognito": false
}

Campos:

Response: text/event-stream

Formato SSE (una línea por evento):

data: {"meta":{"plan":"Free","restanteDia":20,"mode":"student","requestId":"abc123"}}

data: {"token":"La","done":false}

data: {"token":" fotosíntesis","done":false}

data: {"token":" es","done":false}

...

data: {"token":"","done":true,"provider":"groq"}

Tipos de eventos:

  1. meta — primer evento, info de sesión
  2. token — fragmento de la respuesta
  3. done — fin del stream (provider indica qué motor respondió)
  4. error — hubo un error

Evento de error:

data: {"error":"Los motores de IA están saturados.","done":true}

Evento con partial:

data: {"token":"","done":true,"provider":"groq","partial":true}

partial: true significa que el motor murió a mitad del stream.

Ejemplo curl:

curl -N -X POST https://numination.app/api/chat/stream \
  -H "Content-Type: application/json" \
  -b "numination_session=<JWT>" \
  -d '{
    "message": "di hola",
    "role": "student"
  }'

Ejemplo JS:

const response = await fetch('/api/chat/stream', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  credentials: 'include',
  body: JSON.stringify({
    message: 'Hola',
    role: 'student',
    history: [],
  }),
});

const reader = response.body.getReader();
const decoder = new TextDecoder();
let buffer = '';

while (true) {
  const { done, value } = await reader.read();
  if (done) break;

  buffer += decoder.decode(value, { stream: true });
  const lines = buffer.split('\n\n');
  buffer = lines.pop() || '';

  for (const line of lines) {
    if (!line.startsWith('data: ')) continue;
    const event = JSON.parse(line.slice(6));

    if (event.meta) console.log('Meta:', event.meta);
    if (event.token) process.stdout.write(event.token);
    if (event.done) console.log('\nDone:', event.provider);
    if (event.error) console.error('Error:', event.error);
  }
}

Errores:

Rate limits:

Motores (fallback automático):

  1. Groq (openai/gpt-oss-120b) — rápido, gratis
  2. Gemini (3 keys rotando) — potente
  3. Kimi K3 (NVIDIA NIM) — respaldo

Si un motor falla en el primer token, pasa al siguiente en 25s máximo.


POST /api/chat

Variante sin streaming. Mismo body que /api/chat/stream.

Response 200:

{
  "ok": true,
  "reply": "La fotosíntesis es...",
  "provider": "groq",
  "mode": "student",
  "durationMs": 1240
}

Cuándo usar: cuando no necesitás streaming (ej. bots, tests).


Memorias

GET /api/memories

Listar memorias del usuario.

Query params:

Response 200:

{
  "ok": true,
  "memories": [
    {
      "id": "mem-1",
      "user_id": "abc-123",
      "text": "Álvaro tiene 14 años",
      "title": "Álvaro tiene 14 años",
      "category": "general",
      "tags": ["perfil", "edad"],
      "pinned": true,
      "relevance": 8,
      "source": "chat",
      "use_count": 3,
      "last_used_at": "2026-10-12T01:00:00.000Z",
      "created_at": "2026-10-10T19:44:00.000Z",
      "updated_at": "2026-10-12T01:00:00.000Z"
    }
  ]
}

POST /api/memories

Crear memoria.

Body:

{
  "text": "El usuario prefiere ejemplos cortos",
  "title": "Preferencia: ejemplos cortos",
  "category": "preferences",
  "tags": ["preferencias", "estilo"],
  "pinned": false,
  "source": "manual"
}

Response 201:

{
  "ok": true,
  "memory": { ... }
}

Detección de duplicados:

Límite: 500 memorias por usuario (plan free).


GET /api/memories/:id

Obtener una memoria.

Response 200:

{
  "ok": true,
  "memory": { ... }
}

PATCH /api/memories/:id

Actualizar memoria.

Body:

{
  "text": "Nuevo texto",
  "category": "otra",
  "tags": ["a", "b"],
  "pinned": true,
  "relevance": 9
}

Response 200:

{
  "ok": true,
  "memory": { ... }
}

DELETE /api/memories/:id

Eliminar memoria.

Response 200:

{ "ok": true }

POST /api/memories/:id/pin

Toggle del pin.

Response 200:

{
  "ok": true,
  "memory": { "id": "mem-1", "pinned": true }
}

POST /api/memories/:id/use

Registrar uso de la memoria (incrementa use_count).

Response 200:

{
  "ok": true,
  "memory": {
    "id": "mem-1",
    "useCount": 4,
    "lastUsedAt": "2026-10-12T02:00:00.000Z"
  }
}

GET /api/memories/stats

Estadísticas de memorias.

Response 200:

{
  "ok": true,
  "total": 25,
  "pinned": 3,
  "byCategory": {
    "general": 15,
    "preferences": 5,
    "education": 5
  },
  "topTags": [
    { "tag": "perfil", "total": 8 },
    { "tag": "estudio", "total": 5 }
  ],
  "weekDelta": 3,
  "thisWeek": 5,
  "lastWeek": 2
}

GET /api/memories/tags

Lista de tags únicos.

Response 200:

{
  "ok": true,
  "tags": [
    { "tag": "perfil", "total": 8 },
    { "tag": "estudio", "total": 5 }
  ]
}

GET /api/memories/:id/related

Memorias relacionadas (comparten tags).

Response 200:

{
  "ok": true,
  "related": [ ... ]
}

POST /api/memories/bulk/delete

Eliminar varias memorias.

Body:

{ "ids": ["mem-1", "mem-2", "mem-3"] }

Response 200:

{
  "ok": true,
  "deleted": 3
}

POST /api/memories/bulk/update

Actualizar varias.

Body:

{
  "ids": ["mem-1", "mem-2"],
  "patch": {
    "pinned": true,
    "addTags": ["importante"],
    "removeTags": ["obsoleto"],
    "category": "importante"
  }
}

Response 200:

{
  "ok": true,
  "updated": 2
}

GET /api/memories/export

Exportar todas las memorias.

Query params:

Response 200: archivo con Content-Disposition: attachment.


DELETE /api/memories

Eliminar TODAS las memorias.

Body:

{ "confirm": "BORRAR TODO" }

Response 200:

{
  "ok": true,
  "deleted": 25
}

Proyectos

GET /api/projects

Listar proyectos.

Response 200:

{
  "ok": true,
  "projects": [
    {
      "id": "proj-1",
      "name": "Mi proyecto",
      "color": "#7c5eff",
      "type": "coder",
      "createdAt": "2026-10-12T02:00:00.000Z"
    }
  ]
}

POST /api/projects

Crear proyecto.

Body:

{
  "name": "Nuevo proyecto",
  "color": "#7c5eff",
  "type": "coder"
}

Response 201:

{
  "ok": true,
  "project": { ... }
}

PATCH /api/projects/:id

Actualizar.

Response 200:

{ "ok": true, "project": { ... } }

DELETE /api/projects/:id

Eliminar.

Response 200:

{ "ok": true }

Skills

GET /api/skills

Lista de skills disponibles.

Response 200:

{
  "ok": true,
  "skills": [
    {
      "id": "explain",
      "name": "Explicar",
      "desc": "Explica un concepto paso a paso",
      "category": "aprender",
      "icon": "book",
      "modes": ["chat", "coder", "reasoning"]
    }
  ],
  "categories": [
    { "id": "aprender", "label": "Aprender", "color": "#7c5eff" }
  ]
}

GET /api/skills/:id

Detalle de un skill.

Response 200:

{
  "ok": true,
  "skill": {
    "id": "explain",
    "name": "Explicar",
    "desc": "...",
    "category": "aprender",
    "icon": "book",
    "modes": ["chat", "coder", "reasoning"],
    "examples": ["Explícame la fotosíntesis"],
    "keywords": ["explica", "qué es"]
  }
}

POST /api/skills/detect

Detectar qué skill encaja con un prompt.

Body:

{ "text": "explícame la relatividad", "mode": "chat" }

Response 200:

{
  "ok": true,
  "skill": { "id": "explain", "name": "Explicar" },
  "score": 2,
  "all": [
    { "id": "explain", "score": 2 },
    { "id": "explain-simple", "score": 0 }
  ]
}

Conectores

GET /api/connectors

Lista de conectores disponibles.

Response 200:

{
  "ok": true,
  "connectors": [
    {
      "id": "wikipedia",
      "name": "Wikipedia",
      "description": "Busca y cita artículos en español",
      "category": "Educación",
      "timeoutMs": 8000,
      "cacheTtlMs": 300000
    }
  ]
}

Conectores disponibles:

  1. wikipedia · Wikipedia en español
  2. colombia · API Colombia (departamentos, municipios)
  3. trivia · Open Trivia (preguntas)
  4. countries · REST Countries
  5. nasa · NASA (astronomía)
  6. meteo · Open-Meteo (clima)
  7. dictionary · Free Dictionary
  8. quotable · Quotable (frases célebres)
  9. books · Google Books
  10. numbers · Numbers API
  11. wiktionary · Wiktionary
  12. holidays · Nager.Date (feriados)
  13. github · GitHub API

POST /api/connectors/:id/query

Ejecutar un conector.

Body: depende del conector. Ejemplo para wikipedia:

{ "query": "fotosíntesis", "lang": "es" }

Ejemplo para meteo:

{ "city": "Medellín" }

Response 200:

{
  "ok": true,
  "connector": "wikipedia",
  "result": {
    "title": "Fotosíntesis",
    "summary": "...",
    "url": "https://es.wikipedia.org/wiki/Fotosíntesis"
  },
  "cached": false,
  "durationMs": 234
}

Errores:


GET /api/connectors/:id/health

Health check de un conector.

Response 200:

{
  "ok": true,
  "connector": "wikipedia",
  "healthy": true,
  "latencyMs": 123
}

Email

GET /api/email/status

Estado del servicio de email.

Response 200:

{
  "ok": true,
  "configured": true,
  "provider": "resend",
  "fromEmail": "no-reply@numination.app"
}

POST /api/email/test

Enviar email de prueba. Solo admin.

Body:

{ "to": "test@example.com" }

Response 200:

{
  "ok": true,
  "messageId": "abc123"
}

GET /api/email/templates

Lista plantillas disponibles.

Response 200:

{
  "ok": true,
  "templates": [
    "reset_password",
    "verify_email",
    "welcome",
    "limit_warning"
  ]
}

GET /api/email/history

Historial de emails enviados al usuario actual.

Response 200:

{
  "ok": true,
  "emails": [
    {
      "id": "email-1",
      "type": "reset_password",
      "status": "delivered",
      "sentAt": "2026-10-12T02:00:00.000Z"
    }
  ]
}

Límites y uso

GET /api/limits/usage

Uso actual del usuario.

Response 200:

{
  "ok": true,
  "plan": "Free",
  "uso": {
    "hoy": 12,
    "dia": 12,
    "minuto": 1,
    "burst": 1,
    "mes": 87
  },
  "limites": {
    "porDia": 20,
    "porMin": 5,
    "porMinuto": 5,
    "porBurst": 3
  },
  "restanteDia": 8,
  "restanteMin": 4,
  "porcentaje": {
    "dia": 60,
    "minuto": 20
  },
  "resetAt": {
    "minuto": "2026-10-12T02:01:00.000Z",
    "dia": "2026-10-13T00:00:00.000Z",
    "mes": "2026-11-01T00:00:00.000Z"
  }
}

Headers:

X-RateLimit-Limit: 5
X-RateLimit-Remaining: 4
X-RateLimit-Reset: 47

Errores comunes

401 Unauthorized

{
  "ok": false,
  "error": "No autenticado",
  "code": "auth_no_session"
}

Solución: verificar que la cookie numination_session esté presente y válida.

403 Forbidden

{
  "ok": false,
  "error": "No puedo procesar esa instrucción. Reformúlala como una pregunta educativa.",
  "code": "chat_injection_blocked"
}

Solución: reformular el mensaje sin instrucciones de override.

429 Too Many Requests

{
  "ok": false,
  "error": "Límite diario alcanzado (20 mensajes). Mejora tu plan para continuar.",
  "code": "limit_daily",
  "retryAfter": 86400
}

Solución: esperar retryAfter segundos o upgrade de plan.

500 Internal Server Error

{
  "ok": false,
  "error": "Error interno del servidor",
  "code": "int_server_error",
  "requestId": "abc12345"
}

Solución: reportar con el requestId para buscar en logs.

502 Bad Gateway

{
  "ok": false,
  "error": "El motor está saturado.",
  "code": "ai_rate_limit",
  "details": {
    "engine": "groq",
    "status": 429
  }
}

Solución: reintentar en unos segundos.

504 Gateway Timeout

{
  "ok": false,
  "error": "El motor no respondió en el tiempo esperado.",
  "code": "ai_timeout"
}

Solución: reintentar; normalmente se resuelve solo.


Ejemplos avanzados

Flujo completo de auth con Google

// 1 · Login con Google (el frontend ya obtiene el credential)
const credential = '<JWT de Google>';

const res = await fetch('/api/auth/google', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  credentials: 'include',
  body: JSON.stringify({ credential, remember: true }),
});

const data = await res.json();
if (data.ok) {
  console.log('Usuario:', data.user);
  window.location.href = '/chat.html';
}

Flujo completo de chat con streaming

async function chat(message, history = []) {
  const response = await fetch('/api/chat/stream', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    credentials: 'include',
    body: JSON.stringify({
      message,
      role: 'student',
      history: history.slice(-12), // últimos 12
    }),
  });

  if (!response.ok) {
    const err = await response.json();
    throw new Error(err.error);
  }

  const reader = response.body.getReader();
  const decoder = new TextDecoder();
  let buffer = '';
  let fullText = '';

  while (true) {
    const { done, value } = await reader.read();
    if (done) break;

    buffer += decoder.decode(value, { stream: true });
    const lines = buffer.split('\n\n');
    buffer = lines.pop() || '';

    for (const line of lines) {
      if (!line.startsWith('data: ')) continue;
      try {
        const event = JSON.parse(line.slice(6));

        if (event.meta) {
          console.log('Plan:', event.meta.plan);
          console.log('Restante:', event.meta.restanteDia);
        }

        if (event.token) {
          fullText += event.token;
          process.stdout.write(event.token);
        }

        if (event.done) {
          console.log('\n\nMotor:', event.provider);
          return { text: fullText, provider: event.provider };
        }

        if (event.error) {
          throw new Error(event.error);
        }
      } catch (e) {
        // ignorar líneas no-JSON
      }
    }
  }
}

// Uso
const { text, provider } = await chat('Explícame la gravedad');
console.log(`\nRespuesta (${provider}): ${text}`);

Flujo de signup + verificación + login

// 1 · Signup
const signup = await fetch('/api/auth/signup', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  credentials: 'include',
  body: JSON.stringify({
    email: 'user@example.com',
    password: 'Password123',
    name: 'Test',
  }),
});
const signupData = await signup.json();

if (!signupData.ok) {
  if (signupData.code === 'auth_email_taken') {
    // Ya existe: ir a login
    return login();
  }
  throw new Error(signupData.error);
}

// 2 · Ya está logueado automáticamente (cookie seteada)
// Verificar:
const me = await fetch('/api/auth/me', { credentials: 'include' });
const meData = await me.json();
console.log('Logueado como:', meData.user.name);

// 3 · Ir al chat
window.location.href = '/chat.html';

Batch de memorias

async function importMemories(memoriesArray) {
  const results = await Promise.all(
    memoriesArray.map((text) =>
      fetch('/api/memories', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        credentials: 'include',
        body: JSON.stringify({ text, source: 'import' }),
      }).then((r) => r.json())
    )
  );

  const ok = results.filter((r) => r.ok).length;
  const duplicates = results.filter((r) => r.code === 'mem_duplicate').length;
  console.log(`Importadas: ${ok}, duplicadas: ${duplicates}`);
}

Verificar cuota antes de mandar

async function canSendMessage() {
  const res = await fetch('/api/limits/usage', { credentials: 'include' });
  const data = await res.json();

  if (!data.ok) return true; // fail-open
  if (data.restanteDia <= 0) {
    console.warn('Sin mensajes disponibles hoy');
    return false;
  }
  return true;
}

// Uso
if (await canSendMessage()) {
  await chat('Hola');
}

Webhooks (futuro)

Actualmente no hay webhooks. Si se agregan, se documentarán acá.


SDKs (futuro)

Actualmente no hay SDKs oficiales. Podés usar fetch directamente.


Changelog

v7.0.0 (2026-10-12)

v6.6.0 (2026-10-12)

v6.5.0 (2026-10-12)

v6.4.0 (2026-10-11)


Soporte


=======

Numination · API Reference

v7.0.0 · Numi OT · "La IA para los que resuelven problemas"

Documentación completa de los ~75 endpoints de la API de Numination.


Tabla de contenidos


Introducción

URL base

Producción:   https://numination.app
Desarrollo:   http://localhost:8080

Convenciones

Estructura de respuesta

Éxito:

{
  "ok": true,
  "data": { ... }
}

Error:

{
  "ok": false,
  "error": "Mensaje legible",
  "code": "codigo_de_error",
  "requestId": "abc12345"
}

Headers comunes

Todas las respuestas incluyen:

Header Descripción
X-Request-Id ID único del request (para correlacionar logs)
X-RateLimit-Limit Límite del rate limit actual
X-RateLimit-Remaining Requests restantes en la ventana
X-RateLimit-Reset Segundos hasta que se resetee

Las respuestas de error incluyen:

Header Descripción
Retry-After Segundos a esperar antes de reintentar (solo 429/423)

Autenticación

Métodos soportados

  1. Google OAuth (Identity Services)
  2. GitHub OAuth
  3. Email + contraseña

Sesión

Todas las sesiones son JWT firmados guardados en cookie numination_session:

Set-Cookie: numination_session=<JWT>; HttpOnly; SameSite=Lax; Secure; Path=/

El JWT incluye:

{
  "sub": "user-uuid",
  "email": "user@example.com",
  "role": "student",
  "ver": 1,
  "jti": "abc123",
  "iat": 1728000000,
  "exp": 1730592000
}

Cómo autenticar requests

Desde el navegador:

fetch('/api/chats', {
  credentials: 'include',   // ← incluye cookies
})

Desde curl:

curl -b "numination_session=<JWT>" https://numination.app/api/chats

Desde Postman/Insomnia:

Endpoints que NO requieren auth


Formato de errores

Todos los errores siguen este formato:

{
  "ok": false,
  "error": "Mensaje humano en español",
  "code": "codigo_maquina",
  "requestId": "abc12345",
  "details": { "field": "email" }
}

Códigos de error

Auth:

Chats:

Memorias:

IA:

Límites:

Base de datos:

Validación:

Internos:


Rate limiting

Numination tiene 3 capas de rate limiting:

1 · Por IP (global)

2 · Por usuario (todos los endpoints)

3 · Cuotas de negocio (por plan)

Solo aplica a endpoints que consumen IA (/api/chat/stream).

Comportamiento al exceder

Rate limit (429):

{
  "ok": false,
  "error": "Llegaste al límite por minuto. Esperá un momento.",
  "code": "limit_minute",
  "retryAfter": 42
}

Cuota de negocio (429):

{
  "ok": false,
  "error": "Límite diario alcanzado (20 mensajes). Mejora tu plan para continuar.",
  "code": "limit_daily",
  "retryAfter": 86400
}

Strikes

Si golpeás el rate limit repetidamente:


Códigos de estado

Código Significado
200 OK
201 Creado
204 Sin contenido (OPTIONS)
400 Petición inválida
401 No autenticado
403 Sin permisos / injection
404 No encontrado
409 Conflicto (ej. email duplicado)
413 Payload demasiado grande
422 Entidad no procesable
423 Cuenta bloqueada
429 Rate limit
500 Error interno
502 Motor externo falló
503 Servicio no disponible
504 Timeout

Health & Version

GET /api/health

Estado completo del sistema.

Response 200:

{
  "ok": true,
  "service": "numination",
  "version": "7.0.0",
  "codename": "Numi-OT.01",
  "env": "production",
  "uptime": 12456,
  "priority": {
    "text": ["groq", "gemini", "nvidia"],
    "files": ["gemini", "nvidia", "groq"]
  },
  "models": {
    "GROQ": "openai/gpt-oss-120b",
    "GEMINI": "gemini-3.6-flash",
    "KIMI": "moonshotai/kimi-k3"
  },
  "keys": {
    "groq": true,
    "gemini_1": true,
    "gemini_2": true,
    "gemini_3": true,
    "nvidia": true
  },
  "geminiPool": [
    { "id": 1, "cooldown": false, "requests": 42, "errors": 0 },
    { "id": 2, "cooldown": false, "requests": 38, "errors": 0 },
    { "id": 3, "cooldown": true, "requests": 30, "errors": 2 }
  ],
  "database": {
    "connected": true,
    "ping": { "ok": true, "latencyMs": 17 }
  },
  "limits": {
    "ok": true,
    "latencyMs": 42,
    "failMode": "open"
  },
  "analytics": {
    "ok": true,
    "latencyMs": 38,
    "bufferSize": 3
  },
  "auth": {
    "session": true,
    "email": "user@example.com"
  },
  "runtime": {
    "node": "v24.21.0",
    "memory": { "rss": "97 MB", "heap": "23 MB" }
  },
  "ts": "2026-10-12T02:05:41.156Z"
}

GET /api/version

Versión mínima.

Response 200:

{
  "ok": true,
  "version": "7.0.0",
  "name": "Numination",
  "codename": "Numi-OT.01",
  "env": "production",
  "models": { ... }
}

GET /api/ping

Ping rápido.

Response 200:

{
  "ok": true,
  "pong": 1728000000000
}

Auth

POST /api/auth/signup

Crear cuenta con email + contraseña.

Body:

{
  "email": "user@example.com",
  "password": "Password123",
  "name": "Álvaro"
}

Validaciones:

Response 201:

{
  "ok": true,
  "user": {
    "id": "abc-123",
    "email": "user@example.com",
    "name": "Álvaro",
    "picture": null,
    "role": "student",
    "plan": "free",
    "provider": "email",
    "emailVerified": true,
    "hasPassword": true,
    "createdAt": "2026-10-12T02:00:00.000Z"
  }
}

Cookie numination_session se setea automáticamente.

Errores:

Ejemplo curl:

curl -X POST https://numination.app/api/auth/signup \
  -H "Content-Type: application/json" \
  -d '{
    "email": "test@example.com",
    "password": "Password123",
    "name": "Test"
  }' \
  -c cookies.txt

POST /api/auth/login

Iniciar sesión con email + contraseña.

Body:

{
  "email": "user@example.com",
  "password": "Password123",
  "remember": true
}

Response 200:

{
  "ok": true,
  "user": { ... }
}

Errores:

Rate limits:


POST /api/auth/google

Login con Google Identity Services.

Body:

{
  "credential": "<JWT de Google>",
  "remember": true
}

El credential es el ID token que entrega GIS en el frontend.

Response 200:

{
  "ok": true,
  "user": { ... }
}

Errores:


GET /api/auth/github

Inicia el flow OAuth de GitHub.

Response 302: redirect a https://github.com/login/oauth/authorize?...

Después del flow, redirige a /chat.html y setea la cookie.

Query params de error:


GET /api/auth/github/callback

Callback del flow OAuth. No llamar manualmente.


GET /api/auth/me

Usuario actual.

Response 200:

{
  "ok": true,
  "user": {
    "id": "abc-123",
    "email": "user@example.com",
    "name": "Álvaro",
    "picture": "https://...",
    "role": "student",
    "plan": "free",
    "provider": "google",
    "emailVerified": true,
    "hasPassword": false,
    "createdAt": "2026-10-10T19:43:29.092Z",
    "lastLoginAt": "2026-10-12T02:00:00.000Z"
  }
}

Si no hay sesión:

{
  "ok": false,
  "user": null
}

GET /api/auth/session

Info detallada de la sesión.

Response 200:

{
  "ok": true,
  "authenticated": true,
  "revoked": false,
  "issuedAt": "2026-10-12T02:00:00.000Z",
  "expiresAt": "2026-11-11T02:00:00.000Z",
  "ageSeconds": 245,
  "expiresInSeconds": 2591755,
  "fresh": true,
  "provider": "google",
  "jti": "abc123def456",
  "user": { ... }
}

fresh: true significa que la sesión tiene < 5 min, requerido para operaciones sensibles.


GET /api/auth/check

¿Hay sesión activa?

Response 200:

{ "authenticated": true }

GET /api/auth/providers

Proveedores de auth disponibles.

Response 200:

{
  "ok": true,
  "providers": {
    "google": { "enabled": true, "label": "Google" },
    "github": { "enabled": true, "label": "GitHub" },
    "email": { "enabled": true, "label": "Correo y contraseña" },
    "emailPasswordReset": { "enabled": true, "emailDelivery": true },
    "emailVerification": { "enabled": true, "emailDelivery": true }
  }
}

POST /api/auth/logout

Cerrar sesión.

Response 200:

{ "ok": true }

Limpia la cookie.


POST /api/auth/logout-all

Cerrar sesión en TODOS los dispositivos.

Response 200:

{
  "ok": true,
  "invalidatedAt": "2026-10-12T02:00:00.000Z"
}

Incrementa auth_version del usuario, invalidando todos los JWT anteriores.


POST /api/auth/change-password

Cambiar contraseña. Requiere sesión fresca (< 5 min).

Body:

{
  "currentPassword": "OldPass123",
  "newPassword": "NewPass456"
}

Response 200:

{ "ok": true }

Errores:


POST /api/auth/forgot-password

Pedir reset de contraseña. Envía email.

Body:

{ "email": "user@example.com" }

Response 200 (siempre, no revela si el email existe):

{ "ok": true }

Rate limit: 3/hora por email, 10/hora por IP.

El email tiene un link a /reset-password.html?token=<token>. El token expira en 1 hora.


POST /api/auth/reset-password

Aplicar el reset con el token.

Body:

{
  "token": "abc123...",
  "newPassword": "NewPass456"
}

Response 200:

{ "ok": true }

Errores:


PATCH /api/auth/profile

Actualizar perfil.

Body:

{ "name": "Nuevo Nombre" }

Response 200:

{
  "ok": true,
  "user": { ... }
}

Validaciones:


DELETE /api/auth/account

Eliminar cuenta. Requiere sesión fresca + confirmación textual.

Body:

{ "confirm": "ELIMINAR" }

Response 200:

{ "ok": true }

Borra el usuario, sus chats, mensajes y memorias en una transacción.


GET /api/auth/audit

Ver eventos de seguridad recientes.

Response 200:

{
  "ok": true,
  "events": [
    {
      "ts": "2026-10-12T02:00:00.000Z",
      "event": "login.ok",
      "email": "user@example.com",
      "ip": "1.2.3.4"
    }
  ]
}

Solo muestra los últimos 30 eventos del usuario actual.


Chats

GET /api/chats

Listar chats del usuario.

Query params:

Response 200:

{
  "ok": true,
  "chats": [
    {
      "id": "uuid-1",
      "title": "Mi primer chat",
      "mode": "chat",
      "created_at": "2026-10-10T19:44:51.512Z",
      "updated_at": "2026-10-10T21:04:57.871Z"
    },
    {
      "id": "uuid-2",
      "title": "Código React",
      "mode": "coder",
      "created_at": "2026-10-10T20:11:59.678Z",
      "updated_at": "2026-10-10T20:13:08.178Z"
    }
  ]
}

POST /api/chats

Crear chat nuevo.

Body:

{
  "title": "Mi chat",
  "mode": "chat"
}

Response 201:

{
  "ok": true,
  "chat": {
    "id": "uuid-new",
    "title": "Mi chat",
    "mode": "chat",
    "created_at": "2026-10-12T02:00:00.000Z",
    "updated_at": "2026-10-12T02:00:00.000Z"
  }
}

Modes válidos: chat, coder, reasoning


GET /api/chats/:id

Obtener un chat con TODOS sus mensajes.

Response 200:

{
  "ok": true,
  "chat": {
    "id": "uuid-1",
    "title": "Mi chat",
    "mode": "chat",
    "created_at": "2026-10-10T19:44:51.512Z",
    "updated_at": "2026-10-10T21:04:57.871Z",
    "messages": [
      {
        "id": "msg-1",
        "chat_id": "uuid-1",
        "role": "user",
        "content": "Hola",
        "provider": null,
        "created_at": "2026-10-10T19:44:51.512Z"
      },
      {
        "id": "msg-2",
        "chat_id": "uuid-1",
        "role": "ai",
        "content": "¡Hola! ¿En qué puedo ayudarte?",
        "provider": "groq",
        "created_at": "2026-10-10T19:44:53.012Z"
      }
    ]
  }
}

PATCH /api/chats/:id

Renombrar chat.

Body:

{ "title": "Nuevo título" }

Response 200:

{
  "ok": true,
  "chat": { "id": "uuid-1", "title": "Nuevo título", ... }
}

DELETE /api/chats/:id

Eliminar chat y todos sus mensajes.

Response 200:

{ "ok": true }

POST /api/chats/:id/messages

Guardar un mensaje (usado por el frontend).

Body:

{
  "message": {
    "role": "user",
    "content": "Hola"
  }
}

Response 200:

{
  "ok": true,
  "message": {
    "id": "msg-new",
    "chat_id": "uuid-1",
    "role": "user",
    "content": "Hola",
    "created_at": "2026-10-12T02:00:00.000Z"
  }
}

GET /api/chats/search

Buscar chats por título.

Query params:

Response 200:

{
  "ok": true,
  "chats": [ ... ]
}

Chat & IA

POST /api/chat/stream

Endpoint principal del chat. Envía un mensaje y recibe la respuesta en streaming SSE.

Body:

{
  "message": "Explícame la fotosíntesis",
  "role": "student",
  "history": [
    { "role": "user", "content": "Hola" },
    { "role": "assistant", "content": "¡Hola! ¿En qué puedo ayudarte?" }
  ],
  "file": null,
  "incognito": false
}

Campos:

Response: text/event-stream

Formato SSE (una línea por evento):

data: {"meta":{"plan":"Free","restanteDia":20,"mode":"student","requestId":"abc123"}}

data: {"token":"La","done":false}

data: {"token":" fotosíntesis","done":false}

data: {"token":" es","done":false}

...

data: {"token":"","done":true,"provider":"groq"}

Tipos de eventos:

  1. meta — primer evento, info de sesión
  2. token — fragmento de la respuesta
  3. done — fin del stream (provider indica qué motor respondió)
  4. error — hubo un error

Evento de error:

data: {"error":"Los motores de IA están saturados.","done":true}

Evento con partial:

data: {"token":"","done":true,"provider":"groq","partial":true}

partial: true significa que el motor murió a mitad del stream.

Ejemplo curl:

curl -N -X POST https://numination.app/api/chat/stream \
  -H "Content-Type: application/json" \
  -b "numination_session=<JWT>" \
  -d '{
    "message": "di hola",
    "role": "student"
  }'

Ejemplo JS:

const response = await fetch('/api/chat/stream', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  credentials: 'include',
  body: JSON.stringify({
    message: 'Hola',
    role: 'student',
    history: [],
  }),
});

const reader = response.body.getReader();
const decoder = new TextDecoder();
let buffer = '';

while (true) {
  const { done, value } = await reader.read();
  if (done) break;

  buffer += decoder.decode(value, { stream: true });
  const lines = buffer.split('\n\n');
  buffer = lines.pop() || '';

  for (const line of lines) {
    if (!line.startsWith('data: ')) continue;
    const event = JSON.parse(line.slice(6));

    if (event.meta) console.log('Meta:', event.meta);
    if (event.token) process.stdout.write(event.token);
    if (event.done) console.log('\nDone:', event.provider);
    if (event.error) console.error('Error:', event.error);
  }
}

Errores:

Rate limits:

Motores (fallback automático):

  1. Groq (openai/gpt-oss-120b) — rápido, gratis
  2. Gemini (3 keys rotando) — potente
  3. Kimi K3 (NVIDIA NIM) — respaldo

Si un motor falla en el primer token, pasa al siguiente en 25s máximo.


POST /api/chat

Variante sin streaming. Mismo body que /api/chat/stream.

Response 200:

{
  "ok": true,
  "reply": "La fotosíntesis es...",
  "provider": "groq",
  "mode": "student",
  "durationMs": 1240
}

Cuándo usar: cuando no necesitás streaming (ej. bots, tests).


Memorias

GET /api/memories

Listar memorias del usuario.

Query params:

Response 200:

{
  "ok": true,
  "memories": [
    {
      "id": "mem-1",
      "user_id": "abc-123",
      "text": "Álvaro tiene 14 años",
      "title": "Álvaro tiene 14 años",
      "category": "general",
      "tags": ["perfil", "edad"],
      "pinned": true,
      "relevance": 8,
      "source": "chat",
      "use_count": 3,
      "last_used_at": "2026-10-12T01:00:00.000Z",
      "created_at": "2026-10-10T19:44:00.000Z",
      "updated_at": "2026-10-12T01:00:00.000Z"
    }
  ]
}

POST /api/memories

Crear memoria.

Body:

{
  "text": "El usuario prefiere ejemplos cortos",
  "title": "Preferencia: ejemplos cortos",
  "category": "preferences",
  "tags": ["preferencias", "estilo"],
  "pinned": false,
  "source": "manual"
}

Response 201:

{
  "ok": true,
  "memory": { ... }
}

Detección de duplicados:

Límite: 500 memorias por usuario (plan free).


GET /api/memories/:id

Obtener una memoria.

Response 200:

{
  "ok": true,
  "memory": { ... }
}

PATCH /api/memories/:id

Actualizar memoria.

Body:

{
  "text": "Nuevo texto",
  "category": "otra",
  "tags": ["a", "b"],
  "pinned": true,
  "relevance": 9
}

Response 200:

{
  "ok": true,
  "memory": { ... }
}

DELETE /api/memories/:id

Eliminar memoria.

Response 200:

{ "ok": true }

POST /api/memories/:id/pin

Toggle del pin.

Response 200:

{
  "ok": true,
  "memory": { "id": "mem-1", "pinned": true }
}

POST /api/memories/:id/use

Registrar uso de la memoria (incrementa use_count).

Response 200:

{
  "ok": true,
  "memory": {
    "id": "mem-1",
    "useCount": 4,
    "lastUsedAt": "2026-10-12T02:00:00.000Z"
  }
}

GET /api/memories/stats

Estadísticas de memorias.

Response 200:

{
  "ok": true,
  "total": 25,
  "pinned": 3,
  "byCategory": {
    "general": 15,
    "preferences": 5,
    "education": 5
  },
  "topTags": [
    { "tag": "perfil", "total": 8 },
    { "tag": "estudio", "total": 5 }
  ],
  "weekDelta": 3,
  "thisWeek": 5,
  "lastWeek": 2
}

GET /api/memories/tags

Lista de tags únicos.

Response 200:

{
  "ok": true,
  "tags": [
    { "tag": "perfil", "total": 8 },
    { "tag": "estudio", "total": 5 }
  ]
}

GET /api/memories/:id/related

Memorias relacionadas (comparten tags).

Response 200:

{
  "ok": true,
  "related": [ ... ]
}

POST /api/memories/bulk/delete

Eliminar varias memorias.

Body:

{ "ids": ["mem-1", "mem-2", "mem-3"] }

Response 200:

{
  "ok": true,
  "deleted": 3
}

POST /api/memories/bulk/update

Actualizar varias.

Body:

{
  "ids": ["mem-1", "mem-2"],
  "patch": {
    "pinned": true,
    "addTags": ["importante"],
    "removeTags": ["obsoleto"],
    "category": "importante"
  }
}

Response 200:

{
  "ok": true,
  "updated": 2
}

GET /api/memories/export

Exportar todas las memorias.

Query params:

Response 200: archivo con Content-Disposition: attachment.


DELETE /api/memories

Eliminar TODAS las memorias.

Body:

{ "confirm": "BORRAR TODO" }

Response 200:

{
  "ok": true,
  "deleted": 25
}

Proyectos

GET /api/projects

Listar proyectos.

Response 200:

{
  "ok": true,
  "projects": [
    {
      "id": "proj-1",
      "name": "Mi proyecto",
      "color": "#7c5eff",
      "type": "coder",
      "createdAt": "2026-10-12T02:00:00.000Z"
    }
  ]
}

POST /api/projects

Crear proyecto.

Body:

{
  "name": "Nuevo proyecto",
  "color": "#7c5eff",
  "type": "coder"
}

Response 201:

{
  "ok": true,
  "project": { ... }
}

PATCH /api/projects/:id

Actualizar.

Response 200:

{ "ok": true, "project": { ... } }

DELETE /api/projects/:id

Eliminar.

Response 200:

{ "ok": true }

Skills

GET /api/skills

Lista de skills disponibles.

Response 200:

{
  "ok": true,
  "skills": [
    {
      "id": "explain",
      "name": "Explicar",
      "desc": "Explica un concepto paso a paso",
      "category": "aprender",
      "icon": "book",
      "modes": ["chat", "coder", "reasoning"]
    }
  ],
  "categories": [
    { "id": "aprender", "label": "Aprender", "color": "#7c5eff" }
  ]
}

GET /api/skills/:id

Detalle de un skill.

Response 200:

{
  "ok": true,
  "skill": {
    "id": "explain",
    "name": "Explicar",
    "desc": "...",
    "category": "aprender",
    "icon": "book",
    "modes": ["chat", "coder", "reasoning"],
    "examples": ["Explícame la fotosíntesis"],
    "keywords": ["explica", "qué es"]
  }
}

POST /api/skills/detect

Detectar qué skill encaja con un prompt.

Body:

{ "text": "explícame la relatividad", "mode": "chat" }

Response 200:

{
  "ok": true,
  "skill": { "id": "explain", "name": "Explicar" },
  "score": 2,
  "all": [
    { "id": "explain", "score": 2 },
    { "id": "explain-simple", "score": 0 }
  ]
}

Conectores

GET /api/connectors

Lista de conectores disponibles.

Response 200:

{
  "ok": true,
  "connectors": [
    {
      "id": "wikipedia",
      "name": "Wikipedia",
      "description": "Busca y cita artículos en español",
      "category": "Educación",
      "timeoutMs": 8000,
      "cacheTtlMs": 300000
    }
  ]
}

Conectores disponibles:

  1. wikipedia · Wikipedia en español
  2. colombia · API Colombia (departamentos, municipios)
  3. trivia · Open Trivia (preguntas)
  4. countries · REST Countries
  5. nasa · NASA (astronomía)
  6. meteo · Open-Meteo (clima)
  7. dictionary · Free Dictionary
  8. quotable · Quotable (frases célebres)
  9. books · Google Books
  10. numbers · Numbers API
  11. wiktionary · Wiktionary
  12. holidays · Nager.Date (feriados)
  13. github · GitHub API

POST /api/connectors/:id/query

Ejecutar un conector.

Body: depende del conector. Ejemplo para wikipedia:

{ "query": "fotosíntesis", "lang": "es" }

Ejemplo para meteo:

{ "city": "Medellín" }

Response 200:

{
  "ok": true,
  "connector": "wikipedia",
  "result": {
    "title": "Fotosíntesis",
    "summary": "...",
    "url": "https://es.wikipedia.org/wiki/Fotosíntesis"
  },
  "cached": false,
  "durationMs": 234
}

Errores:


GET /api/connectors/:id/health

Health check de un conector.

Response 200:

{
  "ok": true,
  "connector": "wikipedia",
  "healthy": true,
  "latencyMs": 123
}

Email

GET /api/email/status

Estado del servicio de email.

Response 200:

{
  "ok": true,
  "configured": true,
  "provider": "resend",
  "fromEmail": "no-reply@numination.app"
}

POST /api/email/test

Enviar email de prueba. Solo admin.

Body:

{ "to": "test@example.com" }

Response 200:

{
  "ok": true,
  "messageId": "abc123"
}

GET /api/email/templates

Lista plantillas disponibles.

Response 200:

{
  "ok": true,
  "templates": [
    "reset_password",
    "verify_email",
    "welcome",
    "limit_warning"
  ]
}

GET /api/email/history

Historial de emails enviados al usuario actual.

Response 200:

{
  "ok": true,
  "emails": [
    {
      "id": "email-1",
      "type": "reset_password",
      "status": "delivered",
      "sentAt": "2026-10-12T02:00:00.000Z"
    }
  ]
}

Límites y uso

GET /api/limits/usage

Uso actual del usuario.

Response 200:

{
  "ok": true,
  "plan": "Free",
  "uso": {
    "hoy": 12,
    "dia": 12,
    "minuto": 1,
    "burst": 1,
    "mes": 87
  },
  "limites": {
    "porDia": 20,
    "porMin": 5,
    "porMinuto": 5,
    "porBurst": 3
  },
  "restanteDia": 8,
  "restanteMin": 4,
  "porcentaje": {
    "dia": 60,
    "minuto": 20
  },
  "resetAt": {
    "minuto": "2026-10-12T02:01:00.000Z",
    "dia": "2026-10-13T00:00:00.000Z",
    "mes": "2026-11-01T00:00:00.000Z"
  }
}

Headers:

X-RateLimit-Limit: 5
X-RateLimit-Remaining: 4
X-RateLimit-Reset: 47

Errores comunes

401 Unauthorized

{
  "ok": false,
  "error": "No autenticado",
  "code": "auth_no_session"
}

Solución: verificar que la cookie numination_session esté presente y válida.

403 Forbidden

{
  "ok": false,
  "error": "No puedo procesar esa instrucción. Reformúlala como una pregunta educativa.",
  "code": "chat_injection_blocked"
}

Solución: reformular el mensaje sin instrucciones de override.

429 Too Many Requests

{
  "ok": false,
  "error": "Límite diario alcanzado (20 mensajes). Mejora tu plan para continuar.",
  "code": "limit_daily",
  "retryAfter": 86400
}

Solución: esperar retryAfter segundos o upgrade de plan.

500 Internal Server Error

{
  "ok": false,
  "error": "Error interno del servidor",
  "code": "int_server_error",
  "requestId": "abc12345"
}

Solución: reportar con el requestId para buscar en logs.

502 Bad Gateway

{
  "ok": false,
  "error": "El motor está saturado.",
  "code": "ai_rate_limit",
  "details": {
    "engine": "groq",
    "status": 429
  }
}

Solución: reintentar en unos segundos.

504 Gateway Timeout

{
  "ok": false,
  "error": "El motor no respondió en el tiempo esperado.",
  "code": "ai_timeout"
}

Solución: reintentar; normalmente se resuelve solo.


Ejemplos avanzados

Flujo completo de auth con Google

// 1 · Login con Google (el frontend ya obtiene el credential)
const credential = '<JWT de Google>';

const res = await fetch('/api/auth/google', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  credentials: 'include',
  body: JSON.stringify({ credential, remember: true }),
});

const data = await res.json();
if (data.ok) {
  console.log('Usuario:', data.user);
  window.location.href = '/chat.html';
}

Flujo completo de chat con streaming

async function chat(message, history = []) {
  const response = await fetch('/api/chat/stream', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    credentials: 'include',
    body: JSON.stringify({
      message,
      role: 'student',
      history: history.slice(-12), // últimos 12
    }),
  });

  if (!response.ok) {
    const err = await response.json();
    throw new Error(err.error);
  }

  const reader = response.body.getReader();
  const decoder = new TextDecoder();
  let buffer = '';
  let fullText = '';

  while (true) {
    const { done, value } = await reader.read();
    if (done) break;

    buffer += decoder.decode(value, { stream: true });
    const lines = buffer.split('\n\n');
    buffer = lines.pop() || '';

    for (const line of lines) {
      if (!line.startsWith('data: ')) continue;
      try {
        const event = JSON.parse(line.slice(6));

        if (event.meta) {
          console.log('Plan:', event.meta.plan);
          console.log('Restante:', event.meta.restanteDia);
        }

        if (event.token) {
          fullText += event.token;
          process.stdout.write(event.token);
        }

        if (event.done) {
          console.log('\n\nMotor:', event.provider);
          return { text: fullText, provider: event.provider };
        }

        if (event.error) {
          throw new Error(event.error);
        }
      } catch (e) {
        // ignorar líneas no-JSON
      }
    }
  }
}

// Uso
const { text, provider } = await chat('Explícame la gravedad');
console.log(`\nRespuesta (${provider}): ${text}`);

Flujo de signup + verificación + login

// 1 · Signup
const signup = await fetch('/api/auth/signup', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  credentials: 'include',
  body: JSON.stringify({
    email: 'user@example.com',
    password: 'Password123',
    name: 'Test',
  }),
});
const signupData = await signup.json();

if (!signupData.ok) {
  if (signupData.code === 'auth_email_taken') {
    // Ya existe: ir a login
    return login();
  }
  throw new Error(signupData.error);
}

// 2 · Ya está logueado automáticamente (cookie seteada)
// Verificar:
const me = await fetch('/api/auth/me', { credentials: 'include' });
const meData = await me.json();
console.log('Logueado como:', meData.user.name);

// 3 · Ir al chat
window.location.href = '/chat.html';

Batch de memorias

async function importMemories(memoriesArray) {
  const results = await Promise.all(
    memoriesArray.map((text) =>
      fetch('/api/memories', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        credentials: 'include',
        body: JSON.stringify({ text, source: 'import' }),
      }).then((r) => r.json())
    )
  );

  const ok = results.filter((r) => r.ok).length;
  const duplicates = results.filter((r) => r.code === 'mem_duplicate').length;
  console.log(`Importadas: ${ok}, duplicadas: ${duplicates}`);
}

Verificar cuota antes de mandar

async function canSendMessage() {
  const res = await fetch('/api/limits/usage', { credentials: 'include' });
  const data = await res.json();

  if (!data.ok) return true; // fail-open
  if (data.restanteDia <= 0) {
    console.warn('Sin mensajes disponibles hoy');
    return false;
  }
  return true;
}

// Uso
if (await canSendMessage()) {
  await chat('Hola');
}

Webhooks (futuro)

Actualmente no hay webhooks. Si se agregan, se documentarán acá.


SDKs (futuro)

Actualmente no hay SDKs oficiales. Podés usar fetch directamente.


Changelog

v7.0.0 (2026-10-12)

v6.6.0 (2026-10-12)

v6.5.0 (2026-10-12)

v6.4.0 (2026-10-11)


Soporte


12facd91 (BACK TOTO) Numi es la clave.