Retour à la documentation
Server

Server API & LLM Proxy

Auth, provider routing, model configuration, billing, and WebSocket endpoints.

12 min de lecture

The server is an Actix-Web service written in Rust that provides authentication, model configuration, LLM proxying, and billing. Desktop and mobile clients depend on it for secure provider routing and streaming responses. The server runs on dedicated infrastructure in two regions: Hetzner (EU) at api-eu.plantocode.com and InterServer (US) at 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.