flexx logoflexx docs

Bring Your Own Models (Router)

Add your own model providers — Anthropic, OpenAI, OpenRouter, Groq, or any OpenAI-compatible endpoint — and use them in Flexx Agent or from your own code through one router.

What the Router is

Router is flexx's bring-your-own-model gateway. Instead of scattering provider keys across every tool, you add them once, and flexx gives you:

  • One place for every model — register any provider and its models appear in your model picker.
  • A single endpoint — the router speaks both the OpenAI and Anthropic wire formats, so any SDK works against it unchanged.
  • Budgets and allowlists — router keys (flexxr_…) carry hard daily/monthly spend caps and optional model allowlists, enforced before any upstream call.
  • Shared history — every conversation is logged (scoped by project) and can be distilled into Memory.

You are not locked into flexx's models

Router is provider-neutral. You can point it at a paid provider, a free gateway, or an OpenAI-compatible endpoint you run yourself. Nothing is required to use Flexx Agent beyond at least one registered model.

Supported providers

ProviderHow it connectsNotes
AnthropicAnthropic Messages wire formatDefault base URL https://api.anthropic.com
OpenAIOpenAI chat-completionsDefault base URL https://api.openai.com/v1
OpenRouterOpenAI-compatibleBase URL https://openrouter.ai/api/v1
GroqOpenAI-compatibleBase URL https://api.groq.com/openai/v1
Anthropic-compatibleAnthropic wire formatAny gateway that speaks the Anthropic API — you supply the base URL
CustomOpenAI-compatibleAny OpenAI-compatible endpoint — you supply the base URL

Most third-party gateways speak the OpenAI format, so the presets cover the common cases. Anything else fits under Custom (OpenAI-compatible).

Add a provider

Everything below happens in the dashboard — Models:

  1. Open Dashboard → Models and click Connect a provider.
  2. Pick a provider preset (e.g. OpenRouter) and paste its API key.
  3. Choose how to name the models:
    • Discover models — flexx queries the provider server-side and lists the models your key can reach. Your key never touches the browser beyond the form.
    • Enter model ids — type the exact ids you want (useful for gateways that don't expose a model list).
  4. Register the models you selected.

Your provider key stays server-side

Provider API keys are stored on the server and are never returned to the browser — the dashboard only ever reports whether a key exists. If a model has no key of its own, the router falls back to a key configured for that exact provider.

Pick a default model

After registering models, set a default model for the org. Flexx Agent uses it for new sessions, and you can switch models per session in the model picker.

Use your models in Flexx Agent

Once at least one model is registered, Flexx Agent is ready. Open Flexx Agent, pick a model, and chat — the agent runs every model call through your router, so usage is budgeted and logged. See Flexx Agent.

Use the router from your own code

Because the router speaks both wire formats, any OpenAI or Anthropic SDK can talk to it. Create a router key in Dashboard → Models, then point your client at your router base URL:

# OpenAI-compatible client
OPENAI_BASE_URL=<your-router-base-url>/v1
OPENAI_API_KEY=flexxr_...        # a router key from the dashboard

# Anthropic-compatible client
ANTHROPIC_BASE_URL=<your-router-base-url>
ANTHROPIC_API_KEY=flexxr_...
EndpointWire format
POST /v1/chat/completionsOpenAI chat-completions
GET /v1/modelsOpenAI model list
POST /v1/messagesAnthropic Messages
POST /v1/messages/count_tokensAnthropic token counting

The base URL is wherever your router is reachable. In the hosted product you manage models and keys from the dashboard; when self-hosting, the router runs as its own service (default port 4700) — see Self-Hosting.

Tag traffic with a project scope

Requests can carry x-flexx-project (a git remote) and x-flexx-session headers. Scoped conversations are what the memory distillation job reads from, so tagging your traffic means durable facts eventually land in the right project's memory.

Self-hosting: provider keys on the server

When you run the router yourself, you can supply fallback provider keys through environment variables (used only for the provider they belong to):

VariablePurpose
ROUTER_ANTHROPIC_API_KEYDefault key for anthropic models
ROUTER_OPENAI_API_KEYDefault key for OpenAI's own endpoint
ROUTER_EXTRA_PROVIDERSJSON map of named providers → { baseUrl, apiKey, wireFormat }

A key stored on a model always wins over the environment fallback. A per-model key is required for any non-OpenAI base URL — the router will not send your OpenAI key to a third-party gateway.

On this page