문서로 돌아가기
서버

서버 API 및 LLM 프록시

인증, 프로바이더 라우팅, 모델 구성, 청구, WebSocket 엔드포인트.

12분 읽기

서버는 인증, 모델 구성, LLM 프록싱, 청구를 제공하는 Rust로 작성된 Actix-Web 서비스입니다. 데스크톱 및 모바일 클라이언트는 안전한 프로바이더 라우팅과 스트리밍 응답을 위해 이에 의존합니다. 서버는 두 지역의 전용 인프라에서 실행됩니다: Hetzner (EU) api-eu.plantocode.com과 InterServer (US) api-us.plantocode.com.

서버 요청 흐름

클라이언트, API 라우트, LLM 프록시를 보여주는 다이어그램.

서버 요청 흐름 다이어그램
Click to expand
서버 요청 흐름을 위한 플레이스홀더.

인증 엔드포인트

인증은 PKCE 흐름과 함께 Auth0를 사용합니다:

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 프록시 및 스트리밍

LLM 프록시는 프로바이더 간 요청을 정규화하고 응답을 스트리밍합니다:

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:

  • /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 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 엔드포인트

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.