Skip to content

๐Ÿ’ฌ Advanced AI Chat Assistant & Multi-Model Stream โ€‹

LuxurAI features an ultra-responsive, highly optimized, and intelligence-routed chat engine. It is powered by a serverless-style multi-model orchestration layer that prioritizes speed, cost efficiency, and accuracy. This system token-by-token streams answers directly to the user's screen utilizing Server-Sent Events (SSE), completely eliminating high initial response latencies.

The entire text-generation and general chat pipeline does not rely on expensive American aggregators, choosing instead high-performance direct routes, direct API tunnels, and dynamic fallback networks.


๐Ÿง  Architectural Pipeline & Intelligence Routing โ€‹

When a message is submitted to the system, it is first evaluated by a high-speed routing engine. This engine runs a tiered evaluation strategy to determine the nature of the prompt and select the most efficient model, complexity multiplier, and search routing configuration.

mermaid
graph TD
    UserPrompt[User Message Submitted] -->|HTTP POST| ChatEndpoint["/api/stream/chat"]
    ChatEndpoint -->|Leader Analysis| GeminiLeader[Gemini 2.5 Flash Leader]
    GeminiLeader -->|Option A: Search Needed| WebSearch[Web Search API / Live Data]
    GeminiLeader -->|Option B: Decision Object| ModelRouter{Model Router}
    
    %% Model Branching
    ModelRouter -->|gemini_flash| FlashPool[Gemini 2.5 Flash Pool]
    ModelRouter -->|gemini_pro| ProPool[Gemini 2.5 Pro Pool]
    ModelRouter -->|deepseek| DSHash[Cloudflare Qwen Coder / DeepSeek V3]
    ModelRouter -->|deepseek_r1| R1Pool[Cloudflare QwQ / DeepSeek R1]
    
    %% Execution & Streaming
    FlashPool --> ExecutionStream[SSE Token Stream Generator]
    ProPool --> ExecutionStream
    DSHash --> ExecutionStream
    R1Pool --> ExecutionStream
    
    %% Fallback Loop
    ExecutionStream -->|HTTP 429/500 Error| FallbackChain[Dynamic Fallback Chain]
    FallbackChain -->|Next Best Provider| ExecutionStream
    
    ExecutionStream -->|Token Blocks| UserScreen[Frontend UI Token-by-Token Render]

1. The Leader Routing Engine โ€‹

Every request triggers a background invocation of a Gemini 2.5 Flash Leader routing model. Running on system instructions with temperature: 0.1 and maxOutputTokens: 256, the leader evaluates the prompt structure and returns a JSON payload containing the ideal model choice, complexity tier, and search requirements:

json
{
  "model_choice": "deepseek",
  "complexity": "high",
  "needs_search": false,
  "reason": "Request requires complex Python script optimization and bug fixing."
}
  • Dynamic Keyword Fallback: If the Gemini Leader encounters strict API rate limits or network issues, the backend instantly falls back to a regex-based Keyword Routing Engine to ensure zero user interruption. For example, keywords like def , class , import , or javascript dynamically route prompts to deepseek code models.

๐ŸŽ›๏ธ Supported Models & Specialized Fallback Chains โ€‹

LuxurAI maintains a robust list of fallback models. If a primary provider returns a 429 Too Many Requests or 502 Bad Gateway, the pipeline automatically catches the exception and routes the request to the next provider in the chain:

Model Choice IDSpecialized CapabilitiesPrimary ProviderSecondary Fallback Chain
gemini_flashGeneral discussion, creative writing, fast Q&AGemini 2.5 Flash (Backend keys)Shuffled Community Keys $\rightarrow$ DeepSeek V4 Flash $\rightarrow$ Gemma 3 27B $\rightarrow$ Llama-3.1-8B (Groq) $\rightarrow$ Cerebras $\rightarrow$ G0 Paid Key
gemini_proStructured analysis, document parsing, researchGemini 2.5 Pro (Backend keys)Shuffled Community Keys $\rightarrow$ DeepSeek R1 $\rightarrow$ Phi-4 (OR) $\rightarrow$ Groq Reasoning $\rightarrow$ G0 Paid Key
deepseekAdvanced coding, full-stack dev, debuggingCloudflare Qwen 32B CoderOpenRouter Qwen 32B $\rightarrow$ DeepSeek V4 Flash $\rightarrow$ Groq $\rightarrow$ Gemma 3 27B $\rightarrow$ Cerebras $\rightarrow$ Gemini Flash
deepseek_r1Mathematical proofs, complex logic puzzlesCloudflare QwQ 32B (Reasoning)DeepSeek R1 (Direct) $\rightarrow$ Phi-4 $\rightarrow$ Groq Gemma2 $\rightarrow$ Cerebras Large $\rightarrow$ Gemini Pro
qwenWeb components, React, CSS styling, HTML templatesCloudflare Qwen 32BOR Qwen3.5 Flash $\rightarrow$ DeepSeek $\rightarrow$ Groq $\rightarrow$ Gemma 3 27B $\rightarrow$ Cerebras

