Skip to main content

Provider Fallback

Configure multiple LLM providers. Mercury tries them in order and falls back automatically. When a provider fails, Mercury tries the next one and remembers the last successful provider.

Session Model Switching

You can switch the active provider/model at runtime without restarting Mercury:

  • /models — shows configured providers and current active model
  • /models use <provider> — switches the active session model
  • /models doctor — points to setup flow for adding/configuring providers

This is a session-level switch for the running process. Use mercury doctor to change persisted defaults.

Supported Providers

API Key Providers

ProviderDefault ModelAPI KeyConfiguration
DeepSeekdeepseek-chatDEEPSEEK_API_KEYDefault provider, cost-effective
OpenAIgpt-4o-miniOPENAI_API_KEYGPT-4o-mini, GPT-4o, o3, etc.
Anthropicclaude-sonnet-4-20250514ANTHROPIC_API_KEYClaude Sonnet, Haiku, Opus
Grok (xAI)grok-4GROK_API_KEYOpenAI-compatible endpoint
Ollama Cloudgpt-oss:120bOLLAMA_CLOUD_API_KEYRemote Ollama models via API
Ollama Localgpt-oss:20bNo key neededLocal Ollama instance (127.0.0.1:11434)
OpenAI CompatibleConfigurableOPENAI_COMPAT_API_KEYAny OpenAI-compatible server

OAuth Providers (No API Key Needed)

These providers authenticate through your browser using OAuth device flow — no API key required.

ProviderDefault ModelSubscription RequiredConfiguration
ChatGPT Webgpt-5.4-miniChatGPT Plus or ProUses your ChatGPT subscription
GitHub Copilotgpt-4oGitHub CopilotUses your Copilot subscription

ChatGPT Web (ChatGPT Plus/Pro)

Use your existing ChatGPT Plus or Pro subscription as a Mercury provider. No API key or separate billing — it runs through the same backend as chatgpt.com.

Setup

  1. Run mercury doctor (or first-time mercury setup)
  2. Select OpenAI from the provider list
  3. Choose ChatGPT Plus/Pro (OAuth — use your subscription)
  4. A browser window opens — sign in with your OpenAI account and enter the device code shown in the terminal
  5. Mercury fetches available models from your account and lets you pick a default

How It Works

  • Authenticates via OpenAI's device flow OAuth (same flow used by the Codex CLI)
  • Uses the ChatGPT Responses API at chatgpt.com/backend-api/codex
  • Session tokens are stored locally at ~/.mercury/chatgpt-session.json
  • Access tokens auto-refresh when they expire — no manual re-authentication needed

Available Models

Models are fetched from your account. Typical models available on the codex endpoint include:

  • gpt-5.5, gpt-5.4, gpt-5.4-mini, gpt-5.3-codex, gpt-5.2
Not all ChatGPT models are supported

Only models available on the codex/responses endpoint work with this provider. Some models like gpt-4o, o3, and o4-mini are not available through this endpoint.

Environment Variables

VariableDefaultDescription
CHATGPT_WEB_ENABLEDfalseEnable the ChatGPT Web provider
CHATGPT_WEB_MODELgpt-5.4-miniDefault model to use

GitHub Copilot

Use your GitHub Copilot subscription as a Mercury provider. Authenticates through GitHub OAuth and accesses models through the Copilot API.

Setup

  1. Run mercury doctor (or first-time mercury setup)
  2. Select GitHub Copilot from the provider list
  3. A browser window opens — sign in with your GitHub account and enter the device code shown in the terminal
  4. Mercury fetches available models from the Copilot API and lets you pick a default

How It Works

  • Authenticates via GitHub's device flow OAuth
  • Exchanges the GitHub token for a short-lived Copilot API token (auto-refreshed every ~30 minutes)
  • Uses the Copilot API endpoint with OpenAI-compatible requests
  • Session stored locally at ~/.mercury/github-session.json
  • GitHub OAuth tokens don't expire — they remain valid until revoked on github.com

Available Models

Models are fetched dynamically from the Copilot API. Typical models include:

  • claude-sonnet-4.6, gpt-4o, gpt-5.4, claude-opus-4.6, gpt-4.1, gpt-4o-mini, gemini-3.1-pro-preview
Multi-vendor models through one subscription

GitHub Copilot provides access to models from OpenAI, Anthropic, and Google — all through a single subscription. This makes it one of the most versatile provider options.

Environment Variables

VariableDefaultDescription
GITHUB_COPILOT_ENABLEDfalseEnable the GitHub Copilot provider
GITHUB_COPILOT_MODELgpt-4oDefault model to use
Copilot subscription required

GitHub Copilot must be active on your GitHub account. If the Copilot token exchange fails, Mercury will show: "Is GitHub Copilot enabled for your account?"

Configuring Providers

Run mercury doctor and enter API keys for the providers you want to use. For OAuth providers (ChatGPT Web, GitHub Copilot), the setup flow opens your browser for authentication — no keys to copy/paste.

You can also set environment variables directly or edit ~/.mercury/mercury.yaml.

Environment variables

Each provider has env vars for its API key, base URL, and model. For example, DeepSeek uses DEEPSEEK_API_KEY, DEEPSEEK_BASE_URL, and DEEPSEEK_MODEL. Ollama Local requires no API key — just set OLLAMA_LOCAL_ENABLED=true and OLLAMA_LOCAL_MODEL to your preferred local model.