Repository navigation
feat(models): rename published models via strip_free_suffix and aliases - #125
Closed
TiaraBasori wants to merge 7 commits into
Closed
TiaraBasori wants to merge 7 commits into
TiaraBasori wants to merge 7 commits into
Conversation
Clients saw the upstream's marketing suffix, so `deepseek-v4.1-flash-free` appeared in /v1/models even when the deployment only serves the free lane. Two independent knobs, both applied by a single naming pass so discovery and routing cannot disagree: - `models.strip_free_suffix` drops a trailing `-free` from every model and accepts both spellings on input. It needs no maintenance: a model the upstream adds later is renamed on the next refresh. - `models.aliases` pins a name by hand (public name -> upstream id) and always wins over the automatic name, so the two compose. Names change only: requests are routed by the upstream id, responses and SSE frames echo the public name back, and the upstream id keeps working. A stripped name is skipped when it would collide with another servable model, so `x` and `x-free` stay two entries instead of silently merging.
TiaraBasori
force-pushed
the
feat/model-aliases
branch
from
October 18, 2026 13:43
0332f2f to
2255519
Compare
Brings the free-tier v2 shape work from main so the alias branch stays reviewable against the current base. Conflicts were mechanical: - gateway.go: take upstream's shape context and v1ReadTool name, keep the alias resolution and the model echo on stream and response paths. - protocol/stream.go: keep the frameRewriter interface so the model renamer and upstream's streamToolRenamer both satisfy the reader. - protocol/response.go: keep RenameResponseModel alongside the expanded renameToolInMap documentation.
TiaraBasori
force-pushed
the
feat/model-aliases
branch
from
October 20, 2026 11:24
7ef9e98 to
7c503ff
Compare
…breaker) Pick up origin/main (19 commits since v1.4.3): - 2.1.1 client shape: version bump, /inference/openai|anthropic family routes, max_completion_tokens 32000, strict:false tools, client key order, no HTML escaping, runtime-owned Accept/Content-Length (jasonxu114514#141-jasonxu114514#143) - anonymous-lane abuse handling: IP-block detection, per-exit block TTL, circuit breaker (models.anonymous_backoff), max_anonymous_exits cap, deterministic 4xx stops the walk instead of replaying every exit - placeholder key dropping, probe failure classification (jasonxu114514#111), WebUI Cache-Control (jasonxu114514#112), reasoning disable preserved end to end (jasonxu114514#150), Italian README/WebUI Conflict resolutions: - internal/config/config.go, README.md, README.zh-CN.md: kept both sides — the alias fields (aliases/strip_free_suffix) and the new anonymous_backoff block sit side by side in ModelsConfig and the README tables. Local adaptation for this deployment's #pool exit (not upstream): - a #pool transport dials a fresh upstream address on every attempt, so an IP-scoped abuse block cannot be parked on the transport: blocked() and markBlocked() ignore pool transports and the anonymous walk keeps rotating instead of freezing every exit behind one flagged address.
A 429 on the anonymous free lane is the per-IP quota verdict: the /64 the request left from is spent for now, and every further draw from it wastes an attempt and the client's budget. Rotating pools already label each CONNECT with the exit address they drew (X-V6-Exit); the anonymous walk now captures that label on the transport and, on a 429, fires a fire-and-forget POST /ban?addr=<exit> at the pool so it stops minting addresses from that /64. The pool owns the ban lifetime and recheck; the gateway only reports the verdict and keeps walking to a fresh exit. Local-only on top of the upstream merge; not for upstream (the /ban callback protocol belongs to the v6 pool rotator deployment).
The transport-level lastExit snapshot raced: concurrent requests over one shared #pool transport could ban an address another request was still using. BunTransport now stores the labeled exit address (X-V6-Exit) in a per-request context cell while dialing that attempt's tunnel, and the anonymous walk reads exactly that cell on a 429, so each request bans only the exit it actually left from. Verified e2e: two concurrent 429s over one pool transport banned two distinct exits.
# Conflicts: # README.zh-CN.md # internal/gateway/gateway.go
# Conflicts: # internal/gateway/upstream.go
jasonxu114514
added a commit
that referenced
this pull request
Nov 29, 2026
Owner
|
已在 main 以 9b44a03 重新實作並驗證,本 PR 由該提交取代,將納入 v1.5.2。包含 models.aliases、strip_free_suffix、名稱碰撞及原始 ID 相容、Chat/Responses/Anthropic/System One 的串流及非串流模型回顯,並實際重寫 System One 本文;保留請求取消語意。感謝提案;關閉舊分支而不直接合併。 |
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.
动机
模型 id 带着上游的营销后缀,
deepseek-v4.1-flash-free会原样出现在/v1/models里。想对外只叫deepseek-v4.1-flash,目前没有支持的途径——改能力目录或计价元数据都以���游 id 为键,还会连带破坏免费档的请求整形。改动
两个互相独立的开关,由同一趟命名流程统一应用,因此发现列表与路由不会出现分歧:
models.strip_free_suffix(新增,默认false):把所有以-free结尾的模型去掉后缀对外提供,入参两种写法都接受。不需要维护:上游以后新增的模型会在下次刷新时自动改名。models.aliases(新增,默认{}):手工指定名称,键是公开名、值是上游 id。手动别名优先于自动名称,因此可以「全局去后缀 + 个别模型覆盖」。改名只改名字:
/v1/models用公开名列出,能力、上下文、上限、计价仍取自真实模型model字段,不是子串替换,因此不会误改 prompt 或工具参数去后缀后的名称如果与另一个可服务模型重名,该模型保留上游 id,因此
x和x-free仍然是两个模型,不会被静默合并。实现要点
internal/gateway/alias.go中的resolveModel/publicNames是唯一的命名判定入口,请求路径和发现路径共用resolveModel只在候选 id 真的可路由时才改写成-free版本,避免把付费模型错误地映射到免费孪生protocol.RenameStreamModel与protocol.RenameResponseModel分别处理流式与非流式回显;renameStreamReader抽出frameRewriter接口以便复用同一套 SSE 行处理(保留原有\r\n结尾与[DONE]原样透传)配置示例
{ "models": { "strip_free_suffix": true, "aliases": { "beam-pro": "beam-free" } } }效果:
/v1/models返回deepseek-v4.1-flash、mimo-v2.6-flash、beam-pro等,beam-free/deepseek-v4.1-flash-free仍可请求。验证
本地以真实网关跑过:自动去后缀后
/v1/models列出 9 个无-free的名称;非流式响应model回显公开名;流式 13 帧全部为公开名;用原始-free名称请求仍正常返回。