๐Ÿ’ฐ Economic Cost Calculations (Daily Quotas & Multipliers) โ€‹

The platform provides a highly generous freemium hybrid charging framework designed to prevent programmatic abuse while keeping casual interactions free:

1. The 100,000 Daily Token Free Quota โ€‹

  • Free Quota: Each user account is credited with 100,000 Free Input Tokens per day (resets dynamically at 00:00 UTC).
  • Input Surcharge (Over Limit): Once the daily quota of 100K tokens is depleted, input tokens are charged at a rate of 1 LC per 20 tokens (equivalent to 0.05 LC/token).
  • Rough Calculation: 1 Token $\approx$ 4 characters of plain text.

2. Output Token and Complexity Surcharges โ€‹

Output generation is calculated by the number of non-empty lines generated multiplied by a complexity multiplier determined by the leader router:

$$\text{Output Cost (LC)} = \text{Generated Lines} \times 0.20 \text{ LC/line} \times \text{Complexity Multiplier}$$

  • Low Complexity (0.50x Multiplier): 0.10 LC/line (e.g. trivial questions, short single-line corrections).
  • Medium Complexity (0.75x Multiplier): 0.15 LC/line (e.g. standard descriptions, general coding help).
  • High Complexity (1.00x Multiplier): 0.20 LC/line (e.g. large system designs, full-class templates).
  • Minimum Response Cost: The platform enforces a rigid minimum fee of 0.5 LC per chargeable response to cover gateway connection overheads.

๐Ÿ”Œ API Endpoints & SSE Streaming Protocol โ€‹

To stream real-time chat tokens, developers must open a persistent HTTP connection to the Server-Sent Events endpoint:

1. Initiate Streaming Connection โ€‹

  • Endpoint: POST /api/stream/chat
  • Headers:
    http
    Content-Type: application/json
    Authorization: Bearer <your_session_token>
  • Payload:
    json
    {
      "messages": [
        {"role": "user", "content": "How do I implement custom middleware in FastAPI?"}
      ],
      "system": "You are a professional Python engineer. Answer in concise markdown with code blocks."
    }

2. Event Stream Structure โ€‹

The server returns a text/event-stream returning data chunks:

  1. start event: Initial connection confirmation and token verification.
    http
    data: {"type": "start", "usage": {}}
  2. token events: Text tokens sent chunk-by-chunk in real time.
    http
    data: {"type": "token", "text": "To"}
    data: {"type": "token", "text": " create"}
    data: {"type": "token", "text": " a"}
  3. done event: Signals completion, containing the full response content.
    http
    data: {"type": "done", "full_text": "To create a custom middleware..."}

๐ŸŽจ UI & Styling Configurations โ€‹

The chat frontend is highly customized for developer speed and aesthetic comfort. Custom elements are declared inside frontend/pages/chat.html and styled via frontend/assets/css/theme.css:

  • Code Blocks Markdown Rendering: Code blocks are auto-detected and wrapped in premium dark cards with pre-configured Copy Buttons.
  • Auto-Scrolling Anchors: Smooth transitions hook the viewport directly to the most recent token generated.
  • Premium Typography: Utilizes system font stacks (-apple-system, BlinkMacSystemFont, Segoe UI, Roboto) optimized for visual scanning.

TIP

Optimizing Multi-Turn Token Budgets Because the chat assistant processes input history, long conversations consume input tokens more quickly. Consider starting a New Chat Session once the topic shifts to reset the chat context, preserving your daily 100K free token quota.

Proprietary & Confidential ยท Powered by LuxurAI