Engine reference — generated from the canonical engineering source. Do not edit this page by hand.
Provider Setup Guide
Sol routes inference through two paths:
- Local inference — llama.cpp processes managed by Sol on the same machine
- Remote providers — API calls to Anthropic, OpenAI, xAI, z.ai, Ollama,
Gemini, DeepSeek, Alibaba, AWS Bedrock and Xiaomi via Sol’s resolver, plus
declarative OpenAI-compatible providers loaded from
priv/providers/*.json
Local Inference (llama.cpp)
Prerequisites
llama.cpp compiled with CUDA, Metal, or CPU support GGUF model files in a model directory Sufficient GPU/CPU memory for the target model
Step 1: Place Model Files
Put .gguf files in a directory accessible to Sol:
# Default source directory (NFS)
ls /fun/models/*.gguf
# Or configure a custom path
# In sys.config: {model_source_dir, "/data/models"}
Step 2: Discover Models
zerg discover
# Discovered 12 models
Sol scans the source directory recursively for .gguf files and generates slug names from filenames.
Step 3: Start a Model
zerg start glm-4.7-flash
# With a parameter template
zerg start glm-4.7-flash --template coding
# With parameter overrides
zerg start glm-4.7-flash --temp 0.3 --batch-size 4096
Step 4: Run Inference
# OpenAI format
zerg run --model glm-4.7-flash "Explain quicksort"
# Anthropic format
zerg chat --model glm-4.7-flash "Explain quicksort"
Parameter Templates
Predefined parameter sets selectable via --template:
| Template | temp | top_p | min_p | batch_size | top_k |
|---|---|---|---|---|---|
default | 1.0 | 0.95 | 0.01 | 2048 | — |
coding | 0.3 | 0.95 | — | 2048 | — |
chat | 0.7 | 0.9 | — | 2048 | — |
reasoning | 0.6 | 0.95 | — | — | 40 |
Model Sync (rsync)
For NFS-mounted model directories, Sol can sync models to local disk:
zerg prepare glm-4.7-flash
# Syncs from model_source_dir to model_store_dir via rsync
This is faster for inference because it avoids NFS latency during model loading.
Remote Providers
When local inference is unavailable or a specific model is only available via API, Sol can proxy requests to remote providers.
Model Resolver
Sol uses a local-first resolution strategy:
- Check for a local running model matching the name
- If local model exists but circuit breaker is open, skip to remote
- Look up model in the global cluster catalog
- Route to the first available remote endpoint with open circuit breaker
Provider health (/api/v1/provider-health)
Health is probed per transport identity — {provider/key, endpoint, request_path} — never per model or alias, so N aliases of one provider cost
one probe. The probe uses the provider’s real request path with its
credentials (a side-effect-free pool key peek; no rotation/usage charge).
Verdicts:
| Probe result | Status |
|---|---|
| 2xx | available |
| 401 / 403 | available_unauthorized (reachable; credential problem) |
| 404 / 405 / 429 / other 4xx | available (reachability success — never degraded) |
| 5xx | degraded |
| connect/timeout failure | unavailable |
| no endpoint (registered-only adapter row) | unconfigured (never probed) |
Probes are cached ~60s per transport identity.
Circuit Breaker
Each provider endpoint is protected by a circuit breaker:
| State | Behavior |
|---|---|
| closed | Normal operation. Requests flow through. |
| open | Requests rejected. All traffic returns error. |
| half_open | One request allowed through to test recovery. |
Configuration:
| Key | Default | Description |
|---|---|---|
circuit_breaker_failure_threshold | 5 | Failures before opening |
circuit_breaker_window_ms | 60000 | Failure counting window |
circuit_breaker_cooldown_ms | 30000 | Time before half-open |
CLI:
# Check circuit states
zerg circuits
# Force reset a circuit
zerg circuits-reset my-model
Error Classification
The resolver classifies errors as transient or permanent:
| Error | Classification | Circuit impact |
|---|---|---|
timeout | Transient | Counts toward threshold |
connect_failed | Transient | Counts toward threshold |
connection_down | Transient | Counts toward threshold |
| HTTP 429 (rate limit) | Transient | Counts toward threshold |
| HTTP 503 (unavailable) | Transient | Counts toward threshold |
| HTTP 4xx/5xx (other) | Permanent | Counts toward threshold |
invalid_model | Permanent | Counts toward threshold |
Luna Provider Configuration
Luna (the agent client) connects directly to LLM providers. Configuration is in ~/.luna/config.json or .luna/config.json.
Supported Providers
| Provider | Default Model | API Format | API Key Env |
|---|---|---|---|
| Anthropic | claude-sonnet-4 | Anthropic Messages | ANTHROPIC_API_KEY |
| OpenAI | gpt-4o | OpenAI Chat Completions | OPENAI_API_KEY |
| xAI | grok-4 | OpenAI Chat Completions | XAI_API_KEY |
| z.ai | glm-5.1 | Anthropic Messages (https://api.z.ai/api/anthropic) | ZAI_API_KEY |
| Ollama | (local) | OpenAI-compatible (http://localhost:11434/v1) | N/A (local) |
Defaults and base URLs: client/core/provider.lua (model aliases) and
client/core/provider_urls.lua (PROVIDER_BASE_URLS).
Configuration
{
"model": "glm-5.1",
"provider": "zai",
"api_key": "your-api-key",
"base_url": "https://api.z.ai/api/anthropic"
}
Or use environment variables:
export ZAI_API_KEY="your-api-key"
luajit client/main.lua --model glm-5.1 "Fix the bug"
Provider-Specific Examples
Anthropic
{
"model": "claude-sonnet-4",
"provider": "anthropic",
"api_key": "sk-ant-..."
}
OpenAI
{
"model": "gpt-4o",
"provider": "openai",
"api_key": "sk-..."
}
z.ai (Default)
{
"model": "glm-5.1",
"provider": "zai",
"api_key": "..."
}
Ollama (S68)
{
"model": "qwen3-coder",
"provider": "ollama",
"base_url": "http://localhost:11434"
}
Ollama runs locally and requires no API key. Set the ollama_url config key if using a non-default address.
Model Switching
Switch models at runtime:
CLI: luajit client/main.lua --model gpt-4o "prompt"
TUI: Type /model gpt-4o in the input bar
Fallback & failure semantics
Luna’s client-side failover (client/core/provider_failover.lua) treats a
fallback stream attempt as rescued only by a real success: a 2xx HTTP
status, the internal "handled" marker, or a non-numeric truthy transport
value. Any other outcome — a numeric 4xx/5xx, the typed "error", or a
"redirect_refused" — is a FAILURE: the ladder continues to the next
fallback, and when it is exhausted the turn terminates with a typed
provider_error/error event plus a provider.stream_error publication.
The pre-fix if result ~= "error" comparison read a numeric 500 as a rescue,
ending the turn as an empty success; that class is closed.
Partial-content failures are terminal at the agent layer (agent.lua,
mirrored in agent_followup.lua): once an attempt has delivered any text
delta, a mid-stream error never re-drives the provider — the typed error is
surfaced once together with the single partial copy (turn_done.success = false, reason = "partial_content_stream_failure" /
"followup_stream_failure"). Pre-content failures keep the existing
overflow/transient retry ladder.
Server-side fallback chains
Sol serves provider overload from a configured fallback model instead of a
bare 503. The chain lives beside the declarative provider configs
(server/priv/providers/ bundled, ~/.sol/providers/ user override) as a
JSON object:
{"fallback_chains": {"claude-sonnet-4-20250514": ["claude-3-5-sonnet-20241022"],
"*": ["gpt-4o-mini"]}}
Keys and values are globs resolved against the registered model set
at load. Resolution order is deterministic: exact keys first, then prefix
globs, then other globs, * last (alphabetical per class).
Only dispatchable models are candidates: a
candidate must carry a remote endpoint + credentials or be a local lane
identity. A registered-but-endpoint-less adapter row is skipped, never
attempted into a 503. The attempt uses the serving model: aliases are
resolved to their canonical catalog/provider id before the wire body is
built.
Validation refuses unknown models, self-reference and cycles
(fallback_cycles); a refused config never installs chains (fail closed,
logged + counted) and the provider_boot init label records it.
Two fallback SEAMS exist. The HTTP funnel
engages a chain on a retryable pre-dispatch refusal: provider /
resolver circuit open, every provider-pool key cooling (the 429/quota
class), local admission capacity (429), and an admission-down lane. The
PIPELINE seam re-enters the same chain when a dispatched attempt yields a
retryable pre-token execution verdict — a 429/5xx/529/408 response
head, connect exhaustion, a first-token timeout, a garbage/empty 200, a
bodyless 200, a pre-token connection death, a permanent TLS/connect
failure, or {inference_unavailable, _}. A malformed/unknown model (404)
and auth/request errors (400/401/403) never fall back.
At most 2 fallback attempts after the primary. Each attempt is a NEW
pipeline, so the per-attempt machinery is reused as-is: circuit reports,
key cooldown/rotation,
Retry-After capture. Nothing retries once a byte has flowed: post-first-
token failures stay terminal (the pipeline’s own bounded head-429 retry
is unchanged). A pipeline fallback receives its OWN serving model, wire
dialect, transport posture and request path (fallback_opts +
descriptor), never the failed primary’s.
Observability: model.failed and provider.fallback_engaged (attempt
index + reason) durable events, the
sol_provider_fallback_engaged_total{from,to,reason} counter
(Sol Circuits & Providers dashboard panel), and an audit row per
engagement.
Compat surfaces: a response served by a fallback carries the serving
model — the x-zerg-model-used header plus the envelope model field;
the request body sent to the candidate carries the SERVING model id (and
the candidate’s wire dialect), never the requested body model;
usage/accounting is attributed to the serving provider and
inference.complete carries fallback_from when a fallback served.
The feature is ON with empty chains: no chains configured = no behavior
change (rollback = delete the config).
Luna posture: with a Sol binding present (a
Sol-issued lane grant) Sol owns fallback, and provider_failover does NOT
model-switch — Luna keeps only transport-level retries and surfaces the
typed error. Direct-provider configs (no binding) keep the client-side
chain documented above.
Declarative Providers (S54)
Users can add custom OpenAI-compatible providers without writing Erlang code. Place a JSON config file in the provider directory:
{
"name": "my-provider",
"display_name": "My Provider",
"base_url": "https://api.example.com/v1",
"api_key_env": "MY_PROVIDER_API_KEY",
"format": "openai",
"models": [
{"id": "my-model-large", "alias": "my-large"}
]
}
| Field | Required | Description |
|---|---|---|
name | Yes | Unique provider identifier |
base_url | Yes | API endpoint base URL. https:// (case-insensitive) is always accepted; a non-loopback http:// endpoint is REFUSED at config load (the key would travel in cleartext). Loopback http:// is allowed; a lab may opt in with "allow_insecure_provider_http": true (or the global allow_insecure_provider_http ack). |
api_key_env | No | Environment variable holding the API key |
format | Yes | Wire format: openai or anthropic |
headers | No | Custom HTTP headers (object) |
models | No | List of model objects: {"id": "...", "alias": "..."} (alias optional) |
display_name | No | Human-readable provider name |
default_max_tokens | No | Default completion token budget (also the admission estimate when the caller omits max_tokens). |
allow_insecure_provider_http | No | Explicit lab ack for a non-loopback plaintext endpoint (default off). |
Aliases are registered with an explicit canonical_model — the wire body
and settlement attribution always use the canonical id, never the alias.
See server/priv/providers/00-openai-compatible.json for a full example set
(groq, together, fireworks, openrouter, deepseek, google, mistral, cohere,
perplexity) and server/src/sol_provider_declarative.erl for the validator.
Providers are loaded at boot and registered in the ETS provider registry. They participate in normal routing, circuit breaking, and pool management.
Provider Boot Registration
Providers are registered at boot by sol_provider_boot:register_defaults/0
(server/src/sol_provider_boot.erl). There is no {providers, [...]}
sys.config tuple — registration happens through three mechanisms:
- Bundled adapters — the models exposed by each
sol_provider_*.erladapter (anthropic, openai, zai, ollama, alibaba, bedrock, xiaomi) are registered in code, each stamped with itswire_format. - Config mappings — a
provider_mappingslist insys.configmaps a model name to a provider atom:{provider_mappings, [{<<"my-model">>, anthropic}]}. - Declarative JSON —
priv/providers/*.json, hot-reloadable without restart (sol_provider_declarative:load_configs/0).
Config-based provider mappings require an application restart; declarative JSON providers do not.
Coordinator Mode
sol_coordinator (server/src/sol_coordinator.erl) decomposes a multi-step
task into subtasks and runs each subtask as a workflow through
sol_workflow_manager. The decomposition registry is durable since
A bounded, atomically written file (cap enforced; terminal
entries retire) reconciled on boot, with the workflow rows still the source of
truth. A coordinator restart therefore loses no grouping view and does not
re-dispatch a completed subtask. cancel/1 drives every remaining subtask
workflow to a real terminal state.
Workflow steps can specify model and provider fields to override
automatic routing (sol_workflow_templates.erl step parsing), which is how
per-step provider selection is expressed — there is no built-in
mode→provider routing table.
Cloud Provider Adapters
AWS Bedrock (CSP1)
Sol supports AWS Bedrock’s Converse API for running models like Claude on AWS infrastructure.
Boot config:
{bedrock, #{
format => bedrock,
region => "${AWS_REGION}",
access_key => "${AWS_ACCESS_KEY_ID}",
secret_key => "${AWS_SECRET_ACCESS_KEY}"
}}
Supported models:
| Friendly Name | AWS Model ID |
|---|---|
bedrock-claude-sonnet-4 | anthropic.claude-sonnet-4-20250514-v1:0 |
bedrock-claude-3.5-sonnet | anthropic.claude-3-5-sonnet-20241022-v2:0 |
bedrock-claude-3.5-haiku | anthropic.claude-3-5-haiku-20241022-v1:0 |
OpenAI Responses API — RETIRED
The responses wire is retired. It was never implemented end-to-end
(the request path derivation appended /chat/completions to a
/v1/responses base URL, and the body builder/parse router had no
responses branch), so a responses config produced models that could
never answer correctly. Per the retirement decision (, the luerl
sub-agent precedent):
declarative provider configs declaring format: "responses" fail
validation with an actionable error;
boot refuses to register responses-adapter models (loud log +
counter);
the adapter module answers every call with
{error, {retired_wire, responses}}.
Use the openai wire (chat completions) or the anthropic wire instead.
Re-introduction means implementing the real wire — request builder,
parser, path derivation, translators, and a golden fixture corpus — and is
tracked separately.
Cross-Provider Switching
Runtime adapter switching (POST /api/v1/provider/switch) was retired
in: it flipped a global registry entry, carried an echo-only
workflow_id, and had zero consumers on any client. Model selection is
per-request params + declarative provider configs + the lane plane; reload
declarative configs with POST /api/v1/providers/reload (kept — used by
sol_provider_boot:reload_declarative).
Provider Pool
For providers with multiple API keys, Sol distributes requests across a pool:
| Config Key | Default | Description |
|---|---|---|
provider_pool_strategy | round_robin (shipped sys.config; code default is least_used) | Key selection strategy: round_robin (rotates per-provider key index), least_used (min usage_count), random, least_errors |
See server/src/sol_provider_pool.erl (select_key/3).