Developer Reference

AlphaLlama — complete CLI and API reference.

Quick Start

# Run a model as an OpenAI-compatible server
alphallama -m model.gguf

# Download and run from HuggingFace
alphallama -hf Qwen/Qwen3-35B:Q4_K_M

# Specify GPU layers and context size
alphallama -m model.gguf -ngl auto -c 8192

# Serve with API key protection
alphallama -m model.gguf --api-key mysecretkey

Context Modes

AlphaLlama supports three context modes via the --context flag:

alphallama -m model.gguf --context native      # default
alphallama -m model.gguf --context extended     # for large knowledge bases
alphallama -m model.gguf --context sequential   # for very long documents

Native Mode

Default. Full prompt with native attention. Best for chat, coding, reasoning. Up to 262K tokens with Q4 KV cache on 24GB VRAM.

Extended Mode

For large knowledge bases. Index a corpus, then query with server-side retrieval + inference. Scales to 82B+ tokens with 92-99% accuracy. Client never touches raw chunk text.

# Step 1: Index chunks
curl http://localhost:18080/api/corpus/index -d '{
  "chunk_id": 1, "text": "Your document text..."
}'

# Step 2: Query — returns chunk IDs (not text)
curl http://localhost:18080/api/corpus/query -d '{
  "query": "search terms"
}'

# Step 3: Chat with extended context (server retrieves chunks internally)
curl http://localhost:18080/v1/chat/completions -d '{
  "messages": [{"role": "user", "content": "your question"}],
  "context_mode": "extended"
}'

Sequential Mode

For very long documents. Processes in overlapping windows. Tested up to 1.3M chars with 90.7% accuracy.

Choosing the Right Mode

Use CaseMode
Chat, coding, reasoningnative
Search a knowledge baseextended
Query across millions of docsextended
Long document (exceeds context)sequential
Reproduce exact text from 1M+ docsequential

Model Loading

FlagDescription
-m, --model FNAMEPath to GGUF model file
-hf USER/MODEL[:QUANT]Download and run from HuggingFace
-hff FILESpecific file to download from HF repo
-hft TOKENHuggingFace access token for gated models
--lora FNAMEApply LoRA adapter
--lora-scaled FNAME:SCALEApply LoRA with custom scale
-mm, --mmproj FILEMultimodal projector file (vision models)
alphallama -m ~/models/qwen3-35b.gguf
alphallama -hf Qwen/Qwen3-35B-MoE:Q4_K_M
alphallama -m model.gguf --lora adapter.gguf
alphallama -m model.gguf -mm projector.gguf

GPU & Memory Management

FlagDescription
-ngl NLayers to offload to GPU (auto, all, or number)
--fit [on|off]Auto-adjust parameters to fit in VRAM (default: on)
--fit-target MiBTarget VRAM margin per device
-c, --ctx-size NContext size in tokens (default: 4096)
--cache-type-k TYPEKV cache type for keys (f16, q8_0, q4_0)
--cache-type-v TYPEKV cache type for values
-cmoe, --cpu-moeOffload MoE expert weights to CPU
-ts, --tensor-split N,N,...Split model across multiple GPUs
--numa distributeNUMA-aware memory allocation
# Auto-detect best GPU offload
alphallama -m model.gguf -ngl auto

# Q4 KV cache (fits 262K context on 24GB)
alphallama -m model.gguf -ngl all --cache-type-k q4_0 --cache-type-v q4_0 -c 262144

# MoE offload (keep attention on GPU, experts on CPU)
alphallama -m model.gguf -ngl all --cpu-moe

# Multi-GPU split
alphallama -m model.gguf -ngl all -ts 60,40

Server Options

FlagDescription
--host HOSTListen address (default: 127.0.0.1)
--port PORTListen port (default: 18080)
-np, --parallel NNumber of parallel request slots
--ssl-key-file FILETLS private key for HTTPS
--ssl-cert-file FILETLS certificate for HTTPS
--no-webuiDisable the built-in web UI
--metricsEnable Prometheus metrics at /metrics
--no-licenseSkip license check (cloud/RunPod deployment)
# Production server: bind all interfaces, 4 parallel slots
alphallama -m model.gguf --host 0.0.0.0 --port 18080 -ngl all --parallel 4

