logancyang_obsidian-copilot/docs/llm-providers.md
Logan Yang d3ee3f999b
fix: agent loop improvements, clickable citations, and UI fixes (#2287)
* fix: prevent agent ReAct loop from getting stuck with small local models

Small local models (e.g. qwen3.5-4b-mlx) get stuck calling localSearch
repeatedly with near-identical queries and never synthesizing an answer.

- Remove QueryExpander from agent loop to avoid model contention on
  single-connection local models (retriever still expands internally)
- Add query deduplication that pre-filters tool call batches using
  Jaccard word-overlap similarity before execution
- Force synthesis via raw model (without tools) after 2 consecutive
  iterations where all tool calls are duplicates
- Add agent-specific system prompt guidance for search limits
- Strip leaked chat template role tokens from intermediate content
- Add intermediate model output logging for debugging

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: make inline citation numbers clickable and restore Max Sources setting

Inline citation numbers like [1], [2] in chat responses are now clickable
links that open the corresponding source note. Also restores the Max Sources
slider in QA settings, reverting the hardcoded DEFAULT_MAX_SOURCE_CHUNKS.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: remove excessive 32px bottom padding from chat view on desktop

The padding-bottom on .view-content used max(safe-area + 4px, 32px),
forcing a 32px minimum even on desktop where safe-area-inset-bottom is 0.
Simplified to safe-area + 4px so desktop gets minimal padding while
devices with safe areas still get proper spacing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix(agent): track dedup queries post-execution to keep failed searches retryable

Move previousSearchQueries tracking from before to after each localSearch tool
call executes. Previously, queries were marked as seen before any tool ran, so
if a call was aborted or the loop threw early, those queries were still blocked
from retrying on the next iteration. Now each query is added to
previousSearchQueries immediately after its tool call returns, keeping the dedup
effective for completed calls while leaving transient failures retryable.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(citations): preserve Obsidian internal-link attributes on inline citation anchors

When building clickable inline citation links (e.g. [1], [2]), the previous code
only copied the href from the source section anchor. Obsidian vault-note links have
additional attributes such as data-href and class="internal-link" that are required
for in-app note navigation. Without them, clicking an inline citation resolves the
link as a plain relative URL instead of opening the corresponding note.

Fix: store the source anchor element rather than just the href, then copy all
attributes onto the generated citation anchor before setting the citation-specific
class and aria-label overrides.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(agent): only mark localSearch queries as seen after successful execution

Change the dedup tracking condition from always tracking queries post-execution
to only tracking when the tool call succeeds (result.success is true). This
ensures transient failures (e.g. temporary index unavailability) leave the
query retryable: if a localSearch fails, the model can issue the same query
again on the next iteration. Previously, even a failed execution would mark
the query as seen, blocking recovery.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix: deduplicate inline citations after source consolidation

When multiple chunks come from the same note, the LLM cites them
separately. After consolidation maps them to the same source number,
adjacent duplicates like [1][1] or [1] and [1] now collapse to [1].

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* chore: update GPT-5.2 to GPT-5.4 in builtin models

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: add dynamic status bar clearance for desktop chat view

The chat input was hidden behind Obsidian's status bar on desktop.
Adds ChatViewLayout which measures the geometric overlap between
the view-content and the status bar, setting a CSS variable to
provide the exact padding needed. Adapts to any theme: no clearance
for auto-hide themes (opacity: 0) or themes that already account
for the status bar in their layout; correct clearance for themes
where the bar is visible and overlapping. Re-checks on theme
switches via debounced css-change listener.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: suppress thinking tokens during streaming when reasoning is disabled

When a local model (e.g. Qwen 3.5 via LM Studio) emits text-level
<think> tags but the user has not enabled the reasoning capability,
the thinking content was visibly rendered during streaming and only
stripped once the </think> tag arrived. Now tracks the position of
excluded think blocks across chunks and truncates fullResponse to
the safe prefix on each chunk, so thinking content never appears.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-14 16:17:37 -07:00

188 lines
6.3 KiB
Markdown

# LLM Providers
Copilot includes 16 built-in AI providers, and you can add an unlimited number of additional models as long as they are OpenAI-compatible. You can use cloud-based services that require API keys, or run models locally on your own machine. This guide explains how to set up each provider.
---
## How to Set API Keys
1. Go to **Settings → Copilot → Basic**
2. Click **Set Keys** to open the API key dialog
3. Enter your key for the provider you want to use
4. Click Save
You can configure multiple providers simultaneously and switch between them by changing the default model.
---
## Cloud Providers
### OpenRouter (Default)
OpenRouter is a gateway that provides access to hundreds of models from many providers through a single API key.
- **Get a key**: https://openrouter.ai/keys
- **Default model**: OpenRouter Gemini 2.5 Flash
- **Why use it**: One key, many models. Good starting point.
- **Setting key**: `openRouterAiApiKey`
### OpenAI
Direct access to GPT-4.1, GPT-5, and other OpenAI models.
- **Get a key**: https://platform.openai.com/api-keys
- **Models include**: GPT-5.4, GPT-5 mini, GPT-5 nano, GPT-4.1, GPT-4.1 mini, GPT-4.1 nano, o4-mini (reasoning)
- **Setting key**: `openAIApiKey`
### Anthropic
Access to Claude models (Opus, Sonnet, etc.).
- **Get a key**: https://console.anthropic.com/settings/keys
- **Models include**: claude-opus-4-6, claude-sonnet-4-5
- **Setting key**: `anthropicApiKey`
### Google Gemini
Access to Google's Gemini family of models.
- **Get a key**: https://makersuite.google.com/app/apikey
- **Models include**: gemini-2.5-pro, gemini-2.5-flash, gemini-3-flash-preview, gemini-3.1-pro-preview
- **Setting key**: `googleApiKey`
### XAI / Grok
Access to Grok models from xAI.
- **Get a key**: https://console.x.ai
- **Models include**: grok-4-1-fast
- **Setting key**: `xaiApiKey`
### Groq
Groq provides very fast inference for open-source models.
- **Get a key**: https://console.groq.com/keys
- **Models include**: llama3-8b-8192 (and others)
- **Setting key**: `groqApiKey`
### Mistral
Access to Mistral AI's models.
- **Get a key**: https://console.mistral.ai/api-keys
- **Models include**: mistral-tiny-latest (and others)
- **Setting key**: `mistralApiKey`
### DeepSeek
Access to DeepSeek's chat and reasoning models.
- **Get a key**: https://platform.deepseek.com/api-keys
- **Models include**: deepseek-chat, deepseek-reasoner
- **Setting key**: `deepseekApiKey`
### Cohere
Access to Cohere's Command models.
- **Get a key**: https://dashboard.cohere.ai/api-keys
- **Models include**: command-r
- **Setting key**: `cohereApiKey`
### SiliconFlow
A Chinese AI cloud platform with access to DeepSeek and Qwen models.
- **Get a key**: https://cloud.siliconflow.com/me/account/ak
- **Models include**: DeepSeek-V3, DeepSeek-R1 (via SiliconFlow)
- **Setting key**: `siliconflowApiKey`
### Azure OpenAI
Access to OpenAI models deployed on Microsoft Azure. Requires four fields to be configured:
| Setting | Description |
|---|---|
| API Key | Your Azure OpenAI key |
| Instance Name | Your Azure resource name |
| Deployment Name | Your model deployment name |
| API Version | e.g., `2024-02-01` |
- **Note**: Unlike other providers, Azure OpenAI uses your own Azure deployment
- **Embedding**: Can also use Azure for embeddings (separate deployment name required)
### Amazon Bedrock
Access to models hosted on AWS Bedrock.
- **Get credentials**: https://console.aws.amazon.com/iam/home#/security_credentials
- **Required fields**: Access Key ID (API key), Region
- **Setting key**: `amazonBedrockApiKey`
**Important**: Always use cross-region inference profile IDs, not bare model IDs. For example:
- Use: `us.anthropic.claude-sonnet-4-5-20250929-v1:0`
- Not: `anthropic.claude-sonnet-4-5-20250929-v1:0`
Cross-region profiles (with the `us.`, `eu.`, `apac.`, or `global.` prefix) are more reliable and available across regions.
### GitHub Copilot
Use your existing GitHub Copilot subscription to access AI models.
- **OAuth flow**: Click **Connect GitHub Copilot** in the API key dialog
- **No separate API key needed** — authenticates via GitHub OAuth
- **Requires**: Active GitHub Copilot subscription
---
## Local Model Providers
Local providers run models on your own computer. No API key or internet connection needed once set up.
### Ollama
Runs open-source models locally on your machine.
- **Default port**: 11434
- **URL**: `http://localhost:11434/v1/`
- **Setup**: Install Ollama (ollama.ai), pull a model, then add it in Copilot's Model settings
- **No API key required**
### LM Studio
A desktop app for running local models with a GUI.
- **Default port**: 1234
- **URL**: `http://localhost:1234/v1`
- **Setup**: Install LM Studio, load a model, go to the Developer tab, **enable CORS** (required), click "Start Server", then add the model in Copilot
- **No API key required**
### 3rd Party (OpenAI-Format)
For any API that follows the OpenAI API format. Useful for custom deployments, proxies, or other local inference servers (vLLM, LiteLLM, etc.).
- **Requires**: Base URL and optionally an API key
- **Use when**: Your provider isn't in the list but speaks OpenAI-format
> **CORS Warning**: Some third-party providers (e.g., Perplexity) don't support CORS, which causes Copilot to fail with a CORS error. When adding a custom model for such a provider, enable the **CORS** toggle in the custom model form. Note: streaming is not available in CORS mode.
---
## Provider-Specific Gotchas
| Provider | Common Issue | Fix |
|---|---|---|
| Azure OpenAI | Missing one of four required fields | Check all four settings: key, instance name, deployment name, API version |
| Amazon Bedrock | Rate limit or model not found | Use cross-region inference profile IDs with `us.`, `eu.`, `apac.`, or `global.` prefix |
| GitHub Copilot | Token expired | Re-authenticate via the OAuth button in API key dialog |
| Ollama | Connection refused | Make sure Ollama is running (`ollama serve`) and the port is correct |
| Google Gemini | Quota exceeded | Use a different model or check your quota at console.cloud.google.com |
| DeepSeek | Streaming errors | Try disabling streaming in the per-session settings if you encounter issues |
---
## Related
- [Models and Parameters](models-and-parameters.md) — Enable, disable, and configure models
- [Getting Started](getting-started.md) — First-time setup