Volver a Documentación
Servidor

API del Servidor y Proxy LLM

Autenticación, enrutamiento de proveedores, configuración de modelos, facturación y endpoints WebSocket.

12 min de lectura

El servidor es un servicio Actix-Web escrito en Rust que proporciona autenticación, configuración de modelos, proxy LLM y facturación. Los clientes de escritorio y móviles dependen de él para enrutamiento seguro de proveedores y respuestas en streaming. El servidor se ejecuta en infraestructura dedicada en dos regiones: Hetzner (UE) en api-eu.plantocode.com e InterServer (EE.UU.) en api-us.plantocode.com.

Server request flow

Diagram showing clients, API routes, and the LLM proxy.

Server request flow diagram
Click to expand
Placeholder for the server request flow.

Authentication endpoints

Authentication uses Auth0 with PKCE flow:

Auth endpoints:

  • /auth/auth0/initiate-login - Start Auth0 PKCE flow
  • /auth0/poll-status - Poll for login completion
  • /auth0/finalize-login - Exchange code for tokens
  • /api/auth/userinfo - Get authenticated user info
  • /api/auth/logout - Invalidate session

LLM proxy and streaming

The LLM proxy normalizes requests across providers and streams responses:

LLM proxy routes:

  • /api/llm/chat/completions - Text completions (streaming)
  • /api/llm/video/analyze - Multimodal video analysis
  • /api/audio/transcriptions - Voice transcription

Supported providers:

  • OpenAI (GPT-4, GPT-4o, Whisper)
  • Anthropic (Claude 3.5/4)
  • Google (Gemini 2.0/2.5)
  • X.AI (Grok)
  • OpenRouter (aggregated providers)

Configuration endpoints

Configuration and model metadata endpoints:

Configuration endpoints:

  • /api/config/runtime - Runtime AI configuration
  • /api/providers - Provider list and status
  • /api/models - Model metadata and context windows
  • /api/system-prompts - System prompt templates
  • /config/regions - Available server regions

Device management

Device registration and push notifications:

Device endpoints:

  • /api/devices - Device registration and listing
  • /api/devices/heartbeat - Device health checks
  • /api/devices/push-token - Push notification registration
  • /api/notifications - Notification delivery

WebSocket endpoints

Real-time communication via WebSocket:

WebSocket routes:

  • /ws/device-link - Desktop/mobile relay channel
  • /ws/events - Real-time event streaming

Server-side storage:

  • PostgreSQL - Users, billing, audit logs, settings
  • Redis - Rate limiting, pending charges, sessions
  • RLS policies - Row-level security per user

Key source files

  • server/src/main.rs - Application entry and route configuration
  • server/src/routes.rs - Route definitions
  • server/src/handlers/proxy/ - LLM proxy handlers
  • server/src/handlers/auth/ - Authentication handlers
  • server/src/clients/ - Provider client implementations
  • server/src/streaming/ - SSE streaming adapters
  • server/src/middleware/ - Auth and rate limiting
  • server/src/services/ - Business logic services

Continue learning

Understand how the server integrates with the desktop app and manages LLM provider routing.