# HTTPS with SSL
alphallama -m model.gguf --ssl-key-file key.pem --ssl-cert-file cert.pem

# RunPod / cloud deployment (no license needed)
alphallama -m model.gguf --host 0.0.0.0 --port 18080 -ngl 99 --no-license --parallel 4

API Authentication

Two levels of API key protection:

FlagDescription
--api-key KEYServer-side API key (local protection)
--api-key-file FILELoad API keys from file (one per line)
ALPHACHAT_API_KEYAlphaChat platform key (tier-based, see Pricing)
# Server-side key
alphallama -m model.gguf --api-key mysecret
curl -H "Authorization: Bearer mysecret" http://localhost:18080/v1/chat/completions

# Platform key (Business tier)
export ALPHACHAT_API_KEY=sk-alphachat-biz-abc123
alphallama -m model.gguf

Sampling Parameters

FlagDescription
--temp NTemperature (default: 0.8, 0 = greedy)
--top-k NTop-K sampling (default: 40, 0 = disabled)
--top-p NTop-P / nucleus sampling (default: 0.95)
--min-p NMin-P sampling (default: 0.05)
--repeat-penalty NRepeat penalty (default: 1.0)
--dry-multiplier NDRY repetition penalty multiplier
--seed NRandom seed (-1 = random)

Reasoning / Thinking

Enable chain-of-thought reasoning for supported models:

FlagDescription
--reasoningEnable reasoning mode
--reasoning-budget NMax tokens for thinking (0 = unlimited)
--reasoning-format FORMATOutput format: deepseek | none
alphallama -m model.gguf --reasoning --reasoning-budget 4096

Speculative Decoding

Speed up inference by drafting tokens with a smaller model:

FlagDescription
-md, --model-draft FNAMEDraft model for speculative decoding
-nd, --draft NNumber of draft tokens (default: 16)
--spec-layer-skip NSelf-speculative layer-skip decoding
# Draft model speculation
alphallama -m big-model.gguf -md small-model.gguf -nd 16

# Self-speculative (no draft model needed)
alphallama -m model.gguf --spec-layer-skip 4

API Endpoints

OpenAI-Compatible

MethodEndpointDescription
POST/v1/chat/completionsChat completions (streaming supported)
POST/v1/completionsText completions
POST/v1/embeddingsGenerate embeddings
GET/v1/modelsList loaded models

AlphaLlama-Specific (Extended Context)

MethodEndpointDescription
POST/api/corpus/indexIndex a chunk into the corpus
POST/api/corpus/queryQuery the corpus — returns chunk IDs only (no text)
DELETE/api/corpus/clearClear all indexed chunks
GET/api/corpus/statsCorpus statistics (chunk count, size)

Ollama-Compatible

Also supports Ollama API endpoints:

/api/chat · /api/generate · /api/tags · /api/show · /api/ps

Environment Variables

FlagDescription
ALPHACHAT_API_KEYPlatform API key (sk-alphachat-* / sk-alphachat-biz-* / sk-alphachat-org-*)
CUDA_VISIBLE_DEVICESSelect specific GPU(s)
GGML_CUDA_NO_PINNEDDisable pinned memory (saves RAM)
LLAMA_CACHEModel cache directory
LLAMA_ARG_*Set any CLI flag via env var (e.g., LLAMA_ARG_N_GPU_LAYERS=99)

Common Configurations

16GB GPU (RTX 4080)

alphallama -m qwen3-35b-q4.gguf -ngl auto --cpu-moe -c 8192 --parallel 2

24GB GPU (RTX 3090) — Maximum Context

alphallama -m qwen3-35b-q4.gguf -ngl all --cache-type-k q4_0 --cache-type-v q4_0 -c 262144

Knowledge Base Server

alphallama -m qwen3-35b-q4.gguf -ngl all --context extended \
  --host 0.0.0.0 --port 18080 --parallel 4

Low-VRAM (8GB laptop)

alphallama -m qwen3-4b-q4.gguf -ngl auto --fit on -c 4096

Cloud / RunPod Deployment

alphallama -m model.gguf --host 0.0.0.0 --port 18080 \
  -ngl 99 --no-license --ctx-size 32768 --parallel 4