Skip to content

Move Mux Gateway routing to backend #1769

@ethanndickson

Description

@ethanndickson

Summary

First message in a new workspace can bypass mux‑gateway and fail with “API key not found for anthropic.” Retry succeeds after gateway state syncs. Root cause is frontend/localStorage timing; fix by moving routing decision to backend.

Observed

  • First message fails with API key not found for anthropic
  • Manual retry succeeds via mux-gateway

Root Cause (frontend race)

Gateway routing is determined in the browser via toGatewayModel() + localStorage:

  1. gateway-available defaults to false
  2. useProvidersConfig() loads async
  3. useGateway() writes gateway-available after config loads
  4. First send can happen before sync → model stays anthropic:*

Why name generation still works

Name generation runs on the backend (nameGeneration.generate) and selects a model server‑side via aiService.createModel(), which reads providers.jsonc every time. It can choose mux‑gateway variants even if frontend localStorage is stale.

Proposed Fix

Move gateway routing to the backend:

  • Backend receives canonical provider:model
  • Backend decides mux‑gateway routing from provider config on disk
  • Backend rewrites to mux-gateway:provider/model when enabled
  • Frontend toggles remain UI + send flags, but routing becomes authoritative server‑side

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