diff --git a/docs/integrating.md b/docs/integrating.md index 7707cbd87..a62cec1c5 100644 --- a/docs/integrating.md +++ b/docs/integrating.md @@ -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: diff --git a/internal/gateway/gateway.go b/internal/gateway/gateway.go index 1e537cf18..45f11f90f 100644 --- a/internal/gateway/gateway.go +++ b/internal/gateway/gateway.go @@ -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 { diff --git a/internal/gateway/models_kind_test.go b/internal/gateway/models_kind_test.go index ad141d0f1..731da43e9 100644 --- a/internal/gateway/models_kind_test.go +++ b/internal/gateway/models_kind_test.go @@ -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) + } + } +} diff --git a/site/public/docs/cherry-studio.html b/site/public/docs/cherry-studio.html index 3af0fc380..3d3fcb863 100644 --- a/site/public/docs/cherry-studio.html +++ b/site/public/docs/cherry-studio.html @@ -204,6 +204,7 @@

Pick the models

Cherry Studio lists a provider’s models from /v1/models, so the magpie provider offers every model magpie has, named provider/model (for example deepseek/deepseek-v4-pro). Add the ones you want to the magpie provider in Cherry Studio, and choose them in a chat like any other model.

+

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 Paintings page, not in a chat. For one it doesn’t know, open the model’s settings in the magpie provider and tick image generation.

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.

From a terminal

diff --git a/site/public/docs/integrate.html b/site/public/docs/integrate.html index dabbdfa0c..9ddde31d0 100644 --- a/site/public/docs/integrate.html +++ b/site/public/docs/integrate.html @@ -176,7 +176,7 @@ curl -s http://127.0.0.1:3425/v1/models -H "Authorization: Bearer magpie-acme"On this machine the gateway takes any key. Send magpie-<your-app-id> (Authorization: Bearer magpie-acme, or x-api-key) and every call is counted as acme 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 User-Agent (Acme/1.4 (darwin) is Acme); an SDK’s own User-Agent (OpenAI/JS …, ai-sdk/…) would count it as that SDK. From another computer (Settings → Share on local network) the key must be one of the user’s gateway keys, and the User-Agent names your app.

Models

-

GET /v1/models lists what the user has turned on: id (provider/model, or a routing group’s name, sent as it is), display_name, owned_by (the provider), reasoning and supported_reasoning_levels ([{"effort":"low"},…], and the same as plain names in reasoning_levels), context_window and max_output_tokens when known, and modalities 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 (reasoning_effort, reasoning.effort, Anthropic’s thinking or output_config.effort). ?format=text gives the ids one a line. The list holds chat models alone: ask for image and video models with ?kind=image,video (or ?kind=all). Each is marked "kind": "image" or "video" and is made on /v1/images/generations or /v1/videos, not a chat route.

+

GET /v1/models lists what the user has turned on: id (provider/model, or a routing group’s name, sent as it is), display_name, owned_by (the provider), reasoning and supported_reasoning_levels ([{"effort":"low"},…], and the same as plain names in reasoning_levels), context_window and max_output_tokens when known, and modalities 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 (reasoning_effort, reasoning.effort, Anthropic’s thinking or output_config.effort). ?format=text gives the ids one a line. The list holds chat models alone: ask for image and video models with ?kind=image,video (or ?kind=all). Each is marked "kind": "image" or "video" and is made on /v1/images/generations or /v1/videos, 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.

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, such as Volcengine Ark’s content (reference video and audio, draft_task), ratio, resolution, duration: -1, tools, watermark and sequential_image_generation, and a video’s answer carries Ark’s own fields (content.last_frame_url, usage). For the rest of a vendor’s API use /v1/magpie/native/<provider>/<path>: GET, POST, PUT, PATCH or DELETE, with <path> 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 GET /v1/magpie/native/ark/api/v3/contents/generations/tasks. It serves a provider added with an API key, not a subscription or sign-in, and Ark’s short paths (images/generations, contents/generations/tasks) 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.

diff --git a/site/public/docs/ja/cherry-studio.html b/site/public/docs/ja/cherry-studio.html index 785009288..7c32c721d 100644 --- a/site/public/docs/ja/cherry-studio.html +++ b/site/public/docs/ja/cherry-studio.html @@ -204,6 +204,7 @@

モデルを選ぶ

Cherry Studio はプロバイダのモデル一覧を /v1/models から取得するので、magpie プロバイダには magpie のすべてのモデルが プロバイダ/モデル の名前(例:deepseek/deepseek-v4-pro)で並びます。使いたいモデルを Cherry Studio の magpie プロバイダに追加し、チャットでほかのモデルと同じように選びます。

+

一覧には magpie の画像・動画モデルも入ります。Cherry Studio はその多く(gpt-image-2、Gemini の画像モデル、Imagen、Seedream、Grok Imagine…)を名前で見分け、チャットではなくペイントページに出します。見分けられないモデルは、magpie プロバイダでそのモデルの設定を開き、画像生成にチェックを入れます。

あとで magpie に追加したプロバイダは、Cherry Studio が次に一覧を取得したときに出ます。Cherry Studio 側の変更は要りません。一つのモデルの裏の複数アカウント、429 後の休止、フェイルオーバーは、ほかのエージェントと同じように働きます。

