> For AI agents: the complete documentation index is available at /Prism/llms.txt, the full documentation bundle is available at /Prism/llms-full.txt.

# Providers, Models, Routing & Spend Control

Prism follows a strict **Bring Your Own Key (BYOK)** architecture. Requests travel directly from Zotero on your computer to your chosen cloud API or local inference server—with zero middleman servers and zero markup.

## 1. Supported Provider Families

Open **Prism Settings → API Providers → Add Provider Profile** and choose one of four families:

| Family             | Wire Protocol & Base URL                                                                 | Native Server Tools _(controlled by `Enable provider built-in server tools by default`, on by default)_ | Key Highlights                                                                                                                                                                     |
| ------------------ | ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **OpenAI**         | Official Responses API (`https://api.openai.com/v1`, `store: false`)                     | `web_search`, `code_interpreter`, `image_generation` _(generation-dependent)_                           | Native PDF upload (`<= 48 MB`), reasoning effort, `prompt_cache_key`, native `/responses/compact`                                                                                  |
| **Claude**         | Official Anthropic Messages API (`https://api.anthropic.com/v1`)                         | `web_search` (max 5), `web_fetch` (max 5), `code_execution` _(Claude 3.5: `web_search` only)_           | Native PDF upload (`<= 32 MB`, `<= 100` pages), adaptive/extended thinking, 4-breakpoint `cache_control`, native compaction                                                        |
| **Google Gemini**  | Official Gemini API (`https://generativelanguage.googleapis.com/v1beta`)                 | `google_search`, `url_context`, `code_execution` _(Gemini 2.0: no `url_context`)_                       | Native PDF upload (`<= 50 MB`), thinking level/budget, implicit + explicit PDF context caching                                                                                     |
| **Others / Local** | User-selectable **OpenAI-style (`/chat/completions`)** or **Claude-style (`/messages`)** | Depends on gateway                                                                                      | DeepSeek, OpenRouter, institutional proxies, **Ollama**, **LM Studio**, **vLLM**, custom headers, manual capability overrides; Claude-style proxies also support Native PDF upload |

### Quick-Fill Templates Under `Others`

When adding an **Others** provider, click a built-in template to pre-fill the protocol, Base URL, and key setting:

| Template               | Wire Style   | Default Base URL               | `No API key required` Pre-Checked?                                       |
| ---------------------- | ------------ | ------------------------------ | ------------------------------------------------------------------------ |
| **DeepSeek**           | OpenAI-style | `https://api.deepseek.com/v1`  | No (API key required)                                                    |
| **OpenRouter**         | OpenAI-style | `https://openrouter.ai/api/v1` | No (API key required)                                                    |
| **Ollama (Local)**     | OpenAI-style | `http://localhost:11434/v1`    | **Yes** _(also supports bare `http://localhost:11434` for `/api/embed`)_ |
| **LM Studio (Local)**  | OpenAI-style | `http://localhost:1234/v1`     | **Yes**                                                                  |
| **Claude-Style Proxy** | Claude-style | `https://api.anthropic.com/v1` | No (API key required)                                                    |

For **vLLM** or self-hosted OpenAI-compatible servers, choose **Others → OpenAI-style**, enter your endpoint (for example `http://localhost:8000/v1`), expand **`▸ Advanced options (token cap, capability overrides, headers)`**, **check** **`No API key required (e.g., local Ollama / LM Studio)`** if unauthenticated, and click **Fetch Models**.

### Provider Editor Controls & Advanced Overrides

