> ## Documentation Index
> Fetch the complete documentation index at: https://docs.prysm1.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How PRYSM routes across 27 models in under 5 ms

> A look at the ten-signal intent classifier, the fallback chain, and the BRAIN.md override layer that make up PRYSM's routing engine.

PRYSM's routing engine receives a prompt and returns a routing decision in under 5 ms — before
any model call happens. This post explains how it works.

## The ten intent signals

The classifier scores each prompt on ten dimensions simultaneously (no sequential calls, no
embedding round-trips):

```
1. code          — mentions functions, classes, algorithms, debugging
2. write         — mentions essays, stories, emails, creative tasks
3. analysis      — complex comparative reasoning, trade-off evaluation
4. math          — equations, proofs, numerical computation
5. translate     — explicit language translation request
6. realtime      — queries about current events, prices, today's date
7. simple        — short, low-complexity, conversational
8. multimodal    — references images, audio, or other media
9. reasoning     — formal logic, deductive chains, scientific reasoning
10. long_context — prompt exceeds ~16k tokens
```

Each signal produces a float in `[0, 1]`. The final routing decision combines signal strengths
with the chosen routing mode.

## Routing modes

| Mode       | When to use                       | Cost profile                           |
| ---------- | --------------------------------- | -------------------------------------- |
| `agility`  | Speed and cost over quality       | Cheapest model that handles the task   |
| `balanced` | The PRYSM default                 | Best cost/quality tradeoff             |
| `quality`  | Critical tasks, complex reasoning | Cross-validates across multiple models |

## The decision logic

```python theme={null}
# Simplified pseudocode — the actual classifier uses bitfield operations
def classify_and_route(prompt: str, mode: str = "balanced", brain: dict = None) -> dict:
    signals = score_signals(prompt)
    wc = len(prompt.split())

    # Short prompts → always agility
    if wc < 8:
        mode = "agility"

    # Long analysis → quality unless overridden
    if wc > 20 and signals["analysis"] > 0.6 and mode != "agility":
        mode = "quality"

    # Select tier by mode
    if mode == "agility":
        tier = "budget"
    elif mode == "quality":
        tier = "frontier"
    else:
        tier = primary_tier(signals)   # budget | mid | premium | frontier

    # Pick the best model in the tier for the dominant signal
    model = best_model_for_signal(tier, dominant_signal(signals))

    # Apply BRAIN.md overrides (model lock, max_cost, blocked list)
    if brain:
        model = apply_brain_overrides(model, signals, brain)

    return {"model": model, "tier": tier, "signals": signals, "why": reason_string(model, signals)}
```

## The fallback chain

If the selected provider has no API key configured, the engine falls back through providers in
cost order:

```
1. DeepSeek  ($0.28/MTok) → try first
2. Mistral   ($0.30/MTok) → if DeepSeek unavailable
3. OpenAI    ($0.25+/MTok) → if Mistral unavailable
4. Anthropic ($3.00+/MTok) → last resort
```

This means a deployment with only `DEEPSEEK_API_KEY` still gets cost-optimized routing — it
just uses DeepSeek's full model lineup.

## Dry-run: see the routing decision

```python theme={null}
from prysm import Prysm

client = Prysm()

# See the full routing decision without calling any model
preview = client.route("Write a Python function to merge two sorted lists")
print(preview["routing"]["model"])   # claude-sonnet-4.5
print(preview["routing"]["tier"])    # premium
print(preview["routing"]["why"])     # "code signal + balanced mode"
print(preview["routing"]["signals"]) # {"code": 0.92, "simple": 0.1, ...}
print(preview["estimated_cost"]["est_1k_tokens"])  # 0.003 USD
```

## PrysmProof: cryptographic attestation of every decision

Every response includes a `prysm.proof` field:

```python theme={null}
resp = client.chat.completions.create(
    model="auto",
    messages=[{"role": "user", "content": "Explain quantum entanglement"}],
)
proof = resp.prysm.proof
print(proof["model"])       # gemini-3-flash
print(proof["proof_hash"])  # sha256:a1b2c3d4e5f67890
print(proof["timestamp"])   # 2026-06-13T...
```

The hash is `sha256(request_id + timestamp + model + provider + mode + prompt_sha256 +
response_sha256)[:16]`. Verify offline:

```python theme={null}
is_valid = client.verify_proof(proof["request_id"], resp.choices[0].message.content)
print(is_valid)  # True
```

## Benchmarks

| Prompt type                        | Time to routing decision | Model selected    |
| ---------------------------------- | ------------------------ | ----------------- |
| "What's 2+2?" (simple)             | 0.8 ms                   | mistral-nemo      |
| "Write a binary search" (code)     | 1.2 ms                   | claude-sonnet-4.5 |
| "Prove P≠NP" (reasoning+analysis)  | 1.5 ms                   | deepseek-r1       |
| 50k-token document (long\_context) | 2.1 ms                   | gemini-3-flash    |

All measured on a single-core container, no GPU. The classifier is a pure Python bitfield
operation over pre-compiled signal patterns — no embedding calls, no ML inference.
