Model providers
P4 of docs/plans/mcp-agent.md. Mouser talks to language models through one
interface, mouser_core::models::ModelProvider, which streams text and tool
calls. Every model is a plugin of kind model-provider (decision 5):
| Provider | Kind of plugin | Wire API | Default URL |
|---|---|---|---|
openai |
built in | OpenAI Chat Completions | https://api.openai.com/v1 |
grok |
built in | by key: xAI (OpenAI-compatible), Cursor agents API, or the Grok Bot desktop login | see §grok |
xai |
built in | OpenAI-compatible | https://api.x.ai/v1 |
openrouter |
built in | OpenAI-compatible | https://openrouter.ai/api/v1 |
moonshot (Kimi) |
built in | OpenAI-compatible | https://api.moonshot.ai/v1 |
anthropic |
built in | Anthropic Messages | https://api.anthropic.com |
google |
built in | Gemini streamGenerateContent |
https://generativelanguage.googleapis.com |
gemma-local |
built in (every build) | llama.cpp, or a compatible URL | — |
| any name | [[models.providers]] |
openai / anthropic / google | yours |
| any name | installed plugin with [model] |
openai / anthropic / google | the plugin's |
First run
With no usable model, the chat (esc :a) shows a picker that sets one up: local Gemma
(consent, download, SHA256) or a hosted provider (key into the keychain, connection
test). See docs/chat.md §Picking a model. Code: mouser_core::models::setup.
Commands
mouser model default and mouser model test take provider/model, a provider, or
just a model name when only one provider offers it (mouser model default gemma-4-e4b means gemma-local/gemma-4-e4b).
mouser model list # providers, models, * = default
printf %s "$KEY" | mouser model add anthropic --key-stdin # a built-in: key only
mouser model add openai --key-stdin --model gpt-5 --model gpt-5-mini # first = its default
# Any compatible URL (llama-server, Ollama, vLLM, LM Studio, a proxy, …)
mouser model add local --api openai --url http://127.0.0.1:8080/v1 --model qwen3
mouser model add proxy --api anthropic --url https://llm.example.com --key-stdin --model claude-x
# Gemini's OpenAI-compatible endpoint instead of the native one:
mouser model add gemini-compat --api openai --url https://generativelanguage.googleapis.com/v1beta/openai --key-stdin --model gemini-2.5-flash
mouser model default anthropic/claude-sonnet-4-5 # or just a provider: its first model
mouser model test # stream one reply from the default
mouser model test local/qwen3 --prompt "hi" --tool # --tool offers get_time and requires a call
mouser model remove local # also deletes its key
Without --model, mouser model add asks the provider for its models (key in
memory only) and shows a numbered list to pick from on the terminal; Enter takes the
marked one. --model skips the question. With no terminal it uses the provider's
default and says which models it offers.
Keys are checked by shape: a key sent to the wrong provider (a grok_… key to
xai, an xai-… key to openai, …) is refused with a hint naming the right one.
Keys and bearer tokens are redacted from every error and log line.
grok
One provider, three ways to sign in:
# (a) console.x.ai key (xai-…): https://api.x.ai/v1, OpenAI-compatible
printf %s "$XAI_KEY" | mouser model add grok --key-stdin
# (b) grok.com key (grok_…, grok.com/dashboard/api-keys): a Cursor API key, so
# https://api.cursor.com agents (GET /v1/me checks it, GET /v1/models lists models;
# each chat is an agent, follow-ups are runs, replies stream over SSE)
printf %s "$GROK_KEY" | mouser model add grok --key-stdin
# (c) the signed-in Grok Bot desktop app (opt-in): pick one of your agents;
# Mouser sends with sendPrompt and polls its transcript for the reply
mouser model add grok --desktop
mouser model test grok --prompt "hi"
The desktop login reads the Grok Bot app's saved session only when you run
--desktop and on each chat, sends it only to Cursor hosts, and re-reads the app's
files once after a 401/417 (sign in again in the app if it still fails). xai stays
as before for xai- keys.
Configuration
[models]
default = "anthropic/claude-sonnet-4-5"
[[models.providers]]
name = "anthropic"
api = "anthropic" # openai | anthropic | google
url = "https://api.anthropic.com"
key = "keychain:model-anthropic" # a reference; the key is in the OS keychain
models = ["claude-sonnet-4-5"]
# ca = "/path/ca.pem" # trust a self-signed https server
- Keys go to the OS keychain (Keychain, Credential Manager, Secret Service) via
--key-stdin; with no keychain, a 0600 file in$MOUSER_HOME/secrets/with a warning. They are never printed, logged or written to preferences.toml, and are sent only to that provider's URL. Error messages show the server's message, never the request. - Plain
http://is accepted only for this computer (local servers); remote providers needhttps://(Mozilla roots, orca). - Auth: OpenAI-compatible
Authorization: Bearer, Anthropicx-api-key+anthropic-version: 2023-06-01, Googlex-goog-api-key. No key, no header (local).
The interface
trait ModelProvider: Send + Sync {
fn id(&self) -> &str;
fn models(&self) -> Vec<ModelInfo>;
fn chat(&self, req: &ChatRequest, sink: &mut dyn ChatSink) -> Result<()>;
}
// ChatRequest { model, system, messages, tools: Vec<ToolSpec{name, description, schema}>,
// tool_choice: Auto|None|Required|Tool(name), max_tokens, temperature }
// Message { role: User|Assistant, parts: Text | ToolCall{id,name,args} | ToolResult{id,name,content,is_error} }
// ChatSink::event(Text | ToolStart{index,id,name} | ToolArgs{index,delta} | Usage{input,output} | Done{stop})
// ChatSink::cancelled() is polled between stream events; true stops the request.
stop is normalised to end, tool_use, max_tokens (or the provider's own
word). models::Collect assembles a reply into an assistant Message.
Per-model quirks: Kimi K2 models (kimi-k2*) get no temperature, and
tool_choice = Required is sent as auto (Moonshot rejects required). Anthropic
requires max_tokens (default 4096).
Model-provider plugins
A plugin can bring a model by declaring an HTTP endpoint (see
examples/plugins/ollama-model):
name = "ollama-model"
version = "0.1.0"
[[provides]]
kind = "model-provider"
[run]
transport = "http"
[model]
api = "openai"
url = "http://127.0.0.1:11434/v1"
default = "llama3.2"
models = ["llama3.2", "qwen3"]
The local model (gemma-local)
gemma-local is Mouser's own model: Gemma 4 E2B by default and E4B as the
switch (mouser model default gemma-local/gemma-4-e4b). It runs on llama.cpp built
into every Mouser build and package (Vulkan on Linux, Metal on macOS, the CPU on
Windows) or, instead, on any OpenAI/Anthropic-compatible server you name. Nothing is
downloaded until you agree to it.
mouser model local enable # Gemma 4 E2B (or the one already downloaded): asks, downloads, makes it the default
mouser model local enable gemma-4-e4b # the larger model
mouser model local disable # stop offering it; downloads are kept
The chat picker's local rows (esc :a) do the same as enable.
| Weights | File (ggml-org on Hugging Face) | Size |
|---|---|---|
gemma-4-e2b (default) |
gemma-4-E2B-it-Q4_0.gguf |
2.84 GB |
gemma-4-e4b |
gemma-4-E4B-it-Q4_0.gguf |
4.59 GB |
mouser model local # engine, server, models dir, what is downloaded
mouser model local download # shows the size and asks [Y/n]; --yes skips the question
mouser model local download gemma-4-e4b
mouser model local delete gemma-4-e2b
mouser model local dir /mnt/big/models # or MOUSER_MODELS_DIR=…; --clear for the default
mouser model local move /mnt/big/models # move what is downloaded (SHA256-checked), then use that dir
mouser model local url http://127.0.0.1:8080/v1 [--api anthropic] [--model NAME] [--key-stdin]
mouser model local url --clear # back to the built-in engine
mouser model test gemma-local --tool # a tool call, a demo result and the reply
In the app, the [mouser] line model download [gemma-4-e4b] opens an approval popup
with the size, source and destination. It offers only Allow once or Deny,
asks every time and is never saved as a permission. The download then runs in the
background with progress notices.
-
Nothing downloads without consent.
local::downloadneeds aConsentthat only the prompt or popup creates. The.partfile resumes; size and SHA256 (pinned per file) are checked, and a mismatch deletes it. -
Models dir:
$MOUSER_MODELS_DIR, else[models.local] dir, else$MOUSER_HOME/models. To change it, runmouser model local dir DIR, or put this inconfig.toml:[models.local] dir = "/mnt/big/models"mouser model local move DIRmoves weights that are already downloaded. A rename on the same drive is atomic. Across drives, each file is copied and its SHA256 checked before the old copy is removed. -
[models.local]:dir,url,api,key(akeychain:ref),model,gpu_layers(default all) andcontext(default 8192). -
Prompting: the GGUF's own chat template (Jinja, rendered with minijinja), with a Gemma-format fallback. Tools are described in the system turn, and the model answers with
<tool_call>{"name":…,"arguments":…}</tool_call>, which becomes the usual ToolStart/ToolArgs events. -
Timings: set
MOUSER_LLM_TIMINGS=1to print load/prompt/generation speed to stderr.
Building it
llama.cpp is part of the default build (mouser-app's default local-llm feature):
cargo build --release -p mouser-app
- Build needs: cmake and clang everywhere. On Linux also Vulkan headers, shaderc
and spirv-headers (Arch:
cmake clang vulkan-headers shaderc spirv-headers; Debian/Ubuntu:cmake clang libclang-dev libvulkan-dev glslc spirv-headers). - Run needs: the Vulkan loader on Linux (
libvulkan.so.1: Archvulkan-icd-loader, Debian/Ubuntulibvulkan1, Fedoravulkan-loader). The packages depend on it. Without a Vulkan driver (ICD) llama.cpp runs on the CPU. macOS uses Metal (always there). Windows builds llama.cpp for the CPU, so it needs novulkan-1.dll. - Startup: llama.cpp only starts on the first local chat. Starting Mouser never touches the GPU for the model.
- Size: the binary grows by about 44 MB (Linux, Vulkan shaders included). The Arch package goes from 11.4 MB to 21.8 MB.
- Without it:
cargo build --no-default-featuresleaves llama.cpp out.gemma-localthen says so and still works throughmouser model local url.
Measured on a mid-range desktop GPU (Vulkan, E2B Q4_0, warm cache): about 0.9 s to load, about 2,800-5,500 tokens/s on the prompt and about 90-110 tokens/s generating. The NVIDIA driver compiles shaders on first use, so the very first long prompt can take several seconds.
Hugging Face
Any GGUF model on Hugging Face can be downloaded and run on the built-in
llama.cpp engine (gemma-local). In the chat: ⌕ models, h or /hf
(Chat). From the command line:
mouser model hf search qwen 0.5b # GGUF models, most downloaded first: id, download size, ↓downloads, ♥likes
mouser model hf pick [qwen 0.5b] # choose on the terminal: query → model → quantization → install
mouser model hf info bartowski/Qwen2.5-0.5B-Instruct-GGUF # card summary, license, task, size, quantizations
mouser model hf install bartowski/Qwen2.5-0.5B-Instruct-GGUF [Q4_K_M] [--yes]
mouser model hf list # installed ones, with their gemma-local ids
mouser model hf remove Qwen2.5-0.5B-Instruct-Q4_K_M
mouser model test gemma-local/Qwen2.5-0.5B-Instruct-Q4_K_M
- Download size in
search: the smallest to the largest quantization (0.49–8.10 GB; one size when there is one), with split files summed. It comes from each repository's file metadata (/api/models/ID?blobs=true: names and sizes, never weights), at most 6 requests at a time and 15 seconds in all.unknownwhen the Hub didn't answer in time or gave no sizes,no GGUFwhen only projectors orimatrixfiles are there, and a*when some quantizations' sizes are unknown (a missing split part counts as unknown). Vision projectors (mmproj) andimatrixfiles are never counted. - Choosing on the terminal:
mouser model hf pick [QUERY]asks for a query, lists the results with their sizes, then the chosen model's quantizations with each size (the default marked), and hands the choice toinstall: the same question (Download it? [Y/n]), resumable download and checksums. ↑/↓ (orj/k), Page Up/Down, Home/End move; Enter chooses;/searches again; Esc goes back a step (and leaves from the results); Ctrl-C orqleaves; nothing downloads until you answer the question. It needs a terminal: without one it stops at once (scripts usesearchandinstall). The terminal is put back (alternate screen left, cursor shown, settings restored) however it ends. - What runs: GGUF files only (the format llama.cpp loads). A repository's
quantizations (Q2_K … Q8_0, IQ…, BF16, F16, F32) are listed with their sizes;
split files (
-00001-of-00003.gguf) are one choice and download together. Without a quantization,installtakes the smallest Q4. - Checked before download: the model's GGUF architecture (from the Hub) must
be one the llama.cpp bundled with Mouser loads (
hf::LLAMA_CPP_ARCHS, the list in llama-cpp-sys-2 0.1.161) and a chat model.infoand the chat's details say "won't run" and why, and Install refuses, for an unknown architecture ("isn't supported by the llama.cpp bundled with this Mouser"), embedding, encoder, speech and draft models (bert, t5encoder, qwen3tts, eagle3, …), a vision projector on its own (clip) and repositories without GGUF files (safetensors and other formats don't run). When the Hub lists no architecture it says the model is unverified: it may still fail to load, and the chat says so on the first message. Vision projectors (mmproj) are left out of downloads, so models answer with text only, and so areimatrixfiles (calibration data, not models). - Not load-tested: a supported architecture is shown as "supported architecture, not load-tested". Mouser doesn't load a file before you install it, so a new variant of a known architecture (extra MTP heads, say) can still fail on the first message; the chat then shows llama.cpp's error.
- Nothing from the repository runs as code: only
.gguffiles are fetched (no Python, notrust_remote_code); llama.cpp reads the weights, and the GGUF's chat template is rendered by minijinja, a sandboxed template engine. - Consent:
install(and the chat's Install) shows the repository, quantization, size, source, folder and license and downloads only after you agree (Download it? [Y/n]: Enter orydownloads,ncancels; no answer or no terminal cancels);--yesskips the question. Gated models are refused (they need a Hugging Face login, which Mouser doesn't support yet). - Download: to
<models dir>/hf/OWNER--NAME/, resuming a.partfile with HTTP ranges, cancellable (Ctrl+C, or cancel in the chat) and checked against the SHA256 the Hub publishes for each file; a mismatch deletes it. A file with no published SHA256 is not downloaded, a file already there is re-checked rather than trusted by its size, redirects never go from https to plain http, and file names that could leave the folder (.., absolute, backslashes, drive letters) are skipped. - Then: the model is recorded under
[models.local] installedinconfig.toml,gemma-localis enabled, andgemma-local/IDbecomes the default model, so the next chat message uses it.IDis the file name without.gguf(with the owner in front if two repositories have the same file). MOUSER_HF_URLpoints the search and downloads at another Hub (a mirror, or the tests' mock server).
Source: docs/models.md