Skip to main content
POST

Single Chat Stable

Send a prompt to a single AI model. Supports automatic or manual model selection with a 3-tier fallback chain.

Authentication Required

JWT Claims Extraction (Controller Lines 154-166):

Request Body

string
required
User message textValidation (Line 89):
Constraints:
  • MUST NOT be null
  • MUST NOT be whitespace-only
  • No max length enforced (provider-dependent)
string
Model name or "auto" for random selectionSelection Logic (Lines 102-108):
Behavior:
  • null, empty, "auto" → Random active model
  • Specific name → Direct model usage
string
System prompt (maps internally to request.System)Default: Implementation-defined and not guaranteed (provider-specific)
integer
Maximum response tokensLimits: Provider-dependent (checked at provider level)
number
Sampling temperatureRange: 0.0 (deterministic) to 2.0 (maximum creativity)Default: Not specified by API contract (provider-defined)
string
Session identifierAuto-generation (Line 87):
string
Thread UUID for message persistenceValidation (Lines 168-174):
Behavior: If invalid GUID or omitted, message not persisted to thread

Response

string
Always "ai.response" (Line 121)
object
boolean
Always true on success (Line 130)
string
AI response text (Line 131, mirrors output.content[0].text)
object
string
Echo of user prompt (Line 138)
string
"automatic" or "manual" (Line 139)
object
integer
Total duration in milliseconds (Lines 115, 140)Includes: Fallback retry time if primary provider failed
string
ISO8601 UTC timestamp (Line 147)

Side Effects

Database Mutations (Lines 150-174):
  1. message_logs table (Line 150):
  2. users table UPSERT (Lines 152-166):
    • Executes on every authenticated request
    • Idempotent UPSERT operation
    • Creates user if not exists, updates if exists
  3. thread_messages table (conditional, Lines 168-174):
    • Only if threadId provided and valid GUID
    • Links message to existing thread

Behavior

Provider Execution with Fallback (Lines 111, 528-593):
Timeout Implementation (Lines 540-552):
Model Selection (Lines 102-104):
  • null or "auto": Query ai_models table for random active model
  • Specific model name: Direct lookup in model registry
User Sync Timing:
  • Happens after AI inference (Lines 152-166)
  • Non-blocking (awaited)
  • Failure behavior not enforced by server contract
Thread Message Persistence:
  • Happens after AI inference and user sync
  • Only if threadId provided
  • Only if threadId valid GUID
  • Failure would bubble to 500 error

Error Conditions

Exception Messages (Lines 184, 428):
Inner exceptions exposed (provider timeout/connection errors visible to client)

Edge Cases

  1. Invalid threadId GUID: Silently skipped, no error (Line 170 guard)
  2. User sync failure: Logged as warning, request continues (implicit in UserSyncService)
  3. Model not found: Fallback chain triggered
  4. All providers fail: 500 error after ~135s
  5. Empty model name: Treated as "auto" (Line 102 check)

Rate Limits

No explicit rate limiting in controller. Provider-level limits apply:
  • Groq free tier: 30 req/min, 14,400 tokens/min
  • Groq paid tier: Higher limits (check API dashboard)
  • Bytez: Provider-dependent
429 Handling: Not explicitly caught, would trigger fallback chain