Skip to content

Support custom OpenAI-compatible AI endpoints (OpenRouter, 9Router, local gateways) #188

Backlog

Description

@Jelloeater

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/completions and GET {base}/models with Authorization: Bearer <key>.

Proposed approach

Minimal surface — add a base URL and treat the endpoint as OpenAI-compatible.

  1. Add to internal/ai a small openAICompatible client (or generalize openAI) taking baseURL, key, model:
    • POST {baseURL}/chat/completions
    • GET {baseURL}/models for ValidateCredentials
    • Authorization: Bearer header; skip the header when the key is empty (some local servers want no auth)
  2. Add openai_base_url and a new provider id (openrouter, custom, or a general openai-compatible) to config.AIConfig.
  3. Route OpenRouter's HTTP-Referer / X-Title headers if trivial, but not required for function.
  4. Settings UI: add the provider to aiProviderIDs/aiProviderLabels plus a base-URL text field, shown only for the custom provider (mirrors the existing sfOllamaURL pattern).
  5. mailcore.AIConfig gets the same field so the CLI and plugin paths work too.
  6. Docs: docs/guide.md AI 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_url at a gateway. Doesn't work: Ollama's /api/generate is 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:

  1. Provider id: one general openai-compatible provider with a base-URL field, or openrouter as a separate preset that just prefills the URL (more discoverable, slightly more code)?
  2. 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

  1. acecloud123 commented on Dec 3, 2026

    @acecloud123

    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

  2. Jelloeater commented on Dec 3, 2026

    @Jelloeater
    Author

    Mmmm ... spam....

  3. allisonhere commented on Dec 3, 2026

    @allisonhere
    Owner

    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:

    1. Let's go with a generic openai-compatible provider. I'd prefer a single backend implementation, with optional presets for OpenRouter, 9Router, LM Studio, llama.cpp and other popular endpoints for discoverability.

    2. 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:

    • Maintain backward compatibility with existing AI configurations.
    • Support optional authentication for local endpoints.
    • Support automatic model discovery where available, with manual model entry as a fallback.
    • Default to HTTPS for remote endpoints while allowing HTTP for localhost.
    • Ensure API keys and email content are never written to logs.
    • Include appropriate tests and documentation.

    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

  4. Jelloeater commented on Dec 3, 2026

    @Jelloeater
    Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions