9Router Gateway & Model Config
Relevant source files
The following files were used as context for generating this wiki page:
9Router provides a centralized AI gateway and multi-provider management system for the LV.AI project. It acts as an OpenAI-compatible interface that routes requests to various Large Language Models (LLMs), primarily utilizing DeepSeek V4 backends. The system integrates NeXify's routing logic with a high-performance caching layer to optimize token usage and response times for construction-specific AI tasks.
Sources: CLAUDE.md:46-52, README.md:19-27
Gateway Architecture
The 9Router infrastructure runs as a Docker-Compose stack on a Virtual Private Server (VPS). It consists of two primary services: niner-router, which handles the routing logic, and headroom, which manages context optimization and token caching.
The diagram shows the request flow from the Vercel AI SDK through the caching and routing layers to the final model backends.
Sources: CLAUDE.md:46-52
Components and Endpoints
The gateway exposes two primary endpoints depending on the environment. For local development or deployments on the same VPS, it uses a direct IP address. For public or remote access (such as Vercel deployments), it utilizes a Cloudflare Tunnel.
| Component | Port / Protocol | Description |
|---|---|---|
niner-router | Port 20128 | Main Next.js-based routing engine |
headroom | Port 8788 | Context optimization and token caching |
| Local Endpoint | http://127.0.0.1:20128/v1 | Used for services on the same VPS |
| Public Endpoint | https://ai-router.nexifyai.cloud/v1 | Public HTTPS via Cloudflare Tunnel |
Sources: CLAUDE.md:46-52, README.md:61-63
Model Configuration
The system uses a curated list of models optimized for different construction industry tasks, such as generating Bill of Quantities (LV), price mirrors (Preisspiegel), and technical analysis.
Curated Chat Models
LV.AI configures four primary models through 9Router. Each serves a specific purpose in the AVA (Ausschreibung, Vergabe, Abrechnung) workflow.
| Model ID | Provider | Name | Primary Use Case |
|---|---|---|---|
nexifyai-combo-llm | NeXify | NeXify Combo LLM | Default round-robin (Pro/Flash) |
ds/deepseek-v4-flash | DeepSeek | DeepSeek V4 Flash | Fast, token-efficient title generation |
ds/deepseek-v4-pro | DeepSeek | DeepSeek V4 Pro | Highest quality AVA document generation |
ds/deepseek-reasoner | DeepSeek | DeepSeek Reasoner | Complex technical or legal cases |
Sources: CLAUDE.md:53-56, lib/ai/models-config.test.ts:25-50
Default Selections
The application enforces specific model selections for background tasks to ensure efficiency and accuracy.
- Default Chat Model:
nexifyai-combo-llmis the standard for user interactions. - Title Model:
ds/deepseek-v4-flashis used exclusively for summarizing chat messages into short titles (2-5 German words).
Sources: lib/ai/models-config.test.ts:7-23, lib/ai/prompts.ts:168-175
Token Optimization & Caching
The gateway implements several strategies to minimize latency and costs.
- Headroom Caching: Identical prompt prefixes are cached at the gateway level to reduce re-computation.
- Round-Robin Distribution: The
combo-llmdistributes load between Flash and Pro versions to balance speed and depth. - Prompt Modularization (T21/T22): System prompts are split into stable and dynamic parts. The stable parts (Role, Expertise, Language) are cached, while dynamic parts (Project Context, Geo-location) change per request.
The sequence shows how the Headroom component intercepts requests to provide cached results for stable prompt components.
Sources: CLAUDE.md:57-58, lib/ai/prompts.ts:98-135
Environment Configuration
Access to the 9Router gateway requires two mandatory environment variables. These variables configure the Vercel AI SDK to point away from standard OpenAI endpoints toward the NeXify infrastructure.
# Required Configuration in .env
OPENAI_API_KEY: "9Router API Key"
OPENAI_BASE_URL: "https://ai-router.nexifyai.cloud/v1"
Sources: README.md:61-63, CLAUDE.md:56
Summary
The 9Router Gateway & Model Config system centralizes AI access for LV.AI. By utilizing a Dockerized routing stack and specific DeepSeek model variants, the architecture provides high-quality German-language AVA expertise while maintaining cost efficiency through intelligent token caching and modular prompt structures.