Inference is the centralized LLM gateway, multi-provider fallback router, and high-speed token streaming engine of the FRIDAY Universe. It aggregates and load-balances API keys across leading model providersβGroq, Cerebras, OpenRouter, and Google Geminiβproviding automated cascading fallback, calibrated multi-agent adversarial debate, and OpenAI-compatible endpoints with sub-second response times.
Inference is deployed within the unified private container mesh (friday_mesh) on Oracle Cloud Always Free and fronted by an automated HTTPS Caddy reverse proxy.
| Parameter | Value | Description |
|---|---|---|
| Identity | inference |
Specialist Gateway Agent |
| Internal Container Port | 8000 |
Application listen port |
| Host Port | 8004 |
Published host port on host |
| Internal Docker Mesh URL | http://inference:8000 |
Mesh discovery address for universe agents (friday, memora, etc.) |
| Public Gateway Route | https://friday-universe.duckdns.org/inference/* |
External public ingress routed via Caddy |
| Gateway Host | Oracle Cloud Always Free | 2 OCPUs, 12 GB RAM Ampere A1 (ARM64 / x86_64) |
| Runtime Base | python:3.11-slim |
Non-root appuser (UID 1000) with curl healthchecks |
FRIDAY UNIVERSE CONTAINER MESH (friday_mesh)
[Public Client] ββ HTTPS ββ> Caddy (Reverse Proxy :443)
|
+ββ /inference/* ββ> [Inference :8000] (Host: 8004)
| |
| +ββ Primary: Groq (LPU)
| +ββ Primary: Cerebras (Ultra-Fast)
| +ββ Primary: Google Gemini (3.8 Flash)
| +ββ Fallback: OpenRouter (Multi-model)
| +ββ Local: Self-Hosted Tier (llama.cpp/vLLM)
|
+ββ /friday/* ββ> [FRIDAY Core :10000]
+ββ /memora/* ββ> [Memora :8000]
Inference implements an automated cascading fallback ladder across providers. If a primary provider experiences rate limits (429), timeouts (504), socket failures, or service outages (503), Inference seamlessly cascades to the next healthy provider within the same request lifecycle without leaking provider exceptions to the client:
[Incoming Request]
β
βΌ
1. Fast-Path Speculative Race βββββββΊ Groq & Cerebras (Ultra-Low Latency LPU)
β (Timeout / Rate Limit)
βΌ
2. Primary Reasoning Engine βββββββββΊ Google Gemini (Gemini 3.8 Flash)
β (429 / Outage)
βΌ
3. Broad Provider Mesh ββββββββββββββΊ OpenRouter (Aggregated Free/Low-Cost Frontier Models)
β (Network Failure)
βΌ
4. Fallback Cloud Keys ββββββββββββββΊ Secondary & Third-Party Key Pools
β (Air-Gapped / Outage)
βΌ
5. Terminal Self-Hosted Tier ββββββββΊ Local Server (127.0.0.1:11434 / Ollama / llama.cpp)
- Health Recovery Probing: Quarantined keys or providers automatically enter a half-open probe state after
PROVIDER_HEALTH_RECOVERY_SECONDS(30s default) to recover capacity without human intervention. - Deadline Reservation: 40% of the request timeout is reserved for fallback execution (
PRIMARY_ATTEMPT_FRACTION = 0.60), guaranteeing that a slow primary cannot starve the fallback ladder.
Standard endpoint compatible with the OpenAI SDK, LangChain, LiteLLM, and any ecosystem agent.
curl -X POST http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-H "X-INFERENCE-API-KEY: your_api_key_here" \
-d '{
"model": "auto",
"messages": [
{"role": "system", "content": "You are a concise engineering specialist."},
{"role": "user", "content": "Explain circuit breaker pattern in two sentences."}
],
"temperature": 0.5,
"max_tokens": 256,
"stream": false
}'{
"id": "chatcmpl-a1b2c3d4e5f6",
"object": "chat.completion",
"created": 1729000000,
"model": "openai/gpt-oss-120b",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "The circuit breaker pattern detects service failures and prevents applications from repeatedly trying to execute an operation doomed to fail. When failures exceed a threshold, the breaker trips to open state, immediately failing calls and allowing degraded dependencies to recover."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 24,
"completion_tokens": 42,
"total_tokens": 66
}
}Lists the active model catalog available across configured providers.
curl -X GET http://localhost:8000/v1/models \
-H "X-INFERENCE-API-KEY: your_api_key_here"{
"object": "list",
"data": [
{"id": "gemini-3.8-flash", "object": "model", "owned_by": "google", "permission": []},
{"id": "openai/gpt-oss-120b", "object": "model", "owned_by": "groq", "permission": []},
{"id": "llama-3.3-70b-versatile", "object": "model", "owned_by": "groq", "permission": []},
{"id": "cerebras/llama-3.3-70b", "object": "model", "owned_by": "cerebras", "permission": []},
{"id": "nvidia/nemotron-3-super-120b-a12b", "object": "model", "owned_by": "nvidia", "permission": []},
{"id": "liquid/lfm-2.5-2.6b:free", "object": "model", "owned_by": "openrouter", "permission": []},
{"id": "auto", "object": "model", "owned_by": "inference", "permission": []}
]
}Sub-300ms Time-To-First-Token (TTFT) Server-Sent Events (SSE) streaming endpoint for real-time conversational UI.
curl -N -X POST http://localhost:8000/stream \
-H "Content-Type: application/json" \
-H "X-INFERENCE-API-KEY: your_api_key_here" \
-d '{
"prompt": "List 3 high-throughput caching strategies.",
"model": "auto"
}'data: {"token": "1.", "done": false}
data: {"token": " Cache", "done": false}
data: {"token": "-Aside", "done": false}
data: {"token": " pattern\n", "done": false}
...
data: {"done": true}
Lightweight unauthenticated liveness probe compatible with Kubernetes and Docker Healthcheck.
curl -X GET http://localhost:8000/health{
"status": "healthy",
"service": "inference",
"evidence_class": "process_liveness",
"observed_at": "2026-10-14T16:00:00.000000+00:00",
"providers": ["groq", "cerebras", "openrouter", "gemini"],
"active_specialist_agents": 10,
"version": "2.0.0"
}Deep readiness probe verifying persistent SQLite database connectivity (WAL mode verification) and model routing initialization. Returns HTTP 200 when ready to serve production traffic, or HTTP 503 if degraded.
curl -X GET http://localhost:8000/ready{
"status": "ready",
"service": "inference",
"evidence_class": "service_readiness",
"ready": true,
"database": {
"status": "connected",
"detail": "connected",
"connected": true,
"journal_mode": "wal"
},
"model_routing": {
"status": "ready",
"initialized": true,
"providers": ["gemini", "groq", "cerebras", "openrouter"]
},
"providers_initialized": true,
"observed_at": "2026-10-14T16:00:00.000000+00:00",
"version": "2.0.0"
}Exposes real-time Prometheus metrics for scrapers and Grafana dashboards, including request totals, latencies, provider health, token counts, and memory statistics.
curl -X GET http://localhost:8000/metricsAll configuration is loaded from environment variables and .env. Keys support both singular and comma-separated lists for automatic round-robin pooling.
| Variable | Type | Default | Description |
|---|---|---|---|
INFERENCE_API_KEY |
string |
(Required) | Primary secret token for authenticating gateway calls |
GEMINI_API_KEYS |
string |
"" |
Comma-separated Google Gemini API keys (Gemini 3.8 Flash) |
GROQ_API_KEYS |
string |
"" |
Comma-separated Groq API keys (LPU ultra-fast inference) |
CEREBRAS_API_KEYS |
string |
"" |
Comma-separated Cerebras API keys |
OPENROUTER_API_KEYS |
string |
"" |
Comma-separated OpenRouter API keys |
NVIDIA_API_KEYS |
string |
"" |
Comma-separated NVIDIA NIM API keys |
THIRD_PARTY_*_KEYS |
string |
"" |
Dedicated fallback key pools for tertiary redundancy |
PORT |
int |
8000 |
Application server port |
HOST |
string |
0.0.0.0 |
Bind interface |
DATABASE_URL |
string |
required in production | Oracle Autonomous Database DSN for persistent consultation & task memory (PostgreSQL/SQLite are not supported) |
WEB_CONCURRENCY |
int |
1 |
Uvicorn worker process count |
MEMORY_TRIM_ENABLED |
bool |
true |
Proactive glibc memory trim to prevent container OOM |
MEMORY_TRIM_THRESHOLD_MB |
float |
400.0 |
RSS high-water trigger for idle memory reclamation |
LOCAL_ENABLED |
bool |
false |
Enable self-hosted local model server fallback |
LOCAL_BASE_URL |
string |
http://127.0.0.1:11434/v1 |
Local server base URL |
# 1. Clone repository & setup virtual environment
git clone https://github.com/surendra2304/Inference.git
cd Inference
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# 2. Install production dependencies
pip install -r requirements.txt
pip install -e ".[dev]"
# 3. Configure credentials
cp .env.example .env
# Edit .env with your provider API keys and INFERENCE_API_KEY
# 4. Start local development server
uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload# Build production container image
docker build -t inference .
# Run container with persistent data volume and port mapping
docker run -d \
--name inference \
-p 8004:8000 \
--env-file .env \
-v inference-data:/app/data \
--restart unless-stopped \
inferencedocker compose -f docker-compose.production.yml up -d --build