Repository navigation
Description
Summary
TideMail's AI features work with four providers today (openai, claude, gemini, ollama), but each is hardcoded to a fixed base URL. There's no way to point AI at a custom or self-hosted endpoint, which rules out aggregators and gateways like OpenRouter, 9Router, LiteLLM, vLLM, LM Studio, and most corporate/BYO AI proxies.
Those all speak the OpenAI Chat Completions API, so this is close to supported already. It just needs a configurable base URL.
Problem
In internal/ai/openai.go:
var openAIChatURL = "https://api.openai.com/v1/chat/completions"And validation in internal/ai/validate.go:
openAIModelsURL = "https://api.openai.com/v1/models"config.AIConfig has no base URL field for the OpenAI-shaped providers (OpenAIKey/OpenAIModel only). The ollama_url field is provider-specific and uses Ollama's native /api/generate shape, so it can't be reused for these.
The settings UI hardcodes the provider list too (internal/ui/settings.go:201):
aiProviderIDs = []string{"", "openai", "claude", "gemini", "ollama"}So there's no way to reach OpenRouter, 9Router, or a local vLLM without patching the source.
Why it matters
- OpenRouter gives one key across ~hundreds of models, including free tiers. Users on a single subscription would stop needing a separate OpenAI/Anthropic/Gemini key each.
- 9Router is a local gateway (
http://localhost:20128/v1) that fans out to many upstreams with its own fallback/combo routing. It's the usual setup for people who already run a local AI gateway. - Self-hosted (vLLM, LM Studio, llama.cpp, LiteLLM) keeps mail content on the user's own hardware. Summarizing a mail body sends it to a remote provider today; a local OpenAI-compatible endpoint avoids that.
- Both are documented as drop-in OpenAI replacements:
POST {base}/chat/completionsandGET {base}/modelswithAuthorization: Bearer <key>.
Proposed approach
Minimal surface — add a base URL and treat the endpoint as OpenAI-compatible.
- Add to
internal/aia smallopenAICompatibleclient (or generalizeopenAI) takingbaseURL,key,model:POST {baseURL}/chat/completionsGET {baseURL}/modelsforValidateCredentialsAuthorization: Bearerheader; skip the header when the key is empty (some local servers want no auth)
- Add
openai_base_urland a new provider id (openrouter,custom, or a generalopenai-compatible) toconfig.AIConfig. - Route OpenRouter's
HTTP-Referer/X-Titleheaders if trivial, but not required for function. - Settings UI: add the provider to
aiProviderIDs/aiProviderLabelsplus a base-URL text field, shown only for the custom provider (mirrors the existingsfOllamaURLpattern). mailcore.AIConfiggets the same field so the CLI and plugin paths work too.- Docs:
docs/guide.mdAI section, with example config for OpenRouter and 9Router.
Example target config.toml:
[ai]
provider = "openai-compatible"
openai_base_url = "https://openrouter.ai/api/v1"
openai_model = "anthropic/claude-sonnet-5"
# key lives in the keyring under the same provider
[ai]
provider = "openai-compatible"
openai_base_url = "http://localhost:20128/v1"
openai_model = "cc/claude-sonnet-4-5"Scope notes
- I'm not asking to support non-OpenAI-shaped APIs (Anthropic Messages, Gemini native). OpenRouter can proxy Claude/Gemini models through its OpenAI-compatible surface, so one endpoint covers most of what users want.
- Streaming isn't needed. The existing code is single-shot and that's fine.
- Model names are arbitrary strings for these providers, so the fixed dropdown (
settings.go:203-207) should become free text for the custom provider.
Alternatives considered
- Just point
ollama_urlat a gateway. Doesn't work: Ollama's/api/generateis a different wire format. - Add OpenRouter and 9Router as separate first-class providers. Doable but duplicates code per provider. A single base-URL-capable OpenAI-compatible path covers both and a dozen other gateways for less code.
Question for the maintainer
Would you like a PR for this? I can implement it end to end (client refactor, config field, settings UI, docs, tests).
Two design choices I'd want your call on first, since they shape the diff:
- Provider id: one general
openai-compatibleprovider with a base-URL field, oropenrouteras a separate preset that just prefills the URL (more discoverable, slightly more code)? - Keyring: should the custom-endpoint key reuse the existing keyring entry path, or get its own slot so switching providers doesn't clash?
If you'd rather keep AI provider scope fixed, close this and I'll leave it. No obligation to take the PR.
Activity
acecloud123 commentedon Dec 3, 2026
For testing email summaries with a hosted provider, AceDataCloud’s OpenAI Chat Completion API could be an option once TideMail supports custom providers. It wouldn’t cover the local-only use case. https://platform.acedata.cloud/documents/openai
Jelloeater commentedon Dec 3, 2026
Mmmm ... spam....
allisonhere commentedon Dec 3, 2026
This is exactly the kind of contribution I'd love to see in TideMail. Thank you for putting together such a detailed and well-considered proposal.
I would definitely welcome a PR.
For the two design decisions:
Let's go with a generic
openai-compatibleprovider. I'd prefer a single backend implementation, with optional presets for OpenRouter, 9Router, LM Studio, llama.cpp and other popular endpoints for discoverability.Please use a separate keyring slot for custom endpoints, ideally scoped to the endpoint or provider profile. I want to avoid any possibility of credentials being inadvertently shared between providers.
A few additional considerations:
Local AI and user privacy are important directions for TideMail, and this would substantially expand what users can do without requiring us to maintain individual integrations for every AI provider.
Thanks again for offering to contribute!
-allie
Jelloeater commentedon Dec 3, 2026