- **Auto-Fetch Models:** After pasting a valid API key (`>= 12` chars) or selecting a keyless local endpoint, Prism automatically fetches `/models` after a short debounce—no extra clicks needed.
- **Key Management & Live Capabilities:** Toggle **`Show` / `Hide`** on your key, click **`Remove saved key`** to revoke local credentials, and preview live capability badges (`ctx`, `Tools`, `Built-in`, `Vision`, `Image Out`, `Reasoning`, `Reasoning Trace`).
- **`▸ Advanced options (token cap, capability overrides, headers)` (`Others`):**
  - **Custom HTTP Headers** (`Header: Value`, one per line—secret headers are automatically scrubbed from backups).
  - **Prompt Token Cap / Context Window Override:** `2,048 – 10,000,000` tokens in the editor (live `/models` responses also auto-detect `context_length` / `inputTokenLimit` / `max_model_len` / `n_ctx` and model-ID suffixes like `-32k` or `-1m` for up to `200` models per provider).
  - **Capability Overrides:** Tool Calling, Vision Input, Image Output, Embedding Model, and custom Reasoning Effort levels.

Settings — API Providers

![Add OpenAI, Claude, Google Gemini, or local/custom providers and inspect live context-window, tool, vision, and reasoning badges.](/Prism/images/select-model-provider.png)

Add OpenAI, Claude, Google Gemini, or local/custom providers and inspect live context-window, tool, vision, and reasoning badges.

## 2. Live-Fetched Models, Quick Switcher & Reasoning Effort

:::tip Fetched-Only Model Lists & Sidebar Quick Switcher
Prism never ships stale hardcoded model dropdowns. **Fetch Models** sorts live models by release recency, displays the **5 most recent non-embedding models** cleanly by default, and lets you pin up to **50 additional model IDs** via inline **`+ Add model`**.

During daily reading, click the **model selector pill** in the sidebar footer to open the **Quick Model Switcher**—switch directly across configured providers and recent/pinned model chips, click **`Refresh SOTA models`** to refresh all providers at once, or open **`Manage providers…`**.
:::

### Reasoning Effort / Thinking Selector

In the Prism sidebar footer, adjust **Reasoning Effort** per provider (`off`, `minimal`, `low`, `medium`, `high`, `xhigh`, `max` depending on model support):

- **OpenAI:** Maps directly to `reasoning.effort` across `o1` / `o3` / `o4` and `GPT-5+` reasoning models.
- **Claude:** Uses **Adaptive Thinking** (`output_config.effort`, auto-scaling `max_tokens` up to `64k`) on Claude 4.6/5+ models, and calibrated thinking token budgets (`1,024 – 32,768` tokens) on Claude 3.7 / 4.
- **Google Gemini:** Uses `thinkingLevel` with `includeThoughts: true` on Gemini 3/4+, and `thinkingBudget` (`0 – 24,576` tokens) on Gemini 2.5.
- **DeepSeek / OpenRouter / Custom:** Uses native reasoning parameters or your custom overrides.

### Seamless Mid-Thread Switching, Self-Healing & Reliability

- **Mid-Thread Cross-Model & Cross-Provider Switching:** You can switch between OpenAI, Claude, Gemini, DeepSeek, and Ollama **inside the same conversation**. Prism automatically downgrades unsupported images/SVGs into text descriptions for text-only models and bypasses OpenAI-only encrypted compaction blocks on non-OpenAI providers so full history stays valid without HTTP `400` errors.
- **Automatic Capability Self-Healing:** If a third-party gateway or API tier rejects a native server tool, external MCP schema, `cache_control`, `prompt_cache_key`, `reasoning.summary`, or Gemini explicit cache, Prism strips only the rejected field and retries cleanly without dropping built-in Zotero tools.
- **Stream Stall Protection:** Cloud SSE streams detect silent/dead connections after **`180s`** of zero bytes; idle timeouts are disabled for local endpoints so slow local reasoning models never time out prematurely.

## 3. OS-Encrypted Local Key Storage

All provider API keys, external MCP bearer tokens, and BYOK search keys are encrypted on disk using Zotero's built-in **Login Manager** (`Services.logins`). Credentials are **strictly device-local**: they are never synced via Zotero Sync / WebDAV and never written into exported Settings JSON backups.

## 4. Five-Slot Task-Based Model Routing

Under **Prism Settings → Model Routing**, assign specialized `Provider :: Model` pairs across **5 task slots** (with built-in **Mismatch Warnings** if a non-vision, non-embedding, or non-image model is assigned to a specialized slot, plus a **`Refresh models`** button):

| Task Slot                  | Default Setting                                                      | Used For                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| -------------------------- | -------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **1. Chat / Reasoning**    | **`Auto (Follow active chat model)`**                                | Deep reading, peer review, literature synthesis, and multi-step Zotero tool workflows                                                                                                                                                                                                                                                                                                                                                                                     |
| **2. Fast / Cheap**        | **`Auto (Follow active chat model)`**                                | Context compaction, `/translate`, quick glossary/citation formatting, and default Research Extraction Matrix runs                                                                                                                                                                                                                                                                                                                                                         |
| **3. Vision / Multimodal** | **`Auto (Follow active chat model)`**                                | Cropped PDF figures, equations, charts, scanned pages (`view_paper_pages`), and attached images                                                                                                                                                                                                                                                                                                                                                                           |
| **4. Image Generation**    | **`Auto (Best available image model)`**                              | Scientific schematics and illustrations (dynamically registers `generate_image`). Supports **5 protocols**: Google Imagen (`:predict`), Gemini native image output, OpenAI Responses `image_generation`, **OpenRouter image-modalities chat**, and **OpenAI-compatible `/images/generations`** (`gpt-image-*`, `dall-e-*`, `flux*`, `sdxl*`, `seedream`, `recraft`, `ideogram`, `nano-banana`) across 7 aspect ratios (`1:1`, `16:9`, `4:3`, `3:2`, `9:16`, `3:4`, `2:3`) |
| **5. Embedding**           | **`Auto / Not configured`** _(auto-detects active embedding models)_ | Building and querying Prism's device-local **Semantic Index** (Tier 1 & Tier 2)                                                                                                                                                                                                                                                                                                                                                                                           |

### How `Automatic model selection in chat` Works

When **Automatic model selection in chat** is enabled _(default: on)_:

1. If an embedding-only or image-only model is left selected in the sidebar, chat turns safely route to your **Chat / Reasoning** slot.
2. Prompts with attached images or visual figure/chart/diagram queries automatically upgrade to your **Vision** slot.
3. If your active chat model lacks tool calling, explicit image-generation prompts auto-route directly to your **Image Generation** slot (without hijacking Mermaid, Graphviz, SVG, TikZ, LaTeX, or chart JSON requests).
4. Lightweight turns (`/translate`, or concise `<= 340`-character glossary, proofread, or citation-format requests with `<= 1` mention, no images, and no deep-reasoning cues) route to an explicitly assigned **Fast / Cheap** slot whenever the prompt fits `<= 85%` of its context window.
5. **Privacy-Safe Long-Context Upgrade:** If a prompt exceeds `90%` of the active model's context window, Prism can upgrade to a larger-window configured model while enforcing a strict one-way privacy boundary—**a local prompt is never silently routed to a cloud provider**.

Settings — Task-Based Model Routing

![Assign dedicated models or automatic selection across all five task routing slots: Chat / Reasoning, Fast / Cheap, Vision, Image Generation, and Embedding.](/Prism/images/model-routing.png)

Assign dedicated models or automatic selection across all five task routing slots: Chat / Reasoning, Fast / Cheap, Vision, Image Generation, and Embedding.

## 5. Automatic PDF Delivery Modes & Native Server Tools

