Skip to content

Chat: OpenRouter as a chat provider on Windows and Linux (chat only) - #161

Open
4rchila wants to merge 1 commit into
Louis-CFM:mainfrom
4rchila:pr/openrouter-chat
Open

4rchila wants to merge 1 commit into
Louis-CFM:mainfrom
4rchila:pr/openrouter-chat

Conversation

@4rchila

@4rchila 4rchila commented Oct 3, 2026

Copy link
Copy Markdown

What

OpenRouter as a second chat provider on Windows and Linux, next to the Claude API. On macOS the chat already supports Google AI and OpenAI; the Tauri build only had Anthropic. OpenRouter gives access to many models through one key, including free ones, which makes the chat usable without an Anthropic API key.

How

  • openai_compat.rs: a small OpenAI-compatible /chat/completions client, built like claude.rs:
    • multi-turn history on the Rust side; only successful turns enter it;
    • the key lives in the keychain (openrouter-api-key added to KNOWN_KEYS), never on disk and never in the front end;
    • chat only: no tools are sent, so the model can answer but never act on the machine;
    • images (data URL) and text files ride along with the first message, like the Claude chat; PDFs are not sent (no portable document part in the OpenAI format);
    • readable errors for 401 (bad key), 402 (no credits) and 429 (rate limit, common on free models).
  • openrouter_models command: OpenRouter's public catalogue (no key needed), text-output models, free ones first.
  • Settings → Chat provider: choose Claude API or OpenRouter, save/remove the key, pick a model with a "Free only" filter.
  • chat_send dispatches on settings.chatProvider (default "anthropic", so nothing changes for existing users); chat_reset clears both histories.

New settings fields have serde defaults, so older settings.json files still load. No new dependency (reqwest and serde_json were already there). Network calls only go to openrouter.ai once the user picks OpenRouter (the model list is fetched when Settings opens).

Testing

  • Fedora 44 / KDE Plasma: saved a key, loaded the model list (free filter on and off) and chatted with a free model.
  • tsc --noEmit, vite build and cargo check --release pass with no new warnings.
  • Not tested on Windows (no machine), but the code is platform-independent.

Screenshots

Settings → Chat provider (taken from my local build; the duplicated "(free) (free)" label and the "KWallet / Secret Service" wording visible there are already fixed in this PR: OpenRouter's free model names already contain "(free)", and the hint now just says "system keychain"):

- openai_compat.rs: multi-turn chat against OpenRouter's
  /chat/completions. No tools are sent, so the model can only answer.
  Key in the system keychain (openrouter-api-key), never on disk.
  Clear errors for 401/402/429. Images and text files ride along with
  the first message; PDFs are not sent.
- openrouter_models: public catalogue, text models, free ones first.
- Settings -> Chat provider: choose Claude API or OpenRouter, save the
  key, pick a model (Free only filter). chat_send dispatches on
  settings.chatProvider; chat_reset clears both histories.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant