ドキュメントに戻る
サーバー

サーバーAPI & LLMプロキシ

認証、プロバイダールーティング、モデル設定、課金、WebSocketエンドポイント。

12分 で読めます

サーバーは認証、モデル設定、LLMプロキシ、課金を提供するRustで書かれたActix-Webサービスです。デスクトップおよびモバイルクライアントは、安全なプロバイダールーティングとストリーミングレスポンスのためにこれに依存しています。サーバーは2つのリージョンの専用インフラストラクチャで稼働しています:Hetzner(EU)はapi-eu.plantocode.com、InterServer(US)はapi-us.plantocode.com。

サーバーリクエストフロー

クライアント、APIルート、LLMプロキシを示す図。

サーバーリクエストフロー図
Click to expand
サーバーリクエストフローのプレースホルダー。

認証エンドポイント

認証はAuth0とPKCEフローを使用します:

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.