feat: add third-party backend account support (upstream, modelMap, models)#74
Merged
Conversation
…dels) - Per-account `upstream` URL routes requests to any Anthropic-compatible API (e.g. DeepSeek, GLM) instead of the global upstream - `modelMap` rewrites the request body's model name before forwarding, with Content-Length updated to match the new body size - `models` array declares model-name ownership: when any account claims a model, only those accounts are eligible for requests that name it — enabling per-session backend selection via --model or /model without affecting other sessions - Third-party accounts set to a higher priority value act as transparent fallbacks when all Claude accounts are exhausted
MagicalTux
added a commit
that referenced
this pull request
Jul 6, 2026
#74 shipped the third-party-backend feature (per-account upstream/modelMap/ models) with no tests. Add coverage for both surfaces: - Model-ownership routing in AccountManager: ownership is inert until some account declares a `models` list; an owned model routes only to owning accounts; the [Nm] suffix is stripped when matching; a Claude model claims no owner so Claude accounts stay eligible; the third-party account acts as a priority fallback; an owned model whose only owner is unavailable selects nothing; two accounts can co-own a model. - Request-body model rewrite (server.rewriteModel, now exported for tests): maps a known model, updates the byte length so Content-Length can be corrected, and passes through unchanged for an unmapped model, a non-JSON body, or a body with no model field. 163 tests pass, lint clean. No behavior change beyond exporting rewriteModel. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This was referenced Jul 6, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
src/account-manager.jsupstream,modelMap, andmodelsfields to the account object(both the constructor map and
addAccount)_accountOwnsModel(account, model): when any account declares amodelslist, only accounts that also list the requested model are eligiblefor that request — accounts without a matching entry are skipped at selection
time, alongside the existing
disabled/quota/Fable checks_isAvailableafter the existing Fable-exhaustion gatesrc/server.jsaccount.upstream || upstreamso each account cantarget a different base URL without touching the global config
rewriteModel(body, modelMap): parses the request body as JSON, rewritesthe
modelfield using the account'smodelMap, and re-serializes; returnsthe original buffer unchanged if the model isn't in the map or the body isn't
valid JSON
Content-Lengthafter rewriting: the model name change shifts the bodysize, so the header is updated to match before the request is forwarded
Behavior
Fallback: a third-party account with a higher
priorityvalue (lower =preferred) sits idle while Claude accounts have headroom. When they're
exhausted it takes over, and
modelMaptranslates e.g.claude-sonnet-4-6→deepseek-v4-pro[1m]transparently — no change needed in the claude session.Explicit routing: a
modelslist lets a session opt in to a specificbackend by naming one of its models directly (
--model "deepseek-v4-pro[1m]"on launch or/model deepseek-v4-pro[1m]inside a session). Other sessions are unaffected.Example config
{ "name": "deepseek", "type": "oauth", "accessToken": "sk-...", "upstream": "https://api.deepseek.com/anthropic", "priority": 100, "modelMap": { "claude-haiku-4-5-20251001": "deepseek-v4-flash", "claude-sonnet-4-6": "deepseek-v4-pro[1m]" }, "models": ["deepseek-v4-pro[1m]", "deepseek-v4-pro", "deepseek-v4-flash"] }