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
        

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.

Building it

llama.cpp is part of the default build (mouser-app's default local-llm feature):

cargo build --release -p mouser-app
        

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
        

Source: docs/models.md