routing: Fast keeps the provider's extra-body Ultrafast; a relay's GPT model can go Ultrafast (KoiLx0 on X)
KoiLx0 on X: with Azure or another provider that takes service_tier
"ultrafast", the group's speed toggle stopped at Fast, and they asked
whether the group's Fast overwrites {"service_tier": "ultrafast"} put
in the provider's extra request body. Before this commit it did. A member
sent fast got service_tier "priority" in its body before the extra body
was merged. A non-forced extra-body field only fills in a missing value,
so "priority" went upstream. Only "!service_tier" survived.
Precedence now:
- Member not sent fast: as before. The agent's own tier is kept, and the
extra body's service_tier fills in when the agent sends none.
- Member sent Fast: priority. If the provider's extra body asks for
"ultrafast", it is sent ultrafast, so Fast is never sent slower than
the user asked of the provider. A slower extra-body tier (flex) gives
way to the toggle, which the user set on this member.
- Member sent Ultrafast: ultrafast.
- A forced "!service_tier" in the extra body still goes over all of
these as written.
The same holds for an agent's fast pick (same member loop).
Ultrafast on a provider the user added by its address (OwnFast): the
toggle goes on to Ultrafast for a GPT model when OpenAI offers the tier
on that model. That is known when one of Codex's accounts lists it, or
when Codex's own entry in models_cache.json for the slug does
(codexcat.OwnOffers). Codex itself is already offered the tier on such a
provider from that same entry (ownTiers). Like its Fast, Ultrafast is
only asked for. A provider that turns the field away is asked again
without it. Other vendors and OpenAI's own API are unchanged. The
Ultrafast button's tooltip on such a provider says the tier is asked of
the provider (new string in zh, zh-TW, ja, de).
Tests, red on the old code:
- TestFastMemberOwnProviderExtraTier: the outgoing body for each
combination of group speed and extra body, from Chat, Responses and
Anthropic agents. Old code sent "priority" for "fast + extra ultrafast"
and for "Ultrafast".
- TestCanUltraOwnProvider: old code returned false for a relay's
gpt-6.1-sol that Codex's entry offers Ultrafast on.
- group-member-fast.test.cjs: an own provider's member steps usual,
Fast, Ultrafast and saves ultra; one with no Ultrafast steps back to
usual. en/zh, Chromium and WebKit.
Docs: gateway-routing.md (a group member's speed) and
providers-accounts.md (Extra body) say the precedence and the
Ultrafast rule.
Run on mote at df2652f63 (base b0d634b85), log kept whole:
- gofmt -l internal: nothing.
- go vet (darwin) provider, gateway, codexcat, gui, agent; GOOS=linux
and GOOS=windows go vet provider, gateway, codexcat: clean.
- go test -timeout 45m -count=1 provider (176s), gateway (1017s),
codexcat, agent (275s), settingsapi: ok. go test -tags nogui gui: ok.
- GUI on mica, Chromium and WebKit: group-member-fast, model-speed,
routing-service-tier, i18n-keys, i18n-en-no-cjk pass. fast-ultra is
red the same way on b0d634b85 (extra POST /api/update/using, #6201).
- Broken by hand: the new Go tests red on the old sources (above).
Rebased onto 338eae3c2 (provider/models.go, remote groups) after
4f40a1061 (sessions, agent/codex.go, app.js, i18n.js; none
of this change's files). At that head, on mica: TestLoopGuardLeavesOrdinaryRepliesAlone (reads
the two edited docs), TestFastMemberOwnProviderExtraTier,
TestGroupMemberUltrafast and TestCanUltraOwnProvider ok; at 338eae3c2
plus this, go vet and go test of provider (143s) and codexcat, and
gateway's fast, ultra, model-tier and loop-guard tests: ok.
Not tried: a real request to Azure or a relay that serves "ultrafast";
the whole GUI suite; a Linux or Windows run beyond cross-vet.
This commit is contained in:
@@ -254,7 +254,7 @@ recorded as a prediction failure (`noPrediction`).
|
||||
- A failed call is in `app.log` too, not only the Routing page and the usage ledger (wjh66 on Discord: Codex's "error decoding response body" after "reconnecting 5/5", and the log had nothing of the turn). `record` writes each call whose status is 400 or more, or that carries an error, as one line (`failedCallLine`: agent, model, provider, status, time, the error to 300 characters); the same failure again within a minute is counted into the next line, not written (`failedLogEvery`), so a client asking in a loop can't fill the log. A Codex reply relayed from the ChatGPT backend that ends before its last event also says which side ended it (`codexEndedEarly` in [`codex_backend.go`](../../internal/gateway/codex_backend.go)): the read of OpenAI's stream that failed, with its error, or a clean end; and the client gone, a write to it that failed, or the failure passed on as `response.failed`, with the bytes passed on. reqwest, Codex's HTTP client, says "error decoding response body" for any read of a body whose connection broke, so only this line tells the legs apart. A gateway that ends with requests still in flight logs that they were cut (`srv.Shutdown`'s error; on Windows there is no handover, so an update or quit cuts a stream after `shortDrain`) (`TestCodexReplyBrokenOffLogged`, `TestCodexClientGoneLogged`, `TestFailedCallLineOncePerMinute`).
|
||||
- Each record keeps the service tier three ways (#1784): `tier_asked` is what the client's body asked (`bodyTier`; Claude's speed fast reads `fast`), `tier_sent` is what that try's last request went out with, noted in `forwardOnce` after every rewrite (fast picks, Ultrafast to priority on a plan without it) onto the per-attempt `wireAt`, and `tier_served` is only what the reply said it ran at (`upstreamTier`, read by the sniffer and the translated readers), empty when it says nothing; from the ChatGPT backend (CodexBase's host) its `auto` and `default` are empty too, since it says them whether priority ran or not (`servedTierAt`, applied in `attempt` and `codexUpstreamOn`). The route's tries carry `tier` and `tier_served` the same way, on Codex's own sign-in (`codexUpstreamOn`) too, which before set only the route's `tier`, so a `/fast` turn there showed nothing (Anotiaww on X). The Routing page's request row shows a try's tier as a quiet tag beside the model (`fast` for `priority`, `Ultrafast`, `flex`; an in-flight row the route's asked tier), with the served tier in its title when the reply said another (`rowTier` in [`plugins/routing/client.js`](../../internal/gui/assets/plugins/routing/client.js), `routing-service-tier.test.cjs`). A bridge that doesn't go through `forwardOnce` (the Claude subscription, Cursor's built-in) leaves `tier_sent` empty. Through a Remote magpie the other magpie's word is taken (JackyFill on X: Codex → magpie1 → magpie2 → a ChatGPT account, Fast on in magpie2 alone, was logged `default` on magpie1): a try asked by another magpie (`magpieAsks`) says on its reply's header the tier it sent its vendor (`X-Magpie-Tier-Sent`, `none` for none) and, when that vendor's `auto`/`default` tell nothing, `X-Magpie-Tier-Unsaid: 1` (`stampTier`, from the holdWriter's `writeHeader`). The asking magpie takes them from a remote magpie's reply alone (`tierThere` in `heardReply`; a vendor's `X-Magpie-` headers are never passed) and records them as its try's `tier_sent` (`sentThere`) and an unknown `tier_served` (`servedThere`); a chain of magpies passes the farthest one's on. A reply whose headers a keepalive sent before the try answered carries neither, and the asking magpie keeps its own record. Code: [`tier_record.go`](../../internal/gateway/tier_record.go).
|
||||
- An agent's fast pick (`settings.FastPicks`, the bolt in its picker, #954) may also be in `settings.UltraPicks` (#1954), offered by the GUI only where one of Codex's accounts lists Ultrafast on the model (`provider.CanUltra`, `UltraModels`). `fastPick` marks its candidates `ultra`; a try of one goes with `service_tier: "ultrafast"` on Chat and Responses, and an agent on Messages carries it in the context (`withUltra`) to `forwardTranslated`, which sets `Request.Ultrafast` for the ChatGPT backend. Either way the same check as a client's own Ultrafast ask applies, now on Chat as well as Responses: an account whose list doesn't offer it is put after a mate that does (`tierMate`), or, with none left, sent `priority`. A Chat body's own `service_tier: "ultrafast"` is parsed as Ultrafast too (`chat.go`). `TestUltraPickSentUltrafast`.
|
||||
- A group's member may be Ultrafast as well as fast (`Group.Ultra`, a subset of `Fast`, `Group.SetMemberTier`; the member's button steps Standard speed, Fast, Ultrafast where `ultraOK`; `ultra=` in `magpie group`), and a model has its own speed (`settings.ModelTiers`, "<provider>/<model>" to `priority` or `ultrafast`, `provider.SetModelTier`, Model settings and `magpie model tier`; kdajenks on X). The gateway sends it on a direct pick for an agent with no fast pick of its own (`provider.ModelTier`, the branch after `IsFastPick`), through the same `fastPick`, so an account without Ultrafast is sent `priority`. A group member goes as the group says. `TestModelTierSentToEveryAgent`, `TestGroupMemberUltrafast`, `model-speed.test.cjs`.
|
||||
- A group's member may be Ultrafast as well as fast (`Group.Ultra`, a subset of `Fast`, `Group.SetMemberTier`; the member's button steps Standard speed, Fast, Ultrafast where `ultraOK`; `ultra=` in `magpie group`), and a model has its own speed (`settings.ModelTiers`, "<provider>/<model>" to `priority` or `ultrafast`, `provider.SetModelTier`, Model settings and `magpie model tier`; kdajenks on X). The gateway sends it on a direct pick for an agent with no fast pick of its own (`provider.ModelTier`, the branch after `IsFastPick`), through the same `fastPick`, so an account without Ultrafast is sent `priority`. A group member goes as the group says. On a provider the user added by its address (`OwnFast`, a GPT or o-series model on an OpenAI API) the member's button goes on to Ultrafast when OpenAI offers the tier on the model: one of Codex's accounts lists it, or Codex's own `models_cache.json` entry for the slug does (`codexcat.OwnOffers`, the entry `ownTiers` already offers Codex), and the tier is only asked for, as its Fast is: a provider that turns the field away is asked again without it (KoiLx0 on X). A fast member never goes slower than the provider's extraBody asks: its `service_tier` `ultrafast` (forced or not) makes a Fast member go Ultrafast (`extraUltra`), a slower one (`flex`) gives way to the member's Fast, and a forced `!service_tier` still goes as written over all of them (`TestFastMemberOwnProviderExtraTier`, `TestCanUltraOwnProvider`, `group-member-fast.test.cjs`). `TestModelTierSentToEveryAgent`, `TestGroupMemberUltrafast`, `model-speed.test.cjs`.
|
||||
- Codex's service tier (`settings.CodexServiceTier`, a row in Codex's settings, JackyFill on X) sets the `service_tier` of every request of Codex's, whatever Codex's own `/fast` asked: empty is as Codex asks (the default, nothing changed), `default` sends none (standard), `priority` is Codex's Fast and `ultrafast` its Ultra Fast (the request values in Codex's `ServiceTier`; Flex is not offered, since the ChatGPT backend's requests drop it in `codex_request.go`). `codexTiered` ([`codex_tier.go`](../../internal/gateway/codex_tier.go)) rewrites the body as it comes in, on both of Codex's ways in: `codexBackend` (Codex signed in, `/backend-api/codex`) and the main handler's Codex-on-Responses block, which a websocket turn reaches too. Everything after treats it as Codex's own ask: an account whose list lacks Ultrafast is put after a mate that offers it (`tierMate`) or sent `priority`, and a provider that refuses a tier drops it. A model with no provider (`gpt-…`, Codex's own sign-in, whose plan magpie doesn't know) is sent `ultrafast` only where one of magpie's Codex accounts lists it on the model (`UltraModels`), else `priority`. Another agent's request is never touched, and fast picks still apply after. `TestCodexServiceTierSet`, `codex-service-tier.test.cjs`.
|
||||
- The Codex client magpie presents to the ChatGPT backend (`settings.CodexClient`, a row in Codex's settings, ouhthuo on X) is Codex CLI by default (`originator: codex_cli_rs`, `User-Agent: codex_cli_rs/<ver> (<os>; <arch>) <terminal>`) or `desktop`: `originator: Codex Desktop` and `Codex Desktop/<ver> (<os>; <arch>) unknown (Codex Desktop; <app build>)`, as codex-rs `default_client.rs` builds it from the originator the app sets. Only these two values are accepted. `codexClientHeaders` in `internal/provider/codex_request.go` is the one place both headers are set, so a model request (`codexSign`), the account calls (`/wham`, resets, token refresh, device sign-in) and a test asked as Codex all follow it; the sign-in's authorize URL keeps `codex_cli_rs`. A real Codex client's own originator never reaches the backend on a signed-in account: `codexSign` replaces it, which this setting now chooses.
|
||||
- A usage record carries its prompt's cache beside `in` and `out` (#1839): `cache_read` (tokens read from the vendor's cache) and `cache_write` (cache creation, Anthropic's `cache_creation_input_tokens`; `cache_write_1h` the part written for an hour). `in` holds neither. Both are written on every record, 0 too, so a prompt that missed the cache reads as that. A record from before then has neither and reads as 0. Every route fills them: Anthropic's messages, Chat (OpenAI's `prompt_tokens_details.cached_tokens`, DeepSeek's `prompt_cache_hit_tokens`, Moonshot's top-level `cached_tokens`, Mistral's older top-level `num_cached_tokens`), Responses (`input_tokens_details.cached_tokens`) and Gemini (`cachedContentTokenCount`), passed through or translated, whole or streamed, a plugin's fetch, and the Claude subscription bridge. System One's decision calls report no cache. `TestUsageRecordsCacheTokensOnEveryRoute`, `TestPluginUsageRecordsCacheTokens`, `TestClaudeSubscriptionUsageKeepsCacheTokens`, `TestRecordAlwaysCarriesCacheTokens`.
|
||||
|
||||
@@ -26,7 +26,7 @@ keys and accounts per request is in [Gateway routing and fallback](gateway-routi
|
||||
| A Zen free model on OpenCode Go | OpenCode's two gateways serve different free models: Zen's free tier (`/zen`, asked with the public key `OpenCodeAnonymousKey`) serves its `-free` models and big-pickle, Go (`/zen/go`, a Go key) only a few of its own (beam-free, iceman-contributor-free on 2026-11-02). Go answers a model it doesn't serve 400 "Upstream request failed: Model is unavailable." before it reads the key, so Claude Code asking one of Zen's free models on an OpenCode Go provider failed on every request (51bit.eth on Discord). Such a request, a free model by `OpenCodeFree`, is asked once more at Zen's free tier on the same API (`openCodeGoToZenFree`, `OpenCodeFreeURL`), with the public key and never the user's Go key (`RetryOpenCodeFreeOnZen`, in the gateway's `forwardOnce`); a model that isn't free isn't. Refused there too, or not free, the 400 keeps Go's words and says where the model is served. Not changed: when Go's `/models` refuses the key, the provider lists models.dev's `opencode-go`, which names free models Go doesn't serve (#4900). | [`opencode_go_free.go`](../../internal/provider/opencode_go_free.go) |
|
||||
| OpenCode Go endpoints | Go's docs name one URL per API under `/inference/go`: `/openai/v1` (chat, Responses), `/anthropic` (Messages), `/google/v1beta` (Gemini, `models/{id}:streamGenerateContent`). The preset gives them (`OpenCodeGoChat`, `OpenCodeGoAnthropic`, `OpenCodeGoGemini`); a provider of the preset saved with the older `/zen/go` or `/inference/go/v1` URLs is moved on load, and one added by hand with a single Go URL gets the rest filled beside it (`openCodeEndpoints`). A URL the user gave another API stays. | [`opencode_endpoints.go`](../../internal/provider/opencode_endpoints.go) |
|
||||
| Zhipu's 200 refusals | Zhipu's and Z.ai's `/api/v1` (the GLM Coding Plan's Responses API, from their Codex pages) and `/api/monitor` answer a refusal 200 in the platform's envelope, `{"code":1000,"msg":"身份验证失败。","success":false}`, where their OpenAI and Anthropic endpoints answer the same key 401 (@xanahopper on X: a refused key tested green on the Responses row only). `ZhipuEnveloped` turns a 2xx JSON body from `open.bigmodel.cn` or `api.z.ai` with `success: false` into `{"error":{"code","message"}}` at the status Zhipu's error-code table gives (1000–1005 → 401, 1113 and 1302–1399 → 429, 1220 → 403, 1210–1229, 1261 and 1301 → 400, anything else → 502), in the provider test's `probe` (endpoint tests, model tests, Detect APIs) and the gateway's `forwardOnce`. A stream, a compressed body, a body over 64 KB and every other host pass as they came. The plan's quota card for a key refused there (1000–1005, or a 401) says `<Zhipu or Z.ai> didn't take this key (<their words>): …` with the vendor's API-keys page (`zhipuRefused`), not asked again as a team's key, and the GUI shows it as that (`quotaError`) rather than "Allowance unavailable". | [`zhipu_envelope.go`](../../internal/provider/zhipu_envelope.go), [`planquota.go`](../../internal/provider/planquota.go), [`test.go`](../../internal/provider/test.go) |
|
||||
| Extra body | `ExtraBody` (`extraBody` in providers.json, the editor's *Extra body*, #1604) is a JSON object whose fields `WithExtraBody` adds at the top level of every JSON body sent to the provider: Messages, Chat, Responses and Gemini, relayed as they came or translated, in the gateway's `forwardOnce` and in Test and Detect (`tested`). A field the body has already is kept; a name written `"!name"` replaces it. Values are put in as written, objects whole, not merged. `${sessionId}` in any string, at any depth, becomes the request's session: the agent's session header (`sessionOf`), else the id `conversationID` derives from how the conversation opens (`magpie-` and its hash, [Gateway routing](gateway-routing.md#responsibilities-and-sources-of-truth)'s Affinity), so it stays the same through one conversation; Test and Detect send `magpie-test-` and 12 random letters, a new one each time. `${threadId}` is the thread the agent names within that session: Codex's `thread_id` (its turn metadata or `thread-id` header, `threadOf`), which a subagent has of its own while it shares its lead's session; read only when the provider's headers or extraBody name it (`AsksThread`). No other agent names a thread, and there `${threadId}` is the session's id. `${subagentId}` becomes the Claude Code subagent the request is of (`x-claude-code-agent-id`, `subOf`), "" on the conversation's own turns, which never send the header, so `${sessionId}:${subagentId}` keeps one prompt_cache_key per subagent where `${sessionId}` alone carries every subagent's turns on one key (#2937). `model`, `stream` and the conversation (`messages`, `input`, `contents`, `system`, `systemInstruction`, `system_instruction`, `instructions`, `tools`, `ExtraBodyReserved`) are magpie's: Save refuses them with or without `!` (`ExtraBodyOK`), the editor says so as they are typed, and one written into providers.json by hand is dropped on read (`cleanExtraBody`). Not sent with it: `count_tokens`, embeddings, images, video and System One's decision model (other APIs), and a signed-in account's requests, except a ChatGPT (Codex) account's (magpie-releases#18): its requests are built as Codex CLI's (`codexBody`) and take the fields Codex CLI adds by choice, such as `access_programs` (OpenAI's Daybreak), while `store`, `tool_choice` and `include`, which the backend needs as `codexBody` sets them, can't be set (`codexOwned`). Its extraBody is written into providers.json by hand under the account's entry and kept onto the account by `withPicks`, and kept by a later `Save` (#4738: `Save` dropped it before); the editor has no box for it. A client's own top-level `access_programs` on Responses or Chat is carried to a Responses build as it came (`Request.AccessPrograms`), so a request translated (a Codex account is streamed, so a whole Responses request is made again) keeps it as a relayed one does. It reaches only the upstreams Codex itself sends it to (`keepsAccessPrograms`, #3172, see [gateway routing](gateway-routing.md)); it is taken out before the extraBody merge, so an `access_programs` the user puts in a provider's extraBody still goes. One object goes to every API; fields for one API alone are not a thing yet. A `thinking` budget it puts in on an Anthropic endpoint is fitted to a Claude that thinks only adaptively after the merge, as an agent's is (`adaptiveThinking`, `TestExtraBodyBudgetFittedToAdaptiveModel`). | [`extrabody.go`](../../internal/provider/extrabody.go), [`gateway.go`](../../internal/gateway/gateway.go) |
|
||||
| Extra body | `ExtraBody` (`extraBody` in providers.json, the editor's *Extra body*, #1604) is a JSON object whose fields `WithExtraBody` adds at the top level of every JSON body sent to the provider: Messages, Chat, Responses and Gemini, relayed as they came or translated, in the gateway's `forwardOnce` and in Test and Detect (`tested`). A field the body has already is kept; a name written `"!name"` replaces it. A `service_tier` of `ultrafast` there is kept by a group member or fast pick sent Fast, which would otherwise have written `priority` first ([gateway routing](gateway-routing.md), KoiLx0 on X). Values are put in as written, objects whole, not merged. `${sessionId}` in any string, at any depth, becomes the request's session: the agent's session header (`sessionOf`), else the id `conversationID` derives from how the conversation opens (`magpie-` and its hash, [Gateway routing](gateway-routing.md#responsibilities-and-sources-of-truth)'s Affinity), so it stays the same through one conversation; Test and Detect send `magpie-test-` and 12 random letters, a new one each time. `${threadId}` is the thread the agent names within that session: Codex's `thread_id` (its turn metadata or `thread-id` header, `threadOf`), which a subagent has of its own while it shares its lead's session; read only when the provider's headers or extraBody name it (`AsksThread`). No other agent names a thread, and there `${threadId}` is the session's id. `${subagentId}` becomes the Claude Code subagent the request is of (`x-claude-code-agent-id`, `subOf`), "" on the conversation's own turns, which never send the header, so `${sessionId}:${subagentId}` keeps one prompt_cache_key per subagent where `${sessionId}` alone carries every subagent's turns on one key (#2937). `model`, `stream` and the conversation (`messages`, `input`, `contents`, `system`, `systemInstruction`, `system_instruction`, `instructions`, `tools`, `ExtraBodyReserved`) are magpie's: Save refuses them with or without `!` (`ExtraBodyOK`), the editor says so as they are typed, and one written into providers.json by hand is dropped on read (`cleanExtraBody`). Not sent with it: `count_tokens`, embeddings, images, video and System One's decision model (other APIs), and a signed-in account's requests, except a ChatGPT (Codex) account's (magpie-releases#18): its requests are built as Codex CLI's (`codexBody`) and take the fields Codex CLI adds by choice, such as `access_programs` (OpenAI's Daybreak), while `store`, `tool_choice` and `include`, which the backend needs as `codexBody` sets them, can't be set (`codexOwned`). Its extraBody is written into providers.json by hand under the account's entry and kept onto the account by `withPicks`, and kept by a later `Save` (#4738: `Save` dropped it before); the editor has no box for it. A client's own top-level `access_programs` on Responses or Chat is carried to a Responses build as it came (`Request.AccessPrograms`), so a request translated (a Codex account is streamed, so a whole Responses request is made again) keeps it as a relayed one does. It reaches only the upstreams Codex itself sends it to (`keepsAccessPrograms`, #3172, see [gateway routing](gateway-routing.md)); it is taken out before the extraBody merge, so an `access_programs` the user puts in a provider's extraBody still goes. One object goes to every API; fields for one API alone are not a thing yet. A `thinking` budget it puts in on an Anthropic endpoint is fitted to a Claude that thinks only adaptively after the merge, as an agent's is (`adaptiveThinking`, `TestExtraBodyBudgetFittedToAdaptiveModel`). | [`extrabody.go`](../../internal/provider/extrabody.go), [`gateway.go`](../../internal/gateway/gateway.go) |
|
||||
| Headers' conversation ids | `${sessionId}`, `${threadId}` and `${subagentId}` in a value of the provider's `Headers` (Axel Burks on Discord: a gateway in front of several Azure accounts routes one conversation to one account by a session header) are the ids extraBody gets, on every request `Sign` signs: the gateway carries the conversation to it in the request's context (`WithConversation`), on every API and `count_tokens` too. A request that is no turn of a conversation (a model list, a balance, an embedding, image or video, System One's decision model, a search) gets an id of its own, `magpie-` and 12 random letters, new each time (`OwnConversation`); Test and Detect's is their `magpie-test-` id, the same in headers and body. A literal placeholder is never sent. In a header the ids go without control characters (`headerSafe`): an agent's session id with CR or LF in it would split the header, or Go would fail the request. A value with neither placeholder goes as written (`SentHeaders`). | [`conversation.go`](../../internal/provider/conversation.go), [`account.go`](../../internal/provider/account.go), [`gateway.go`](../../internal/gateway/gateway.go), [`codex_resume.go`](../../internal/gateway/codex_resume.go) |
|
||||
| A remote magpie's headers | Every request magpie makes to a Remote magpie carries the provider's `Headers` (Yirasumi on Discord: the Usage page's read went without the header a proxy in front of the remote asks for): its API requests and model list as any provider's (`Sign`, `listHeaders`), and its cards, a card's refresh, its quota history and each gateway key's limit (`signRemote`), the last four as no turn of a conversation (`${sessionId}` an id of its own). The key always reaches the remote as `x-api-key` (`remoteKey`), which a gateway reads beside `Authorization`: a user's `Authorization` (a proxy's own scheme) goes in place of magpie's `Bearer` copy without taking the key away, and a user's `x-api-key` is never sent to a remote magpie, so a key's limit is read with that key. A user's `Authorization` that is itself another gateway key of that magpie is read first there, as on any request. | [`remote_quotas.go`](../../internal/provider/remote_quotas.go), [`remote_key_limits.go`](../../internal/provider/remote_key_limits.go), [`remote_magpie.go`](../../internal/provider/remote_magpie.go), [`account.go`](../../internal/provider/account.go) |
|
||||
| A model's own headers | `ModelHeaders` in [settings](../../internal/settings/settings.go) (`"pid/model"`, `SetModelHeaders`, at most 32, names checked as `Headers`' are; the editor's *Model settings*, `+ Add header`; axelburks on Discord: Volcengine Ark routes an endpoint by a header) go on a key's provider's requests for that model alone, after the provider's `Headers`: a name both have is sent once, as the model's, over the provider's and over the key's `Authorization` or `x-api-key` (`headersFor`, in `SentHeaders(ctx)` and `AsksThread(ctx)`). The gateway names the model in the request's context (`WithModel`) on every API, streamed or not, `count_tokens`, images, video, embeddings and System One's decision model; `modelOf` reads it only for the provider it was set for, so a fallback serving the same id is sent its own headers alone. A native route (Gemini's, Copilot's) names the model by the body's vendor id. Headers the agent passes (`PassHeaders`) still stand over both. A signed-in account and a plugin get none (`takesModelHeaders`). `TestModelHeadersReachTheirModelOnEveryRoute`, `TestModelHeadersStayWithTheirProvider`, `TestModelHeadersReachSystemOne`, `model-headers.test.cjs`. |
|
||||
|
||||
@@ -637,6 +637,56 @@ func agentsEffort(own map[string]map[string]any, m catalog.Model) string {
|
||||
return ef
|
||||
}
|
||||
|
||||
// ownSlug is the slug of Codex's own entry for a model a provider the user
|
||||
// added by its address serves: openai/GPT-6-sol-2026-05-01 is gpt-6-sol.
|
||||
func ownSlug(id string) string {
|
||||
slug := strings.ToLower(id)
|
||||
if i := strings.LastIndex(slug, "/"); i >= 0 {
|
||||
slug = slug[i+1:]
|
||||
}
|
||||
return datedSuffix.ReplaceAllString(slug, "")
|
||||
}
|
||||
|
||||
// OwnOffers reports whether Codex's own entry for the model a provider the
|
||||
// user added by its address serves (ownSlug) lists tier, as ownTiers offers
|
||||
// Codex that tier on it: a routing group may send the model at it too
|
||||
// (KoiLx0 on X: Ultrafast on a relay of OpenAI's models). Read through
|
||||
// filememo, as a list asks it of every model.
|
||||
func OwnOffers(id, tier string) bool {
|
||||
tiers, _ := filememo.Read("codex own tiers", catalog.CodexModelsCache(), parseOwnTiers)
|
||||
return slices.Contains(tiers[ownSlug(id)], tier)
|
||||
}
|
||||
|
||||
// parseOwnTiers is each of Codex's own entries' service tier ids, by slug;
|
||||
// one magpie added to the cache is not Codex's own.
|
||||
func parseOwnTiers(b []byte) (map[string][]string, error) {
|
||||
var cache struct {
|
||||
ETag string `json:"etag"`
|
||||
Models []struct {
|
||||
Slug string `json:"slug"`
|
||||
Description string `json:"description"`
|
||||
Tiers []struct {
|
||||
ID string `json:"id"`
|
||||
} `json:"service_tiers"`
|
||||
} `json:"models"`
|
||||
}
|
||||
if err := json.Unmarshal(b, &cache); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := map[string][]string{}
|
||||
for _, m := range cache.Models {
|
||||
if m.Slug == "" || catalog.MagpieAdded(cache.ETag, m.Slug, m.Description) {
|
||||
continue
|
||||
}
|
||||
for _, t := range m.Tiers {
|
||||
if t.ID != "" {
|
||||
out[m.Slug] = append(out[m.Slug], t.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// gptModel is an OpenAI model's id, as a relay may serve it: gpt-6-sol, o4.
|
||||
var gptModel = lazyre.New(`^(gpt-|o\d)`)
|
||||
|
||||
@@ -645,11 +695,7 @@ var gptModel = lazyre.New(`^(gpt-|o\d)`)
|
||||
// relay, a dated snapshot), Ultrafast among them where the entry has it;
|
||||
// Fast on another GPT model; none on any other.
|
||||
func ownTiers(own map[string]map[string]any, m catalog.Model) []tier {
|
||||
slug := strings.ToLower(m.ID)
|
||||
if i := strings.LastIndex(slug, "/"); i >= 0 {
|
||||
slug = slug[i+1:]
|
||||
}
|
||||
slug = datedSuffix.ReplaceAllString(slug, "")
|
||||
slug := ownSlug(m.ID)
|
||||
if raw, ok := own[slug]["service_tiers"].([]any); ok {
|
||||
var ts []tier
|
||||
for _, r := range raw {
|
||||
|
||||
@@ -4105,8 +4105,14 @@ func (s *Server) serve(w http.ResponseWriter, r *http.Request, from provider.Pro
|
||||
attemptBody = withFast(from, attemptBody)
|
||||
}
|
||||
// a pick sent Ultrafast (#1954) asks for it in OpenAI's words; in
|
||||
// Claude's, which have none, the try carries it (withUltra)
|
||||
ultra := fast && c.ultra && !ownFast
|
||||
// Claude's, which have none, the try carries it (withUltra). So
|
||||
// does one sent fast on a provider whose extra body asks for
|
||||
// Ultrafast itself (KoiLx0 on X): fast is never sent slower than
|
||||
// the user asked of the provider, and a tier the extra body forces
|
||||
// ("!service_tier") goes over both as it says (WithExtraBody). On
|
||||
// a provider the user added by its address it is asked for as its
|
||||
// Fast is (OwnFast), and turned away, asked again without it
|
||||
ultra := fast && (c.ultra || extraUltra(c.p))
|
||||
if ultra && (from == provider.Chat || from == provider.Responses) {
|
||||
attemptBody = withFields(attemptBody, map[string]any{"service_tier": "ultrafast"})
|
||||
}
|
||||
@@ -8291,12 +8297,16 @@ func (s *Server) forwardTranslated(ctx context.Context, p provider.Provider, to
|
||||
r.OwnTier, req = own, &r
|
||||
}
|
||||
// a member or pick the user sent fast on a provider they added is
|
||||
// asked for priority on its OpenAI API whatever API the agent
|
||||
// asked for priority (ultrafast, sent Ultrafast) on its OpenAI API whatever API the agent
|
||||
// spoke (#1615); one that turned the field away isn't (own is
|
||||
// false then)
|
||||
if req.OwnTier && req.Tier == "" && isOwnFast(ctx) && (to == provider.Chat || to == provider.Responses) {
|
||||
tier := "priority"
|
||||
if isUltra(ctx) {
|
||||
tier = "ultrafast" // a member sent Ultrafast there
|
||||
}
|
||||
r := *req
|
||||
r.Tier, req = "priority", &r
|
||||
r.Tier, req = tier, &r
|
||||
}
|
||||
// a pick sent Ultrafast from an agent on Claude's API, whose words
|
||||
// for it are speed "fast" (#1954): on the ChatGPT backend alone
|
||||
|
||||
@@ -67,6 +67,13 @@ func isOwnFast(ctx context.Context) bool {
|
||||
return v
|
||||
}
|
||||
|
||||
// extraUltra reports whether p's extra body asks for Ultrafast itself
|
||||
// (provider.ExtraTier), which a member or pick sent fast on it is sent at.
|
||||
func extraUltra(p provider.Provider) bool {
|
||||
tier, _ := p.ExtraTier()
|
||||
return tier == "ultrafast"
|
||||
}
|
||||
|
||||
// ultraKey marks a try of a pick sent Ultrafast (#1954) from an agent on
|
||||
// Claude's API: its speed "fast" goes to the ChatGPT backend as Ultrafast
|
||||
// (forwardTranslated), on an account that offers it.
|
||||
|
||||
@@ -353,3 +353,56 @@ func TestWithFastWire(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The tier a member on a provider the user added goes at (KoiLx0 on X: a
|
||||
// relay that serves Ultrafast), for each of the group's speeds and the
|
||||
// provider's extra body, whichever API the agent spoke. The extra body's
|
||||
// service_tier fills in a member not sent fast; sent fast, the member is
|
||||
// never sent slower than the extra body asks (its Ultrafast stays), and
|
||||
// sent Ultrafast it is asked for it; a forced "!service_tier" goes over
|
||||
// all of them as it says.
|
||||
func TestFastMemberOwnProviderExtraTier(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
extra provider.ExtraBody
|
||||
fast bool
|
||||
ultra bool
|
||||
want any
|
||||
}{
|
||||
{"usual, no extra", nil, false, false, nil},
|
||||
{"usual, extra ultrafast", provider.ExtraBody{"service_tier": json.RawMessage(`"ultrafast"`)}, false, false, "ultrafast"},
|
||||
{"fast, extra ultrafast", provider.ExtraBody{"service_tier": json.RawMessage(`"ultrafast"`)}, true, false, "ultrafast"},
|
||||
{"ultrafast, no extra", nil, true, true, "ultrafast"},
|
||||
{"ultrafast, extra ultrafast", provider.ExtraBody{"service_tier": json.RawMessage(`"ultrafast"`)}, true, true, "ultrafast"},
|
||||
{"fast, extra flex", provider.ExtraBody{"service_tier": json.RawMessage(`"flex"`)}, true, false, "priority"},
|
||||
{"fast, forced flex", provider.ExtraBody{"!service_tier": json.RawMessage(`"flex"`)}, true, false, "flex"},
|
||||
{"ultrafast, forced priority", provider.ExtraBody{"!service_tier": json.RawMessage(`"priority"`)}, true, true, "priority"},
|
||||
}
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
s, up := fasted(t)
|
||||
p, _ := provider.Find("rl")
|
||||
p.ExtraBody = c.extra
|
||||
if err := provider.Save(*p); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
g := provider.Group{ID: "f", Name: "F", Members: []string{"rl/gpt-6.1-sol"}, Routing: provider.Ordered}
|
||||
if c.fast {
|
||||
g.Fast = []string{"rl/gpt-6.1-sol"}
|
||||
}
|
||||
if c.ultra {
|
||||
g.Ultra = []string{"rl/gpt-6.1-sol"}
|
||||
}
|
||||
if err := provider.SaveGroup(g); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, a := range fastAsks {
|
||||
postProto(t, s, a.path, a.body)
|
||||
host, path, _, body := up.last(t)
|
||||
if host != "relay.example" || body["service_tier"] != c.want {
|
||||
t.Errorf("%s: sent to %s%s service_tier %v, want %v: %v", a.name, host, path, body["service_tier"], c.want, body)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7832,7 +7832,7 @@ function routingPage(part) {
|
||||
fb.setAttribute("aria-pressed", String(on));
|
||||
// on a provider the user added (provider.OwnFast, #1615) it is
|
||||
// only asked for: magpie can't know the provider serves it
|
||||
fb.title = ultra ? t("Sent Ultrafast where the account offers it, and fast where it doesn't, whatever the agent asks. Click to send it at the usual speed")
|
||||
fb.title = ultra ? t(m.ownFast ? "Asked for service_tier \"ultrafast\" whatever the agent asks, where your provider serves it. One that turns it away is asked without it. Click to send it at the usual speed" : "Sent Ultrafast where the account offers it, and fast where it doesn't, whatever the agent asks. Click to send it at the usual speed")
|
||||
: m.ownFast
|
||||
? (on ? t("Asked for OpenAI's fast mode (service_tier \"priority\") whatever the agent asks: quicker, at a higher price, where your provider serves it. One that turns it away is asked without it") : t("Sent as the agent asks; click to ask your provider for OpenAI's fast mode (service_tier \"priority\")"))
|
||||
: (on ? t(m.ultraOK ? "Sent in its vendor's fast mode whatever the agent asks: quicker, at a higher price. Click to send it Ultrafast, where the account offers it" : "Sent in its vendor's fast mode whatever the agent asks: quicker, at a higher price") : t("Sent at its vendor's usual speed; click to send it in fast mode"));
|
||||
|
||||
@@ -372,6 +372,7 @@ magpie.strings({
|
||||
"{name} at that reasoning is in the group already": "{name} 以这个推理强度已经在分组里了",
|
||||
"Sent in its vendor's fast mode whatever the agent asks: quicker, at a higher price": "无论 Agent 要求什么,都以服务商的快速模式发送:更快,价格更高",
|
||||
"Sent Ultrafast where the account offers it, and fast where it doesn't, whatever the agent asks. Click to send it at the usual speed": "无论 Agent 要求什么,账号支持极速就走极速,不支持则走快速模式。点一下改回标准速度",
|
||||
"Asked for service_tier \"ultrafast\" whatever the agent asks, where your provider serves it. One that turns it away is asked without it. Click to send it at the usual speed": "无论 Agent 要求什么,都向你的服务商请求极速(service_tier \"ultrafast\"),前提是它支持;不接受的会改为不带该字段重新请求。点一下改回标准速度",
|
||||
"Sent in its vendor's fast mode whatever the agent asks: quicker, at a higher price. Click to send it Ultrafast, where the account offers it": "无论 Agent 要求什么,都以服务商的快速模式发送:更快,价格更高。点一下改为极速(账号支持时)",
|
||||
"Sent at its vendor's usual speed; click to send it in fast mode": "以服务商的常规速度发送;点击改为快速模式",
|
||||
"Asked for OpenAI's fast mode (service_tier \"priority\") whatever the agent asks: quicker, at a higher price, where your provider serves it. One that turns it away is asked without it": "无论代理怎么请求,都向服务商请求 OpenAI 的快速模式(service_tier \"priority\"):服务商支持时更快,价格更高。服务商拒绝这个字段时,会去掉它再请求一次",
|
||||
@@ -1131,6 +1132,7 @@ magpie.strings({
|
||||
"{name} at that reasoning is in the group already": "{name} 以這個推理強度已經在分組裡了",
|
||||
"Sent in its vendor's fast mode whatever the agent asks: quicker, at a higher price": "無論 Agent 要求什麼,都以服務商的快速模式傳送:更快,價格更高",
|
||||
"Sent Ultrafast where the account offers it, and fast where it doesn't, whatever the agent asks. Click to send it at the usual speed": "無論 Agent 要求什麼,帳號支援極速就走極速,不支援則走快速模式。點一下改回標準速度",
|
||||
"Asked for service_tier \"ultrafast\" whatever the agent asks, where your provider serves it. One that turns it away is asked without it. Click to send it at the usual speed": "無論 Agent 要求什麼,都向你的服務商請求極速(service_tier \"ultrafast\"),前提是它支援;不接受的會改為不帶該欄位重新請求。點一下改回標準速度",
|
||||
"Sent in its vendor's fast mode whatever the agent asks: quicker, at a higher price. Click to send it Ultrafast, where the account offers it": "無論 Agent 要求什麼,都以服務商的快速模式傳送:更快,價格更高。點一下改為極速(帳號支援時)",
|
||||
"Sent at its vendor's usual speed; click to send it in fast mode": "以服務商的常規速度傳送;點選改為快速模式",
|
||||
"Asked for OpenAI's fast mode (service_tier \"priority\") whatever the agent asks: quicker, at a higher price, where your provider serves it. One that turns it away is asked without it": "無論代理怎麼請求,都向服務商請求 OpenAI 的快速模式(service_tier \"priority\"):服務商支援時更快,價格更高。服務商拒絕這個欄位時,會拿掉它再請求一次",
|
||||
@@ -1888,6 +1890,7 @@ magpie.strings({
|
||||
"{name} at that reasoning is in the group already": "この推論レベルの {name} はすでにグループにあります",
|
||||
"Sent in its vendor's fast mode whatever the agent asks: quicker, at a higher price": "エージェントの指定にかかわらず、ベンダーの高速モードで送ります。速くなりますが、料金は高くなります",
|
||||
"Sent Ultrafast where the account offers it, and fast where it doesn't, whatever the agent asks. Click to send it at the usual speed": "エージェントの指定にかかわらず、アカウントが対応していれば超高速で、対応していなければ高速モードで送ります。クリックで通常の速度に戻します",
|
||||
"Asked for service_tier \"ultrafast\" whatever the agent asks, where your provider serves it. One that turns it away is asked without it. Click to send it at the usual speed": "エージェントの指定にかかわらず、プロバイダーに超高速(service_tier \"ultrafast\")を求めます(対応している場合)。受け付けない場合はこのフィールドなしで送り直します。クリックで通常の速度に戻します",
|
||||
"Sent in its vendor's fast mode whatever the agent asks: quicker, at a higher price. Click to send it Ultrafast, where the account offers it": "エージェントの指定にかかわらず、ベンダーの高速モードで送ります。速くなりますが、料金は高くなります。クリックで、アカウントが対応していれば超高速にします",
|
||||
"Sent at its vendor's usual speed; click to send it in fast mode": "ベンダーの通常速度で送ります。クリックすると高速モードで送ります",
|
||||
"Asked for OpenAI's fast mode (service_tier \"priority\") whatever the agent asks: quicker, at a higher price, where your provider serves it. One that turns it away is asked without it": "エージェントの指定に関わらず、OpenAI の高速モード(service_tier \"priority\")を求めます。プロバイダーが対応していれば速く、料金は高めです。このフィールドを拒否するプロバイダーには、外して送り直します",
|
||||
@@ -2647,6 +2650,7 @@ magpie.strings({
|
||||
"{name} at that reasoning is in the group already": "{name} mit diesem Reasoning ist bereits in der Gruppe",
|
||||
"Sent in its vendor's fast mode whatever the agent asks: quicker, at a higher price": "Im Schnellmodus des Anbieters gesendet, egal was der Agent verlangt: schneller, zu höherem Preis",
|
||||
"Sent Ultrafast where the account offers it, and fast where it doesn't, whatever the agent asks. Click to send it at the usual speed": "Egal was der Agent verlangt: Ultrafast, wo das Konto es bietet, sonst im Schnellmodus. Klicken für die normale Geschwindigkeit",
|
||||
"Asked for service_tier \"ultrafast\" whatever the agent asks, where your provider serves it. One that turns it away is asked without it. Click to send it at the usual speed": "Egal was der Agent verlangt: Ultrafast (service_tier \"ultrafast\") wird bei deinem Anbieter angefragt, sofern er es bietet. Lehnt er das Feld ab, wird ohne es erneut gefragt. Klicken für die normale Geschwindigkeit",
|
||||
"Sent in its vendor's fast mode whatever the agent asks: quicker, at a higher price. Click to send it Ultrafast, where the account offers it": "Im Schnellmodus des Anbieters gesendet, egal was der Agent verlangt: schneller, zu höherem Preis. Klicken für Ultrafast, wo das Konto es bietet",
|
||||
"Sent at its vendor's usual speed; click to send it in fast mode": "Mit der üblichen Geschwindigkeit des Anbieters gesendet; klicken, um im Schnellmodus zu senden",
|
||||
"Asked for OpenAI's fast mode (service_tier \"priority\") whatever the agent asks: quicker, at a higher price, where your provider serves it. One that turns it away is asked without it": "Fragt unabhängig vom Agenten nach OpenAIs Schnellmodus (service_tier \"priority\"): schneller, zu einem höheren Preis, wo dein Anbieter ihn anbietet. Lehnt er das Feld ab, wird ohne es erneut gefragt",
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
// reasoning is changed stays fast under its new id, while one taken out
|
||||
// leaves it. A GPT model on a provider the user added by its address
|
||||
// (ownFast, #1615) has the toggle too, off until clicked, and its title says
|
||||
// fast is asked of the provider. In English and Chinese, Chromium and WebKit.
|
||||
// fast is asked of the provider; one OpenAI offers Ultrafast on (ultraOK)
|
||||
// goes on to Ultrafast, and its title says that is asked for. In English and Chinese, Chromium and WebKit.
|
||||
const assert = require("node:assert/strict");
|
||||
const fs = require("node:fs/promises");
|
||||
const path = require("node:path");
|
||||
@@ -22,21 +23,25 @@ const models = [
|
||||
{ id: "rl/glm-5", name: "glm-5", providerName: "Relay", icon: "generic" },
|
||||
// a GPT model on a provider the user added by its address (#1615)
|
||||
{ id: "rl/o4-mini", name: "o4-mini", providerName: "Relay", icon: "generic", canFast: true, ownFast: true },
|
||||
// one OpenAI offers Ultrafast on (KoiLx0 on X)
|
||||
{ id: "rl/gpt-6.2-sol", name: "gpt-6.2-sol", providerName: "Relay", icon: "generic", canFast: true, ownFast: true, ultraOK: true },
|
||||
];
|
||||
const members = ["oa/gpt-6.1-sol:high", "an/claude-opus-5-5", "rl/glm-5", "rl/o4-mini"];
|
||||
const members = ["oa/gpt-6.1-sol:high", "an/claude-opus-5-5", "rl/glm-5", "rl/o4-mini", "rl/gpt-6.2-sol"];
|
||||
const groups = () => ({
|
||||
models, pools: [],
|
||||
groups: [{ id: "sol", name: "Sol", members, fast: ["oa/gpt-6.1-sol:high"], routing: "order", ready: true,
|
||||
memberInfo: members.map((id) => ({ id, ready: true, fast: id === "oa/gpt-6.1-sol:high", canFast: id !== "rl/glm-5", ownFast: id === "rl/o4-mini" })) }],
|
||||
memberInfo: members.map((id) => ({ id, ready: true, fast: id === "oa/gpt-6.1-sol:high", canFast: id !== "rl/glm-5", ownFast: id.startsWith("rl/") && id !== "rl/glm-5", ultraOK: id === "rl/gpt-6.2-sol" })) }],
|
||||
});
|
||||
|
||||
const words = {
|
||||
en: { edit: "Edit", save: "Save", fast: "Fast", std: "Standard speed", label: "gpt-6.1-sol · high reasoning · fast", remove: "Remove",
|
||||
ownOff: 'Sent as the agent asks; click to ask your provider for OpenAI\'s fast mode (service_tier "priority")',
|
||||
ownOn: 'Asked for OpenAI\'s fast mode (service_tier "priority") whatever the agent asks: quicker, at a higher price, where your provider serves it. One that turns it away is asked without it' },
|
||||
ownOn: 'Asked for OpenAI\'s fast mode (service_tier "priority") whatever the agent asks: quicker, at a higher price, where your provider serves it. One that turns it away is asked without it',
|
||||
ultra: "Ultrafast", ownUltra: 'Asked for service_tier "ultrafast" whatever the agent asks, where your provider serves it. One that turns it away is asked without it. Click to send it at the usual speed' },
|
||||
zh: { edit: "编辑", save: "保存", fast: "快速", std: "标准速度", label: "gpt-6.1-sol · high 推理强度 · 快速", remove: "移除",
|
||||
ownOff: '按代理的请求发送;点击向你的服务商请求 OpenAI 的快速模式(service_tier "priority")',
|
||||
ownOn: '无论代理怎么请求,都向服务商请求 OpenAI 的快速模式(service_tier "priority"):服务商支持时更快,价格更高。服务商拒绝这个字段时,会去掉它再请求一次' },
|
||||
ownOn: '无论代理怎么请求,都向服务商请求 OpenAI 的快速模式(service_tier "priority"):服务商支持时更快,价格更高。服务商拒绝这个字段时,会去掉它再请求一次',
|
||||
ultra: "极速", ownUltra: '无论 Agent 要求什么,都向你的服务商请求极速(service_tier "ultrafast"),前提是它支持;不接受的会改为不带该字段重新请求。点一下改回标准速度' },
|
||||
};
|
||||
|
||||
function serve(lang, posts) {
|
||||
@@ -131,6 +136,15 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
await fast("o4-mini").click();
|
||||
assert.equal(await fast("o4-mini").textContent(), w.fast);
|
||||
assert.equal(await fast("o4-mini").getAttribute("title"), w.ownOn);
|
||||
await fast("o4-mini").click();
|
||||
assert.equal(await fast("o4-mini").textContent(), w.std, "no Ultrafast where OpenAI offers none");
|
||||
await fast("o4-mini").click();
|
||||
// usual -> fast -> Ultrafast on the one OpenAI offers it on
|
||||
await fast("gpt-6.2-sol").click();
|
||||
assert.equal(await fast("gpt-6.2-sol").textContent(), w.fast);
|
||||
await fast("gpt-6.2-sol").click();
|
||||
assert.equal(await fast("gpt-6.2-sol").textContent(), w.ultra);
|
||||
assert.equal(await fast("gpt-6.2-sol").getAttribute("title"), w.ownUltra);
|
||||
|
||||
const b = ed.locator("button.primary", { hasText: w.save });
|
||||
await page.mouse.move(550, 600);
|
||||
@@ -142,8 +156,9 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
await page.mouse.click(bb.x + bb.width / 2, bb.y + bb.height / 2);
|
||||
await page.waitForFunction(() => !document.querySelector(".rt-gedit"));
|
||||
const sent = posts.find((p) => p.path === "/api/groups/save");
|
||||
assert.deepEqual(sent.body.members, ["oa/gpt-6.1-sol:xhigh", "rl/glm-5", "rl/o4-mini"]);
|
||||
assert.deepEqual(sent.body.fast, ["oa/gpt-6.1-sol:xhigh", "rl/o4-mini"]);
|
||||
assert.deepEqual(sent.body.members, ["oa/gpt-6.1-sol:xhigh", "rl/glm-5", "rl/o4-mini", "rl/gpt-6.2-sol"]);
|
||||
assert.deepEqual(sent.body.fast, ["oa/gpt-6.1-sol:xhigh", "rl/o4-mini", "rl/gpt-6.2-sol"]);
|
||||
assert.deepEqual(sent.body.ultra, ["rl/gpt-6.2-sol"]);
|
||||
|
||||
const missing = await page.evaluate(() => [
|
||||
"fast", "Fast", "Standard speed", "Sent in its vendor's fast mode, as the group says",
|
||||
@@ -151,6 +166,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
"Sent at its vendor's usual speed; click to send it in fast mode",
|
||||
'Asked for OpenAI\'s fast mode (service_tier "priority") whatever the agent asks: quicker, at a higher price, where your provider serves it. One that turns it away is asked without it',
|
||||
'Sent as the agent asks; click to ask your provider for OpenAI\'s fast mode (service_tier "priority")',
|
||||
'Asked for service_tier "ultrafast" whatever the agent asks, where your provider serves it. One that turns it away is asked without it. Click to send it at the usual speed',
|
||||
"{model} is asked for OpenAI's fast mode for {agent}, where your provider serves it. Click to send it as {agent} asks",
|
||||
'Ask your provider for OpenAI\'s fast mode (service_tier "priority") on {model} for {agent}: quicker, at a higher price, where it serves it',
|
||||
].filter((k) => !I18N.zh[k] || !I18N["zh-TW"][k] || !I18N.ja[k] || !I18N.de[k]));
|
||||
|
||||
@@ -189,6 +189,28 @@ func (p Provider) WithExtraBody(body []byte, c Conversation) []byte {
|
||||
return bytes.TrimSuffix(out.Bytes(), []byte("\n"))
|
||||
}
|
||||
|
||||
// ExtraTier is the service_tier the provider's extra body asks for, and
|
||||
// whether it is forced ("!service_tier"); "" when it names none, or not as
|
||||
// a string. A group's member, or an agent's pick, sent fast on the
|
||||
// provider is sent at it when it is Ultrafast: fast is never sent slower
|
||||
// than the user asked of the provider (the gateway's member tries).
|
||||
func (p Provider) ExtraTier() (tier string, forced bool) {
|
||||
if _, takes := p.extraBodyTakes(); !takes {
|
||||
return "", false
|
||||
}
|
||||
for k, raw := range p.ExtraBody {
|
||||
n, f := extraName(k)
|
||||
if n != "service_tier" {
|
||||
continue
|
||||
}
|
||||
var v string
|
||||
if json.Unmarshal(raw, &v) == nil {
|
||||
return strings.TrimSpace(v), f
|
||||
}
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
||||
// withSession is v with ${sessionId}, ${threadId} and ${subagentId} in its
|
||||
// strings, at any depth, as c's ids.
|
||||
func withSession(v any, c Conversation) any {
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/catalog"
|
||||
"github.com/yetone/magpie/internal/codexcat"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
)
|
||||
|
||||
@@ -47,8 +48,13 @@ func UltraPicks(agent string) []string {
|
||||
// Ultrafast: a ChatGPT model that one of Codex's accounts lists the tier
|
||||
// on (Account.Tiers), or a plugin's model, with fast mode, that the plugin
|
||||
// says its vendor serves at ultrafast (serviceTiers, #2514), or another
|
||||
// magpie's model its list offers ultrafast on (#1234). A list that
|
||||
// doesn't say tiers offers none.
|
||||
// magpie's model its list offers ultrafast on (#1234), or a GPT model on a
|
||||
// provider the user added by its address (OwnFast) that OpenAI offers
|
||||
// Ultrafast on: one of Codex's accounts lists the tier on the model, or
|
||||
// Codex's own entry for it does, which Codex is offered on that provider
|
||||
// as well (codexcat.OwnOffers; KoiLx0 on X, a relay that serves it). Like
|
||||
// its Fast, that is asked for, and a provider that turns the field away is
|
||||
// asked again without it. A list that doesn't say tiers offers none.
|
||||
func CanUltra(p Provider, model string) bool {
|
||||
return UltraOn(p, model, UltraModels())
|
||||
}
|
||||
@@ -67,6 +73,10 @@ func UltraOn(p Provider, model string, ultra map[string]bool) bool {
|
||||
// another magpie's model it offers Ultrafast on, beside Fast
|
||||
return CanFast(p, model) && slices.Contains(RemoteTiers(p, model), "ultrafast")
|
||||
}
|
||||
if OwnFast(p, model) {
|
||||
slug := modelSlug(model)
|
||||
return ultra[slug] || codexcat.OwnOffers(slug, "ultrafast")
|
||||
}
|
||||
return p.Account != nil && p.Account.Agent == "codex" && CanFast(p, model) && ultra[model]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -139,3 +141,46 @@ func TestSaveGroupFast(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A GPT model on a provider the user added by its address can be sent
|
||||
// Ultrafast where OpenAI offers it on the model (KoiLx0 on X): Codex's own
|
||||
// entry for it lists the tier, as Codex itself is offered it there. Not on
|
||||
// a model Codex's entry gives Fast alone, nor one it has no entry for, nor
|
||||
// on another vendor's model.
|
||||
func TestCanUltraOwnProvider(t *testing.T) {
|
||||
fastHome(t)
|
||||
codexHome := t.TempDir()
|
||||
t.Setenv("CODEX_HOME", codexHome)
|
||||
rl, _ := Find("rl")
|
||||
oa, _ := Find("oa")
|
||||
if UltraOn(*rl, "gpt-6.1-sol", nil) {
|
||||
t.Fatal("Ultrafast with no list saying so")
|
||||
}
|
||||
cache := `{"etag":"e1","models":[
|
||||
{"slug":"gpt-6.1-sol","description":"x","service_tiers":[{"id":"priority","name":"Fast"},{"id":"ultrafast","name":"Ultra Fast"}]},
|
||||
{"slug":"gpt-6.1-mini","description":"x","service_tiers":[{"id":"priority","name":"Fast"}]}]}`
|
||||
if err := os.WriteFile(filepath.Join(codexHome, "models_cache.json"), []byte(cache), 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, c := range []struct {
|
||||
p Provider
|
||||
model string
|
||||
want bool
|
||||
}{
|
||||
{*rl, "gpt-6.1-sol", true},
|
||||
{*rl, "openai/GPT-6.1-sol-2026-05-01", true},
|
||||
{*rl, "gpt-6.1-mini", false},
|
||||
{*rl, "gpt-7", false},
|
||||
{*rl, "claude-opus-5-5", false},
|
||||
// OpenAI's own API offers no Ultrafast
|
||||
{*oa, "gpt-6.1-sol", false},
|
||||
} {
|
||||
if got := UltraOn(c.p, c.model, nil); got != c.want {
|
||||
t.Errorf("%s/%s: Ultrafast %v, want %v", c.p.ID, c.model, got, c.want)
|
||||
}
|
||||
}
|
||||
// one of Codex's accounts listing it says so too
|
||||
if !UltraOn(*rl, "gpt-7", map[string]bool{"gpt-7": true}) {
|
||||
t.Error("an account's Ultrafast not taken")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user