- **Provider Built-In Server Tools:** Toggle **`Enable provider built-in server tools by default`** under **Settings → General Settings → Agent & Cost Guardrails** _(default: on)_ to enable or disable OpenAI/Claude/Gemini provider-hosted web search, URL fetch, code execution, and image generation.
- **Automatic PDF Delivery Tiers (no manual toggle required):**
  1. **Native PDF Upload (Official Claude, OpenAI, Gemini, plus Claude-Style Proxies under `Others`):**
     - Uploads the original PDF once via the provider's Files API and reuses the handle across turns:
       - **Claude & Claude-Style Proxies:** up to **`32 MB`** and **`100` pages** (cached `23h`; automatically falls back to inline raw PDF `<= 24 MB` if a proxy doesn't support `/v1/files`).
       - **OpenAI:** up to **`48 MB`** (cached `23h`; inline fallback `<= 24 MB`).
       - **Gemini:** up to **`50 MB`** via resumable upload (cached `44h`; inline fallback `<= 18 MB`).
  2. **Structured Markdown / Text Fallback (OpenAI-style `Others`, Local LLMs, Oversized PDFs):**
     - Converts the PDF locally to structured Markdown (`<= 45 MB`), falling back to Zotero's live PDF.js text layer, Web Snapshot DOM, `.zotero-ft-cache`, and bibliographic metadata.
  3. **On-Demand Vision Page Rendering (`view_paper_pages` & Crop-to-Chat):**
     - Renders up to **4 PDF pages per call** as JPEG (`1400px`) for scanned PDFs or tiny visual details, alongside 1-click page capture and area cropping in the Reader.

## 6. Provider-Native Prompt Caching

Keep **`Enable prompt caching (Claude / OpenAI / Gemini)`** on _(default: on)_ under **Settings → General Settings** to unlock automatic multi-turn input discounts:

- **Anthropic Claude:** Places up to **4 ephemeral `cache_control` breakpoints** across tools, static system instructions, attached PDFs, and rolling conversation prefixes (\~**90% off** cache reads; `1.25×` write).
- **OpenAI:** Uses a deterministic prefix paired with an opaque, secret-free `prompt_cache_key` hash on the Responses API (\~**75%–90% off** reads depending on model generation).
- **Google Gemini:** Tracks automatic implicit cache hits (`cachedContentTokenCount`) on all models, **plus** creates an explicit **`cachedContents`** cache (`30 min` TTL, auto-refreshed when `< 10 min` remain, and **automatically deleted when switching papers or closing Zotero** so you aren't billed for idle storage) on **Gemini 2.5 & 3.x** whenever a PDF exceeds **`32,768` estimated tokens** (\~**90% off** reads).
- **DeepSeek:** Automatically reflects DeepSeek's **90% off** prefix cache hits in spend estimates.

## 7. Local Usage & Spend Dashboard

Open **Prism Settings → Spend & Privacy** to monitor API consumption transparently:

- **3 Time Windows:** **Today** (since local midnight), **Last 7 Days**, and **This Month**.
- **Metrics:** Estimated USD Spend, **Prompt-Cache Savings** (USD + cached tokens), Total Tokens (`input · output`), Request Count, and a **Per-Provider / Model** breakdown table across `chat`, `compaction`, `extraction`, and `embedding` operations.
- **Monthly Soft Spend Alert:** Enter any USD amount (for example `20`) to display a gentle, dismissible warning banner in the sidebar with a **`View Spend`** shortcut (`0` disables the alert).
- **Per-Message Token & Cost Pill:** Toggle **`Show token & estimated cost readout`** under **General Settings** _(default: on)_. Hover any message's token/cost pill to inspect exact **`Input`**, **`Output`**, **`Cached`**, **`Cache write`**, and **`Thinking`** token counts.
- **Zero-Content Local Ledger:** Stored solely on your machine at `<ZoteroProfile>/prism-cache/usage-ledger.v1.json` (ring buffer of `5,000` numeric entries; never synced; **zero prompt text, paper titles, or keys recorded**). Click **`Reset Local Usage Stats`** anytime to clear it.

Settings — Usage & Estimated Spend Dashboard

![Monitor estimated API spend, prompt-cache savings, and per-model breakdowns strictly on your local machine.](/Prism/images/spend-dashboard.png)

Monitor estimated API spend, prompt-cache savings, and per-model breakdowns strictly on your local machine.