gateway: Cherry Studio's model list has magpie's image and video models (pingqipai3 on X)

pingqipai3 on X: with magpie as a provider in Cherry Studio, its image
generation models weren't read. /v1/models lists chat models alone unless
the caller asks ?kind=image,video, and Cherry can't ask, so its list had
no image model at all, and its Paintings page none of magpie's.

What Cherry reads (CherryHQ/cherry-studio v2.2.1, c74990c): a custom
OpenAI-type provider (the type magpie's Cherry link gives it) is fetched
by listOpenAICompatibleModels, which keeps only id, name and owned_by.
The renderer then resolves each id against Cherry's model registry
(provider-registry models.json, normalizeModelId: the id's last "/"
segment, lower-cased), which carries image-generation for gpt-image-2,
dall-e-3, Gemini's image models, Imagen, Seedream, grok-imagine-image and
~130 more, and video-generation for grok-imagine-video and Seedance. Those
go to Paintings (supportsImageGenerationEndpoint), not the chat picker
(isNonChatModel), so the chat-picker worry behind ?kind= doesn't hold for
Cherry. Its new-api fetcher (new-api, CherryIN, AIOnly presets) reads
supported_endpoint_types instead.

Fix: a request of Cherry Studio's, by the key magpie's link gives it or
by its User-Agent (Electron's default with "CherryStudio/<ver>" in it,
read from Cherry Studio 2.1.2's Electron Framework), gets the image and
video models in its plain list, as ?kind=all would; ?format=text stays
chat. Each image model says supported_endpoint_types ["image-generation"]
(plus "image-edit" when it takes images), each video model
["openai-video"], new-api's words, for every caller. Docs: Cherry
Studio's page (en, zh, ja) and the integration page (md, en, zh).

Run (mote, at 889758605):
- go test -run TestModelsListMedia ./internal/gateway: ok
- go vet darwin, GOOS=linux -tags nogui, GOOS=windows on internal/gateway;
  gofmt -l clean
Broken by hand: listKinds' media set false for Cherry:
TestModelsListMediaForCherryStudio red for the UA, Cherry 1.x's UA and
the link's key (image and video rows missing).
Not tried: a real Cherry Studio fetching the list (it would write the
user's live Cherry database); the registry lookup was read from Cherry's
source, not run. Full suite runs after the tag.
This commit is contained in:
yetone
2026-11-13 12:53:04 +08:00
parent d6a6865b1f
commit 15e1d65bcd
8 changed files with 96 additions and 8 deletions
+3 -1
View File
@@ -64,7 +64,9 @@ API's own field (`reasoning_effort`, `reasoning.effort`, Anthropic's
line. The list holds chat models only. Ask for image and video models
with `?kind=image,video` (or `?kind=chat,image,video`, or `?kind=all`).
Each of them is marked `"kind": "image"` or `"kind": "video"` and goes to
`/v1/images/generations` or `/v1/videos`, never to a chat route.
`/v1/images/generations` or `/v1/videos`, never to a chat route. Cherry
Studio, which can't ask and tells an image model from a chat one by its
id, is listed every kind.
**A vendor's own fields.** `/v1/images/generations` and `/v1/videos`
take OpenAI's fields and pass the others on to a vendor that takes them:
+29 -3
View File
@@ -1568,9 +1568,15 @@ func drawerObjects(r *http.Request) []map[string]any {
"owned_by": p.ID, "display_name": name, "magpie_label": name + " · " + p.Name,
"modalities": map[string]any{"input": []string{"text"}, "output": []string{"image"}},
"magpie_via": catalog.ViaHere(m.Via)}
// the endpoints it is drawn through, in new-api's words, which
// Cherry Studio's new-api provider reads its kind from
// (listModels.ts newApiFetcher): image-generation first
ends := []string{"image-generation"}
if m.Images {
o["modalities"] = map[string]any{"input": []string{"text", "image"}, "output": []string{"image"}}
ends = append(ends, "image-edit")
}
o["supported_endpoint_types"] = ends
out = append(out, o)
}
}
@@ -1595,8 +1601,9 @@ func videomakerObjects(r *http.Request) []map[string]any {
name := cmp.Or(m.Name, m.ID)
out = append(out, map[string]any{"id": p.ID + "/" + m.ID, "object": "model", "type": "model", "kind": "video", "created": 0,
"owned_by": p.ID, "display_name": name, "magpie_label": name + " · " + p.Name,
"modalities": map[string]any{"input": []string{"text", "image"}, "output": []string{"video"}},
"magpie_via": catalog.ViaHere(m.Via)})
"modalities": map[string]any{"input": []string{"text", "image"}, "output": []string{"video"}},
"supported_endpoint_types": []string{"openai-video"},
"magpie_via": catalog.ViaHere(m.Via)})
}
}
return out
@@ -1641,10 +1648,21 @@ func catalogFor(r *http.Request) []provider.Entry {
// Cherry Studio's, ZCode's pasted ?format=text) would offer an image model
// in their chat pickers (axelburks on Discord asked for them here). A kind
// it doesn't know is refused, not read as none.
//
// Cherry Studio is the exception: it can't ask, and it tells an image model
// from a chat one itself. Its provider of magpie (an OpenAI-compatible one)
// reads only each id, then looks the id's last segment up in its own model
// registry (provider-registry's models.json, by normalizeModelId), which
// marks gpt-image-2, dall-e-3, the gemini-*-image, imagen, seedream and
// grok-imagine models as image generation: those go to its Paintings page,
// not its chat picker (isNonChatModel). Without them listed, Paintings had
// no model of magpie's (pingqipai3 on X). So it is listed every kind.
func listKinds(r *http.Request) (chat, image, video bool, err error) {
q, ok := r.URL.Query()["kind"]
if !ok {
return true, false, false, nil
// a list of ids pasted somewhere (?format=text) stays chat models
media := cherryStudio(r) && r.URL.Query().Get("format") != "text"
return true, media, media, nil
}
for _, v := range q {
for k := range strings.SplitSeq(v, ",") {
@@ -1665,6 +1683,14 @@ func listKinds(r *http.Request) (chat, image, video bool, err error) {
return chat, image, video, nil
}
// cherryStudio is a request of Cherry Studio's: with the key magpie's link
// gives it (agentOf), or a key the user typed in by hand, by its User-Agent,
// Electron's own with the app's name in it ("Mozilla/5.0 (…)
// CherryStudio/2.1.2 Chrome/… Electron/…").
func cherryStudio(r *http.Request) bool {
return agentOf(r) == "cherrystudio" || strings.Contains(r.Header.Get("User-Agent"), "CherryStudio/")
}
func (s *Server) models(w http.ResponseWriter, r *http.Request) {
// Antigravity's app's catalog, each model with its window (antigravity_models.go)
if r.URL.Query().Get("format") == AntigravityFormat {
+59 -2
View File
@@ -14,7 +14,7 @@ import (
// caller asks: ?kind=image,video (or all), each marked by its "kind". No
// agent's list, the plain one, Claude Desktop's, Claude Science's,
// Cursor's, OpenCode's or the ids of ?format=text, gains an image or a
// video model.
// video model. Cherry Studio's does (TestModelsListMediaForCherryStudio).
func TestModelsListMediaOnlyWhenAsked(t *testing.T) {
grokSignedIn(t)
newGrokMedia(t)
@@ -45,14 +45,18 @@ func TestModelsListMediaOnlyWhenAsked(t *testing.T) {
agents := map[string]map[string]string{
"plain": nil,
"opencode": {"User-Agent": "opencode/1.2.3"},
"cherry": {"User-Agent": "CherryStudio/1.5"},
"claude-desktop": {"User-Agent": "Mozilla/5.0 (Macintosh) Claude/1.2.3 Chrome/130"},
"science": {"X-Anthropic-Surface": "operon", "User-Agent": "Anthropic/JS 0.60.0"},
"cursor": {"User-Agent": "Cursor-CLI/1.0"},
"magpie-key": {"Authorization": "Bearer magpie-acme"},
// Cherry Studio's list has them, its text list (a paste) not
"cherry-text": {"User-Agent": cherryUA},
}
for name, header := range agents {
rows := list("/v1/models", header)
if name == "cherry-text" {
rows = nil
}
if len(rows) == 0 && name == "plain" {
t.Fatalf("plain list is empty")
}
@@ -100,3 +104,56 @@ func TestModelsListMediaOnlyWhenAsked(t *testing.T) {
}
}
}
// Cherry Studio 2.x's User-Agent, Electron's default with the app's name in
// it, as Cherry Studio 2.1.2 sends it.
const cherryUA = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) CherryStudio/2.1.2 Chrome/146.0.7680.65 Electron/44.2.0 Safari/537.36"
// pingqipai3 on X: with magpie as a provider in Cherry Studio, its image
// models weren't there to pick. Cherry can't ask for ?kind=, and reads an
// image model's kind itself (its model registry, by the id's last
// segment), so its plain list, by its User-Agent or by the key magpie's
// Cherry link gives it, has the image and video models, each with the
// endpoints a new-api provider of Cherry's reads; its chat models stay.
func TestModelsListMediaForCherryStudio(t *testing.T) {
grokSignedIn(t)
newGrokMedia(t)
h := New().Handler()
type row struct {
ID, Kind string
Endpoints []string `json:"supported_endpoint_types"`
}
for name, header := range map[string]map[string]string{
"user-agent": {"User-Agent": cherryUA},
"cherry 1.x": {"User-Agent": "CherryStudio/1.5"},
"link's key": {"Authorization": "Bearer magpie-cherrystudio"},
} {
r := httptest.NewRequest("GET", "/v1/models", nil)
for k, v := range header {
r.Header.Set(k, v)
}
w := httptest.NewRecorder()
h.ServeHTTP(w, r)
var l struct{ Data []row }
if w.Code != 200 || json.Unmarshal(w.Body.Bytes(), &l) != nil {
t.Fatalf("%s: %d %s", name, w.Code, w.Body)
}
got := map[string]row{}
chat := 0
for _, m := range l.Data {
got[m.ID] = m
if m.Kind == "" {
chat++
}
}
if chat == 0 {
t.Errorf("%s: no chat models", name)
}
if m := got["grok/grok-imagine-image"]; m.Kind != "image" || len(m.Endpoints) == 0 || m.Endpoints[0] != "image-generation" {
t.Errorf("%s: image model %+v", name, m)
}
if m := got["grok/grok-imagine-video"]; m.Kind != "video" || !slices.Equal(m.Endpoints, []string{"openai-video"}) {
t.Errorf("%s: video model %+v", name, m)
}
}
}
+1
View File
@@ -204,6 +204,7 @@
<h2 id="models"><a class="anchor" href="#models">Pick the models</a></h2>
<p>Cherry Studio lists a provider’s models from <code>/v1/models</code>, so the magpie provider offers every model magpie has, named <code>provider/model</code> (for example <code>deepseek/deepseek-v4-pro</code>). Add the ones you want to the magpie provider in Cherry Studio, and choose them in a chat like any other model.</p>
<p>The list has magpie’s image and video models too. Cherry Studio knows most of them by name (gpt-image-2, Gemini’s image models, Imagen, Seedream, Grok Imagine…) and offers them on its <span class="ui">Paintings</span> page, not in a chat. For one it doesn’t know, open the model’s settings in the magpie provider and tick image generation.</p>
<p>A provider you add in magpie later shows up the next time Cherry Studio fetches the list; there is nothing to change in Cherry Studio. Several accounts behind one model, rest periods after a 429 and failover work as they do for every agent.</p>
<h2 id="cli"><a class="anchor" href="#cli">From a terminal</a></h2>
+1 -1
View File
@@ -176,7 +176,7 @@ curl -s http://127.0.0.1:3425/v1/models -H "Authorization: Bearer magpie-acme"</
<p>On this machine the gateway takes any key. Send <code>magpie-&lt;your-app-id&gt;</code> (<code>Authorization: Bearer magpie-acme</code>, or <code>x-api-key</code>) and every call is counted as <code>acme</code> in Usage, the Requests log and the routing rules that match on agents. Without it, magpie counts the call by the first word of your <code>User-Agent</code> (<code>Acme/1.4 (darwin)</code> is <code>Acme</code>); an SDK’s own User-Agent (<code>OpenAI/JS …</code>, <code>ai-sdk/…</code>) would count it as that SDK. From another computer (<span class="ui">Settings</span> → <span class="ui">Share on local network</span>) the key must be one of the user’s gateway keys, and the User-Agent names your app.</p>
<h3>Models</h3>
<p><code>GET /v1/models</code> lists what the user has turned on: <code>id</code> (<code>provider/model</code>, or a routing group’s name, sent as it is), <code>display_name</code>, <code>owned_by</code> (the provider), <code>reasoning</code> and <code>supported_reasoning_levels</code> (<code>[{"effort":"low"},…]</code>, and the same as plain names in <code>reasoning_levels</code>), <code>context_window</code> and <code>max_output_tokens</code> when known, and <code>modalities</code> when magpie knows whether it takes images. List them from there rather than shipping a list: the user adds and removes providers in magpie. Reasoning is asked in your API’s own field (<code>reasoning_effort</code>, <code>reasoning.effort</code>, Anthropic’s <code>thinking</code> or <code>output_config.effort</code>). <code>?format=text</code> gives the ids one a line. The list holds chat models alone: ask for image and video models with <code>?kind=image,video</code> (or <code>?kind=all</code>). Each is marked <code>"kind": "image"</code> or <code>"video"</code> and is made on <code>/v1/images/generations</code> or <code>/v1/videos</code>, not a chat route.</p>
<p><code>GET /v1/models</code> lists what the user has turned on: <code>id</code> (<code>provider/model</code>, or a routing group’s name, sent as it is), <code>display_name</code>, <code>owned_by</code> (the provider), <code>reasoning</code> and <code>supported_reasoning_levels</code> (<code>[{"effort":"low"},…]</code>, and the same as plain names in <code>reasoning_levels</code>), <code>context_window</code> and <code>max_output_tokens</code> when known, and <code>modalities</code> when magpie knows whether it takes images. List them from there rather than shipping a list: the user adds and removes providers in magpie. Reasoning is asked in your API’s own field (<code>reasoning_effort</code>, <code>reasoning.effort</code>, Anthropic’s <code>thinking</code> or <code>output_config.effort</code>). <code>?format=text</code> gives the ids one a line. The list holds chat models alone: ask for image and video models with <code>?kind=image,video</code> (or <code>?kind=all</code>). Each is marked <code>"kind": "image"</code> or <code>"video"</code> and is made on <code>/v1/images/generations</code> or <code>/v1/videos</code>, not a chat route. Cherry Studio, which can’t ask and tells an image model from a chat one by its id, is listed every kind.</p>
<p>A vendor’s own fields: <code>/v1/images/generations</code> and <code>/v1/videos</code> take OpenAI’s fields and pass the others on to a vendor that takes them, such as Volcengine Ark’s <code>content</code> (reference video and audio, <code>draft_task</code>), <code>ratio</code>, <code>resolution</code>, <code>duration: -1</code>, <code>tools</code>, <code>watermark</code> and <code>sequential_image_generation</code>, and a video’s answer carries Ark’s own fields (<code>content.last_frame_url</code>, <code>usage</code>). For the rest of a vendor’s API use <code>/v1/magpie/native/&lt;provider&gt;/&lt;path&gt;</code>: <code>GET</code>, <code>POST</code>, <code>PUT</code>, <code>PATCH</code> or <code>DELETE</code>, with <code>&lt;path&gt;</code> joined to the provider’s host (not its base URL), in the vendor’s own shape on the user’s key for that provider, a stream as it comes; Ark’s task list is <code>GET /v1/magpie/native/ark/api/v3/contents/generations/tasks</code>. It serves a provider added with an API key, not a subscription or sign-in, and Ark’s short paths (<code>images/generations</code>, <code>contents/generations/tasks</code>) still work under the key’s base. It takes the same gateway key as every route, and a key held to models, accounts or a budget is refused it.</p>
+1
View File
@@ -204,6 +204,7 @@
<h2 id="models"><a class="anchor" href="#models">モデルを選ぶ</a></h2>
<p>Cherry Studio はプロバイダのモデル一覧を <code>/v1/models</code> から取得するので、magpie プロバイダには magpie のすべてのモデルが <code>プロバイダ/モデル</code> の名前(例:<code>deepseek/deepseek-v4-pro</code>)で並びます。使いたいモデルを Cherry Studio の magpie プロバイダに追加し、チャットでほかのモデルと同じように選びます。</p>
<p>一覧には magpie の画像・動画モデルも入ります。Cherry Studio はその多く(gpt-image-2、Gemini の画像モデル、Imagen、Seedream、Grok Imagine…)を名前で見分け、チャットではなく<span class="ui">ペイント</span>ページに出します。見分けられないモデルは、magpie プロバイダでそのモデルの設定を開き、画像生成にチェックを入れます。</p>
<p>あとで magpie に追加したプロバイダは、Cherry Studio が次に一覧を取得したときに出ます。Cherry Studio 側の変更は要りません。一つのモデルの裏の複数アカウント、429 後の休止、フェイルオーバーは、ほかのエージェントと同じように働きます。</p>
<h2 id="cli"><a class="anchor" href="#cli">ターミナルから</a></h2>
+1
View File
@@ -204,6 +204,7 @@
<h2 id="models"><a class="anchor" href="#models">选择模型</a></h2>
<p>Cherry Studio 从 <code>/v1/models</code> 获取供应商的模型列表,所以 magpie 供应商提供 magpie 里的全部模型,名称是 <code>供应商/模型</code>(例如 <code>deepseek/deepseek-v4-pro</code>)。在 Cherry Studio 的 magpie 供应商里添加你要的模型,然后在对话中像其他模型一样选用。</p>
<p>列表里也有 magpie 的图像和视频模型。Cherry Studio 认得其中大多数(gpt-image-2、Gemini 的图像模型、Imagen、Seedream、Grok Imagine…),把它们放在<span class="ui">绘画</span>页里,不放进对话。它不认得的,在 magpie 供应商里打开该模型的设置,勾选图像生成。</p>
<p>之后在 magpie 里新增的供应商,会在 Cherry Studio 下次获取列表时出现,Cherry Studio 这边无需改动。一个模型背后的多个账号、429 后的休息时间和故障转移,都和其他 Agent 一样生效。</p>
<h2 id="cli"><a class="anchor" href="#cli">命令行</a></h2>
+1 -1
View File
@@ -176,7 +176,7 @@ curl -s http://127.0.0.1:3425/v1/models -H "Authorization: Bearer magpie-acme"</
<p>在本机,网关接受任意 key。发送 <code>magpie-&lt;你的应用 id&gt;</code>(<code>Authorization: Bearer magpie-acme</code>,或 <code>x-api-key</code>),每次调用都会在用量、请求记录以及按 Agent 匹配的路由规则里记为 <code>acme</code>。不带它时,magpie 按 <code>User-Agent</code> 的第一个词统计(<code>Acme/1.4 (darwin)</code> 记为 <code>Acme</code>);SDK 自带的 User-Agent(<code>OpenAI/JS …</code>、<code>ai-sdk/…</code>)会被记成那个 SDK。从另一台电脑访问时(<span class="ui">设置</span> → <span class="ui">局域网共享</span>),key 必须是用户的网关密钥之一,应用名就靠 User-Agent。</p>
<h3>模型</h3>
<p><code>GET /v1/models</code> 列出用户打开的模型:<code>id</code>(<code>provider/model</code>,或路由组的名字,原样发送即可)、<code>display_name</code>、<code>owned_by</code>(供应商)、<code>reasoning</code> 与 <code>supported_reasoning_levels</code>(<code>[{"effort":"low"},…]</code>;同样的档位以纯名字列在 <code>reasoning_levels</code>),已知时还有 <code>context_window</code>、<code>max_output_tokens</code>,以及 magpie 知道是否支持图片时的 <code>modalities</code>。请从这里读取,而不是内置一份列表:用户会在 magpie 里增删供应商。推理强度用你所用 API 自己的字段传(<code>reasoning_effort</code>、<code>reasoning.effort</code>、Anthropic 的 <code>thinking</code> 或 <code>output_config.effort</code>)。<code>?format=text</code> 每行一个 id。列表只有对话模型:要图像和视频模型,请加 <code>?kind=image,video</code>(或 <code>?kind=all</code>),它们带 <code>"kind": "image"</code> 或 <code>"video"</code>,在 <code>/v1/images/generations</code> 或 <code>/v1/videos</code> 上生成,不走对话接口。</p>
<p><code>GET /v1/models</code> 列出用户打开的模型:<code>id</code>(<code>provider/model</code>,或路由组的名字,原样发送即可)、<code>display_name</code>、<code>owned_by</code>(供应商)、<code>reasoning</code> 与 <code>supported_reasoning_levels</code>(<code>[{"effort":"low"},…]</code>;同样的档位以纯名字列在 <code>reasoning_levels</code>),已知时还有 <code>context_window</code>、<code>max_output_tokens</code>,以及 magpie 知道是否支持图片时的 <code>modalities</code>。请从这里读取,而不是内置一份列表:用户会在 magpie 里增删供应商。推理强度用你所用 API 自己的字段传(<code>reasoning_effort</code>、<code>reasoning.effort</code>、Anthropic 的 <code>thinking</code> 或 <code>output_config.effort</code>)。<code>?format=text</code> 每行一个 id。列表只有对话模型:要图像和视频模型,请加 <code>?kind=image,video</code>(或 <code>?kind=all</code>),它们带 <code>"kind": "image"</code> 或 <code>"video"</code>,在 <code>/v1/images/generations</code> 或 <code>/v1/videos</code> 上生成,不走对话接口。Cherry Studio 没法这样要,它按 id 自己分辨图像模型和对话模型,所以给它的列表包含所有种类。</p>
<p>厂商自己的字段:<code>/v1/images/generations</code> 和 <code>/v1/videos</code> 读 OpenAI 的字段,其余字段原样转给支持它们的厂商,比如火山方舟的 <code>content</code>(参考视频、参考音频、<code>draft_task</code>)、<code>ratio</code>、<code>resolution</code>、<code>duration: -1</code>、<code>tools</code>、<code>watermark</code>、<code>sequential_image_generation</code>;视频的回答也带上方舟自己的字段(<code>content.last_frame_url</code>、<code>usage</code>)。厂商 API 的其他部分请用 <code>/v1/magpie/native/&lt;provider&gt;/&lt;path&gt;</code>:支持 <code>GET</code>、<code>POST</code>、<code>PUT</code>、<code>PATCH</code>、<code>DELETE</code>,<code>&lt;path&gt;</code> 接在服务商的域名后面(不是 base URL 后面),按厂商自己的格式收发,用的是用户为这个服务商填的密钥,流式回答边到边转;比如方舟的任务列表是 <code>GET /v1/magpie/native/ark/api/v3/contents/generations/tasks</code>。只服务用 API 密钥添加的服务商,不服务订阅或登录的账号;方舟原来的短路径(<code>images/generations</code>、<code>contents/generations/tasks</code>)照旧接在密钥的 base 后面。它和其他接口一样需要网关密钥;限了模型、账号或额度的密钥不能用它。</p>