Brick is a Mixture-of-Models (MoM) routing gateway. It reads each prompt's
capability and complexity, then routes it to the best backend in a pool of
open- and closed-weight LLMs, matching the strongest single model's quality at a
fraction of its cost. No cascades. No wasted calls. Drop-in model: "brick"
.
When to use Brick Β· Quickstart Β· Why Brick Β· Claude Code Β· Codex Β· FAQ Β· Benchmarks Β· How it works Β· Paper
Brick is for anyone running against more than one model, or paying flat rate for a single strong one. Three common cases:
You have a pool of models and want each query to reach the right one. Cheap prompts should not burn your most expensive model, and hard prompts should not be starved on a small one. Brick reads capability and complexity per query and dispatches accordingly, so the pool works as one graded system instead of a manual pick. -
You want to cut Claude Code / Codex costs without losing quality. Put Brick in front of your coding agent and every request is routed to the cheapest model that can actually do the job, escalating only when the task needs it. You keep the same UX and pay for the hard turns, not the easy ones. -
You want to unify different models behind one tool. Use OpenAI models, GLM, DeepSeek, Kimi, Qwen and others from inside Claude Code or Codex through a single OpenAI-compatible endpoint. Define the pool once inconfig.yaml
and callmodel: "brick"
everywhere.
The fastest working path today is the CLI, which self-hosts the router and wires it into Claude Code for you. Requires Node >= 18 and Docker.
git clone https://github.com/regolo-ai/brick-SR1.git
cd brick-SR1/apps/cli && npm install && npm run build && npm link
brick claude on # starts the router + wires ANTHROPIC_BASE_URL in ~/.claude/settings.json
Then open a new Claude Code session and pick brick-claude in the /model
picker.
Every request now routes to haiku / sonnet / opus by capability and complexity. See
Brick + Claude Code for modes, the effort picker, and the live
brick claude status
dashboard.
Prefer a raw OpenAI-compatible gateway (no CLI)?
Once the Docker image is published (see Distribution channels), you'll be able to run the gateway directly:
docker run --rm -p 18000:18000 \
-e REGOLO_API_KEY=$REGOLO_API_KEY \
ghcr.io/regolo-ai/brick:latest # published at the next v2.1.0 tag
Then call it like any OpenAI endpoint, just set "model": "brick"
:
curl http://localhost:18000/v1/chat/completions \
-H "Authorization: Bearer $REGOLO_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"brick","messages":[{"role":"user","content":"Prove that sqrt(2) is irrational"}]}'
The x-selected-model
response header tells you which backend Brick picked.
That math prompt routes to a reasoning model; "Hello"
routes to the cheapest one.
Until then, brick serve
(from the CLI above) runs the same router locally from source.
| Single model | RouteLLM | FrugalGPT / Cascade | Brick |
|
|---|---|---|---|---|
| One call per query (no cascade waste) | β
| β
| β | β
|
| Capability-aware (6 dimensions) | n/a | β binary | β | β
|
| Complexity-aware | n/a | partial | β
| β
|
| Pool of N open + closed models | n/a | 2 | few | β
|
| Continuous cost β quality knob | β | β | threshold | β
r β [-1, 1] |
| Native multimodal (image / audio) | varies | β | β | β
|
| Drop-in OpenAI-compatible | n/a | n/a | n/a | β
|
Cascade routers (FrugalGPT, Cascade Routing) call models one after another until a confidence check passes, paying for every miss in tokens and latency. Brick makes a single forward decision per query, so there is nothing to waste.
gosmiulator.mp4 #
Put one OpenAI/Anthropic-compatible endpoint in front of Claude Code, and Brick routes every request to haiku, sonnet, or opus based on capability and complexity. You keep the Claude Code UX; Brick picks the cheapest model that can do the job.
brick claude on # wires ANTHROPIC_BASE_URL in ~/.claude/settings.json, auto-starts the router
Then:
- Open a
new Claude Code session (your current session is unaffected). - In the
/model
picker, selectbrick-claude(it sits alongside the built-in opus/sonnet/haiku aliases, which it does not replace).
To revert:
brick claude off # restores ANTHROPIC_BASE_URL, optionally stops the router
Use brick claude on --no-start
to require an already-healthy router instead of auto-starting one, and brick claude off --stop
/ --keep
to control the router without a prompt.
A mode is how you tell Brick how much to spend. Each one maps easy/medium/hard queries to a model tier, from cheapest (eco
, always haiku) to strongest (max
, always opus), with lite
, mid
and pro
in between. Pick one and Brick handles the per-query routing inside it.
2026-07-03.23-55-05.mp4 #
You switch mode straight from the thinking effort slider in Claude Code's /model
picker: low picks eco
, medium lite
, high mid
, xhigh pro
, and max max
. So the effort control does not set a thinking budget, it selects the model tier. You can also switch explicitly with brick claude mode
or brick claude <mode>
.
mid
is the default. On 1M-context requests the map shifts up since Haiku has no 1M variant: easy and medium resolve to sonnet, hard to opus.
Once you have picked the tier, how hard to think is decided autonomously per request from the router's own signals (query difficulty plus the chosen model's headroom).
Selecting opus, sonnet, or haiku explicitly in the picker skips Brick entirely: the request is forwarded verbatim to that exact model, with no skill routing and no effort override. Only brick-claude runs the router.
brick claude status # live dashboard (default in an interactive terminal)
brick claude status --once # static one-shot view
The dashboard reports, since the last router restart:
Routed by model: count and percent per model.** Per-model effort distribution**: how reasoning effort spread out within each model.** Difficulty mix**: the classifier's easy/medium/hard verdicts across routed requests.** Economy**: an estimatedsaved ~X% vs all-opus
over the routed request count (a relative estimate from request mix, excluding real token counts and caching).
It also shows connection/wiring state, classifier latency (avg, p50, p95), and fallback rate.
Brick routing is per request. In Claude Code workflows and subagents, each agent's call is routed independently as long as that agent uses brick-claude, so a cheap subagent task can land on haiku while a hard one escalates to opus in the same run.
The same idea behind OpenAI Codex: Brick sits in front of Codex and routes each request across your model pool, so you cut cost on easy turns and can drive Codex with non-OpenAI models through one OpenAI-compatible endpoint.
brick codex on # sets model/model_provider to brick in ~/.codex/config.toml, auto-starts the router
This materializes a dedicated Codex profile (the OpenAI-pool skill router) and adds a managed provider pointing at the local router. Start a new Codex session and it now routes through Brick.
To revert:
brick codex off # restores your previous Codex model/provider
Codex exposes the same 5 modes and status view as Claude Code:
brick codex mode # or: brick codex eco | lite | mid | pro | max
brick codex status # live routing dashboard
Use brick codex on --no-start
to require an already-healthy router instead of auto-starting one. The Claude and Codex router stacks share host port 8000, so only one can serve at a time; stop the other before wiring.
You do not need a coding agent. Brick is a plain OpenAI-compatible gateway you can call from any client, script, or app.
brick serve # docker compose up on http://localhost:18000
brick chat # TUI chat against the local router
brick route "what is 2+2?" # print the routing decision for a prompt, no call made
Call it like any OpenAI endpoint, just set "model": "brick"
:
curl http://localhost:18000/v1/chat/completions \
-H "Authorization: Bearer $REGOLO_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"brick","messages":[{"role":"user","content":"Prove that sqrt(2) is irrational"}]}'
The x-selected-model
response header tells you which backend Brick picked. That math prompt routes to a reasoning model; "Hello"
routes to the cheapest one.
Everything Brick decides comes from config.yaml
. The core block is skill_router
, where you declare the pool, each model's skill vector, and its cost weight:
skill_router:
enabled: true
capabilities: # the 6 dimensions every query and model live in
- coding
- creative_synthesis
- instruction_following
- math_reasoning
- planning_agentic
- world_knowledge
models:
- model: "qwen3.5-9b"
skill_vector: [0.71, 0.51, 0.81, 0.91, 0.58, 0.18] # capability per dimension
use_reasoning: false
cost_weight: 0.10 # relative price, drives the cost bias
- model: "deepseek-v4-flash"
skill_vector: [0.82, 0.66, 0.86, 0.93, 0.62, 0.49]
use_reasoning: false
cost_weight: 0.40
- model: "kimi2.6"
skill_vector: [0.90, 0.75, 0.87, 0.94, 0.64, 0.34]
use_reasoning: true
reasoning_effort: "medium"
cost_weight: 0.60
Add or swap any OpenAI-compatible backend here; the backends themselves are declared under provider_profiles
/ model_config
(the shipped config points them all at Regolo). Two more blocks let you nudge routing without touching the math:
keyword_rules:
- name: "force_coder" # hard override: send these prompts to a specific model
mode: "override"
model: "kimi2.6"
operator: "OR"
keywords: ["debug", "refactor", "compile", "write a function"]
- name: "coding_bias" # soft nudge: push one capability dimension up
mode: "bias"
capability: "coding"
operator: "OR"
keywords: ["python", "rust", "sql", "async"]
Other useful sections: brick
(multimodal preprocessing: STT, OCR, vision), the r
preference knob in r β [-1, 1]
(max-saving to max-quality), and the classifier endpoints. The CLI can edit most of this for you (brick add model
, brick config edit
), or edit the YAML directly. Full field reference: apps/router/README.md.
A monorepo to run, use, and reproduce every result in the Brick paper.
| Component | Path | Purpose |
|---|---|---|
| Router (Go + Rust) | ||
apps/router/ |
CLI(brick
)apps/cli/
Trainingpackages/training/
Evaluationpackages/evals/
Baselinespackages/evals/baselines/
Paperdocs/paper/
Full directory tree #
brick-SR1/
βββ apps/
β βββ router/ # Go + Rust gateway (was vLLM Spatial Router fork)
β β βββ src/spatial-router/ # Go (HTTP proxy, routing pipeline)
β β βββ candle-binding/ # Rust (ML embeddings via candle)
β β βββ ml-binding/ # Rust (Linfa classical ML)
β β βββ nlp-binding/ # Rust (BM25 + n-gram)
β β βββ Dockerfile
β βββ cli/ # @regolo-ai/brick CLI (TypeScript + oclif + ink)
βββ packages/
β βββ training/ # Dataset B pipeline + ModernBERT/complexity training
β βββ evals/ # Dataset A graders + 00..140 pipeline + baselines/
β βββ datasets/ # HF download recipes (no data in git)
βββ docs/
β βββ paper/ # paper.tex + figures + compiled PDF
β βββ quickstart/ # quick.md, serve.md, eval.md
βββ deploy/ # docker-compose, addons, Windows installer
βββ config.yaml # router runtime config
βββ package.json / pyproject.toml # npm + uv workspace roots
βββ Makefile # build / test / lint / docker-build / release
make install # npm install (apps/cli) + uv sync (packages/*)
make build # CLI + router Docker image
make test # Go tests + Python pytest + CLI vitest
make lint # pre-commit run --all-files
Per-component docs: router Β· CLI Β· training Β· evals Β· datasets Β· baselines.
Distribution channels (work in progress) #
| Channel | Status |
|---|---|
Source clone + npm link |
|
| available | |
Docker GHCR (ghcr.io/regolo-ai/brick ) |
|
pending first push (tag v2.1.0 ) |
|
npm (@regolo-ai/brick ) |
|
pending NPM_TOKEN secret |
|
Docker Hub mirror (docker.io/regolo/brick ) |
|
| pending Docker Hub secrets |
How is Brick different from a cascade router like FrugalGPT?
A cascade calls models in sequence (cheap first, escalate on low confidence) and pays for every miss in tokens and latency. Brick makes a single forward decision per query from a capability vector and a complexity score, so there is no wasted call. See Why Brick.
Which backend did Brick pick for my request?
Read the x-selected-model
response header. Every /v1/chat/completions
and /v1/messages
response carries it.
How do I trade cost against quality?
Slide the r
knob in r β [-1, 1]
. At r = -1
Brick favors the cheapest capable model (max-saving), at r = 1
it favors the strongest (max-quality). For Claude Code the same idea is exposed as 5 named modes, see the 5 modes.
Do I need GPUs to run the gateway?
No. The router and both classifiers run on CPU. GPUs only matter if you self-host the backend LLMs; with a hosted pool (Regolo, Anthropic, etc.) a CPU box is enough.
Can I use my own model pool?
Yes. The pool, per-model skill vectors, costs, and the model_map
live in config.yaml
(skill_router.models
). Add or swap any OpenAI-compatible backend. See apps/router/README.md.
What is the upstream for the OpenAI-compatible endpoint failing with 401/insufficient_quota?
That error comes from the backend provider, not Brick. Check the credential you forward (REGOLO_API_KEY
or your own key); Brick passes Authorization through unchanged.
Contributions are welcome. The short loop:
make install # deps for CLI + Python workspaces
make test # Go + pytest + vitest, run before opening a PR
make lint # pre-commit run --all-files
- Open an
issueto discuss non-trivial changes first. - Branch from
main
, keep commits focused, follow the existing style of the files you touch. - Make sure
make test
andmake lint
pass. - Open a PR with a clear description of the what and the why.
For architecture and per-component conventions, start from What's in the repo and the component READMEs linked under Develop.
Everything below reproduces the research behind Brick: the benchmark numbers, the routing algorithm, the datasets and models, and the paper itself.
Brick sits on the Pareto frontier of cost vs quality, dominating single-model baselines and prior routers (RouteLLM, FrugalGPT, Cascade Routing) and approaching the oracle ceiling.
| Setting | Accuracy | Cost (Γ cheapest) | Latency (avg) |
|---|---|---|---|
| Always Qwen3.5-9b | 65.4% | 1.0Γ | 8.1 s |
| Always DeepSeek-v4-flash | 71.2% | 4.0Γ | 14.7 s |
| Always Kimi2.6 | 75.02% | 6.0Γ | 51.2 s |
| Brick (max-quality) | |||
| 76.98% | |||
| 1.5Γ | |||
| 22.8 s | |||
| Brick (max-saving) | |||
| 72.4% | 1.0Γ | ||
| 9.4 s | |||
| Oracle bound (3-model pool) | |||
| 83.25% | |||
| n/a | |||
| n/a |
Brick beats always-Kimi at ~4Γ lower cost and roughly half the latency. Inter-rater agreement on the 3-judge eval panel: ΞΊ = 0.761. Full per-dimension breakdown and baseline reproduction in packages/evals/baselines/RESULTS.md.
For every request the router computes a capability vector and a complexity score, then picks the model whose skill profile is closest to what the query needs.
flowchart LR
Q([Query]) --> C[Capability classifier<br/>ModernBERT β p(x) β ΞβΆ]
Q --> X[Complexity classifier<br/>Qwen3.5-0.8B + LoRA β Ο]
C --> R{{Skill-distance argmin<br/>Jβ = Dβ + Ξ²Β·aβ}}
X --> R
R --> M1[qwen3.5-9b]
R --> M2[deepseek-v4-flash]
R --> M3[kimi2.6]
The query and each model live as vectors in the same capability space. The winner is the model whose skill vector is nearest to the query's needs, biased by a cost term:
Capabilityp(x) β ΞβΆ
: soft assignment overcoding
,creative_synthesis
,instruction_following
,math_reasoning
,planning_agentic
,world_knowledge
().brick-modernbert-capability-classifier
ComplexityΟ β {easy, medium, hard}
(, Qwen3.5-0.8B + LoRA).brick-complexity-2-eco
Objective per model:Jβ = Dβ + Ξ²Β·aβ
, distanceDβ = βp(x) β sββ
plus normalized costaβ
.Argmin over the pool β selected backend. Ther
knob slides the whole pool from max-saving to max-quality.
Multimodal inputs are preprocessed (OCR, Whisper-compatible STT) then routed as text, or forwarded directly to a vision model. Details in apps/router/README.md and the paper Β§3.
Full evaluation pipeline (Dataset A, 5,504 queries) #
git clone https://github.com/regolo-ai/brick-SR1 && cd brick-SR1
uv sync # Python workspaces
cd apps/cli && npm install && cd ../.. # CLI
python packages/datasets/scripts/download_dataset_a.py --out ./data/dataset_a
python packages/datasets/scripts/download_models.py --out ./models
python packages/evals/scripts/100_run_inference.py --config packages/evals/configs/protocols.yaml
python packages/evals/scripts/110_grade_inference.py
python packages/evals/scripts/130_aggregate_results.py | tee results.txt
Full pipeline (judges, baselines, cost/Pareto analysis): docs/quickstart/eval.md.
| Artifact | HF Repo | Type | Notes |
|---|---|---|---|
| Dataset A (eval) | |||
regolo/brick-dataset-A-routing-eval |
massaindustries/dataset-B-modernbert-train
regolo/brick-modernbert-capability-classifier
regolo/brick-complexity-2-eco
Download recipes: packages/datasets/.
Brick and the Mixture-of-Models (MoM) Paradigm: Bridging Open- and Closed-Weight LLM PoolsFrancesco Massa, Marco Cristofanilli (2026) Β· Built atRegolo.ai
Pre-built PDF: docs/paper/paper.pdf Β· compile with
cd docs/paper && latexmk -pdf paper.tex
.
@misc{massa2026brick,
title = {Brick and the Mixture-of-Models ({MoM}) Paradigm:
Bridging Open- and Closed-Weight {LLM} Pools},
author = {Massa, Francesco and Cristofanilli, Marco},
year = {2026},
url = {https://github.com/regolo-ai/brick-SR1}
}