ターミナルから

diff --git a/site/public/docs/zh/cherry-studio.html b/site/public/docs/zh/cherry-studio.html index 625584d90..36c2bce08 100644 --- a/site/public/docs/zh/cherry-studio.html +++ b/site/public/docs/zh/cherry-studio.html @@ -204,6 +204,7 @@

选择模型

Cherry Studio 从 /v1/models 获取供应商的模型列表,所以 magpie 供应商提供 magpie 里的全部模型,名称是 供应商/模型(例如 deepseek/deepseek-v4-pro)。在 Cherry Studio 的 magpie 供应商里添加你要的模型,然后在对话中像其他模型一样选用。

+

列表里也有 magpie 的图像和视频模型。Cherry Studio 认得其中大多数(gpt-image-2、Gemini 的图像模型、Imagen、Seedream、Grok Imagine…),把它们放在绘画页里,不放进对话。它不认得的,在 magpie 供应商里打开该模型的设置,勾选图像生成。

之后在 magpie 里新增的供应商,会在 Cherry Studio 下次获取列表时出现,Cherry Studio 这边无需改动。一个模型背后的多个账号、429 后的休息时间和故障转移,都和其他 Agent 一样生效。

命令行

diff --git a/site/public/docs/zh/integrate.html b/site/public/docs/zh/integrate.html index 01e0e8dc1..434ae2387 100644 --- a/site/public/docs/zh/integrate.html +++ b/site/public/docs/zh/integrate.html @@ -176,7 +176,7 @@ curl -s http://127.0.0.1:3425/v1/models -H "Authorization: Bearer magpie-acme"在本机,网关接受任意 key。发送 magpie-<你的应用 id>(Authorization: Bearer magpie-acme,或 x-api-key),每次调用都会在用量、请求记录以及按 Agent 匹配的路由规则里记为 acme。不带它时,magpie 按 User-Agent 的第一个词统计(Acme/1.4 (darwin) 记为 Acme);SDK 自带的 User-Agent(OpenAI/JS …、ai-sdk/…)会被记成那个 SDK。从另一台电脑访问时(设置 → 局域网共享),key 必须是用户的网关密钥之一,应用名就靠 User-Agent。

模型

-

GET /v1/models 列出用户打开的模型:id(provider/model,或路由组的名字,原样发送即可)、display_name、owned_by(供应商)、reasoning 与 supported_reasoning_levels([{"effort":"low"},…];同样的档位以纯名字列在 reasoning_levels),已知时还有 context_window、max_output_tokens,以及 magpie 知道是否支持图片时的 modalities。请从这里读取,而不是内置一份列表:用户会在 magpie 里增删供应商。推理强度用你所用 API 自己的字段传(reasoning_effort、reasoning.effort、Anthropic 的 thinking 或 output_config.effort)。?format=text 每行一个 id。列表只有对话模型:要图像和视频模型,请加 ?kind=image,video(或 ?kind=all),它们带 "kind": "image" 或 "video",在 /v1/images/generations 或 /v1/videos 上生成,不走对话接口。

+

GET /v1/models 列出用户打开的模型:id(provider/model,或路由组的名字,原样发送即可)、display_name、owned_by(供应商)、reasoning 与 supported_reasoning_levels([{"effort":"low"},…];同样的档位以纯名字列在 reasoning_levels),已知时还有 context_window、max_output_tokens,以及 magpie 知道是否支持图片时的 modalities。请从这里读取,而不是内置一份列表:用户会在 magpie 里增删供应商。推理强度用你所用 API 自己的字段传(reasoning_effort、reasoning.effort、Anthropic 的 thinking 或 output_config.effort)。?format=text 每行一个 id。列表只有对话模型:要图像和视频模型,请加 ?kind=image,video(或 ?kind=all),它们带 "kind": "image" 或 "video",在 /v1/images/generations 或 /v1/videos 上生成,不走对话接口。Cherry Studio 没法这样要,它按 id 自己分辨图像模型和对话模型,所以给它的列表包含所有种类。

厂商自己的字段:/v1/images/generations 和 /v1/videos 读 OpenAI 的字段,其余字段原样转给支持它们的厂商,比如火山方舟的 content(参考视频、参考音频、draft_task)、ratio、resolution、duration: -1、tools、watermark、sequential_image_generation;视频的回答也带上方舟自己的字段(content.last_frame_url、usage)。厂商 API 的其他部分请用 /v1/magpie/native/<provider>/<path>:支持 GET、POST、PUT、PATCH、DELETE,<path> 接在服务商的域名后面(不是 base URL 后面),按厂商自己的格式收发,用的是用户为这个服务商填的密钥,流式回答边到边转;比如方舟的任务列表是 GET /v1/magpie/native/ark/api/v3/contents/generations/tasks。只服务用 API 密钥添加的服务商,不服务订阅或登录的账号;方舟原来的短路径(images/generations、contents/generations/tasks)照旧接在密钥的 base 后面。它和其他接口一样需要网关密钥;限了模型、账号或额度的密钥不能用它。