diff --git a/docs/reference.md b/docs/reference.md index 1d55be2b1..5412d6896 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -1779,7 +1779,9 @@ each of these groups ordered by the share used. for it, else its list price, at the provider's price rate and rate windows; a model its vendor serves free costs nothing. DeepSeek's own API, and Command Code's and OpenCode Go's DeepSeek models, bill double - in their peak hours (weekdays 01:00–04:00 and 06:00–10:00 UTC), so a + in their peak hours (weekdays 01:00–04:00 and 06:00–10:00 UTC), and + Ollama Cloud's DeepSeek V4.1 Flash and V4 Pro in its own (weekdays + 12:00–18:00 UTC; half price the rest of the time), so a DeepSeek model on two providers goes to whichever is cheaper at that hour. A tie on that goes to the cheaper cache read; members that still cost the same keep their order, and one with no known price goes after diff --git a/docs/subsystems/gateway-routing.md b/docs/subsystems/gateway-routing.md index 2c777ab4e..6714b167b 100644 --- a/docs/subsystems/gateway-routing.md +++ b/docs/subsystems/gateway-routing.md @@ -34,7 +34,7 @@ backfilled; see [Gateway Session Aggregation](gateway-sessions.md). | A found group's two ids | A group magpie found is listed (`/v1/models`, the catalog, the lists written into agents, the pickers, the CLI and TUI) as `auto/`: the model's id as a vendor spells it, dots kept and with no vendor prefix (`auto/claude-opus-5.5`; `provider.Group.Ref`, `spelledIn`), so a client that looks the part after the slash up on models.dev finds it (ZeroClover on X). The spelling is the one models.dev gives the model most (`catalog.Spelling`, its `normal` index: `glm-5.3-flash` whether the members serve `glm-5-3-flash`, Ark's dated id or `glm-5.3-flash`), so it no longer follows the order the providers were added in; for a model models.dev doesn't know, the first member's spelling it lists, else the first member's. The group's name comes from the same choice (`autoGroups`): the name models.dev gives that spelling (`catalog.NameOf`), else a vendor's own name for it, else the spelling itself; they were picked apart, a name of `glm-5-3-flash` beside `auto/glm-5.3-flash` (XYenon on Discord, `TestFoundGroupIDAndNameAreOneSpelling`). A found group the user changed keeps the name they saved. Every spelling it was listed by before is still the group (`CanonicalRef`), and `PublicRef` takes one to the spelling now. Its old id `group/auto-` is served forever. Inside magpie the group keeps that one id: `validateModel` takes `auto/` (with `:level` or `[1m]`) back to it with `provider.CanonicalRef` before key limits, routing, affinity and the usage log see the request, and the request body is rewritten to it, so both ids count as one group. A gateway key naming either id, `group/*` or `auto/*` passes for both (`allows` in `key_models.go`). `SaveGroup` stores a member, rule or classifier picked as `auto/` by the old id. An agent field magpie set to `group/auto-`, or to an `auto/` spelt otherwise than the group is listed now, moves to `auto/` on the next `SyncCatalog` (`agent.renameFoundGroups`, `TestFoundGroupMovedOffAnOldSpelling`), but only while its value is still what applied.json says magpie wrote; a value the user set or changed stays, and is still served. A pick of the group by its old id written now (`Agent.Apply`) is written as `auto/`. An agent's hidden, picked and ordered models saved by the old id hold for the new one (`PublicRef` in `visible.go`), and a bare model id still reaches its found group (`bareTarget`). Claude Code is given a dotted Claude version dashed, so it may send `auto/claude-sonnet-4-5`: that is the same group, and `Reseat` still moves an agent off it once the group is gone (`samePick`). `auto` is no provider id: `Save` and `Rename` refuse it for a new provider, and a plugin's `auto` is `auto-plugin` (`PluginID`). A provider of the user's saved as `auto` before keeps its models: while it exists, `auto/` is its model and found groups list as `group/auto-` (`autoRefsOn`). Hand-made groups stay `group/`. | [`internal/provider/autoref.go`](../../internal/provider/autoref.go), [`key_models.go`](../../internal/gateway/key_models.go), [`internal/agent/autoref.go`](../../internal/agent/autoref.go) | | A model's own id at a provider | A model the user lists by an id of theirs at a provider (a signed-in account's and a plugin's too; settings' `ModelIDs`, `magpie model id `, the editor's "Listed as"; [Providers and accounts](providers-accounts.md#runtime-path)) is that id everywhere the gateway names it: `/v1/models` and the lists written into agents (`Available`), `Resolve`, the routing groups and the group magpie finds for it (`auto/`, with every other provider serving that id), a gateway key's models, `X-Magpie-Model` and the usage log's `model`. Only the upstream request differs: every place that sends a wire name reads `settings.Wires()`, which is `ModelWires` with each `ModelIDs` entry turned round (`"/"` → the vendor's own id, wrapped by a `/*` wire), so the body, a Vertex path and the usage log's endpoint carry the vendor's id; an explicit `ModelWires` entry for that id wins. The vendor's reply names its own id, which the usage log, recent calls and the Routing page keep as `served`; the agent gets the id it asked for back in the reply, in every protocol, streamed or whole (`memberWriter` in [`member.go`](../../internal/gateway/member.go), `replyNamingOf`: the reply's `model`, Responses' `response.model`, Anthropic's `message.model`, Gemini's `modelVersion`; issennknight on Discord, whose agent warned that `deepseek-v4.1-flash` came back as `deepseek-v4.1-flash-1017`). The same holds for a group or a `provider/model` id the vendor knows by another name. A reply whose vendor sent the wire name as asked keeps the vendor's name (a dated `-20261017` included); `memberModel` names the group's member instead, and `X-Magpie-Response-Model: vendor` keeps the vendor's name always (`TestReplyNamesAskedModel`, `TestGeminiReplyNamesAskedModel`, `TestReplyNamesMember`). A request still naming `provider/` (an agent's file magpie didn't rewrite) resolves and goes out as it is. A key held to either id passes for both (`modelAllowed` checks the ref, then `OwnModelID`, then `ListedModelID`); a group member passes the same way. An id is given to a model of the provider's chat list or its picks; the image, video and embeddings routes send no wire name, so they are not served under one (`TestLocalModelIDOnEveryRoute`). At an account or a plugin the account's own say of the model is read by the vendor's id: a plugin's API and fetch, Claude Code's `--model`, Antigravity's variant, and which accounts list it and at what levels (`TestLocalModelIDAtAPlugin`, `TestLocalModelIDAtAClaudeAccount`, `TestLocalModelIDAtAnAntigravityAccount`). | [`internal/provider/localid.go`](../../internal/provider/localid.go), [`internal/settings/settings.go`](../../internal/settings/settings.go), [`key_models.go`](../../internal/gateway/key_models.go) | | Candidates | `plan` lists one provider's candidates: one per key or account on, then each `Fallback` model, with resting ones last (`restLast`). A fallback the user unchecked in its own provider's model list is skipped, as a group's member is (`provider.ResolveRoute`, #3911; `fallback_unpicked_test.go`), and so is it where fallbacks are read for careful accounts, native compaction, redaction and Codex's own turns. A fallback can be a routing group (`group/`, 01huadalang on Discord): `planPaused` hands its members to `planLevel` as a request to the group would (`planFallbackGroup`), in the group's own routing and sink, its pause rules applied in `serve`, and its trace rows marked `Fallback` with the group in `Via`. Its turn rules (`ruleFor`, which may ask a classifier) are not applied: the plan is made before the primary is tried, and a classifier call on every request the primary answers costs too much. Each provider/model is tried once a round: a member that is the primary, an earlier fallback or another fallback group's is left out where it came second, so a group holding this provider is no loop (groups have no fallbacks of their own, and a member's are not followed). A group that is gone is passed over. Every place that reads fallbacks (careful accounts, native compaction, redaction, Codex's own turns, Claude's review) reads a group's members through `provider.FallbackModels`. `fallback_group_test.go`. `planGroup` and `planLevel` weigh a group's members together. A nested group plans by its own routing (#576); one left on the default (Smart) in a group that pools (Smart, In turn, Least used, Weekly pace, Free first, Speed first, a plugin's) takes the outer group's, as a provider left on the default does (`provider.Group.Within`, set on `Member.Via`, so the trace's `Subs` and the Routing page read the routing that applies, #3847). In a group In order, By weight or Manual it stays Smart. `TestFreeFirstReachesAGroupInItLeftOnTheDefault`. So does a member whose provider routes other than Smart (`ownRouting`): weighed as one by its first not resting (`firstAwake`), tried whole in its own order; `leastHeld` leaves such a group's order alone too. A provider on Smart, or routed as the group is, is pooled with the group's other keys and accounts. `group_own_routing_test.go`. A member's own fallbacks are not the group's. | [`fallback.go`](../../internal/gateway/fallback.go) | -| Order of keys and accounts | `Routing`: smart (""), `order`, `rotate`, `usage` (least used, with an `usageHalfLife` of 1h), `pace`, `weight`, `free` (free first), `fast` (speed first), `drain` (until used up) or, a group's only, `cheap` (cheapest first). `weighRouted` reads each candidate into a `routes.Seat` and asks the strategy serving its routing (`routes.Find`, the router strategy point of [the plugin runtime](plugin-runtime.md#gateway-extension-points-p3-router-strategy)) for the order: Smart is `routes.Smart`, the core's; the others are `routes.Builtin`, registered by the built-in plugin `rotation`. With it off a routing no strategy serves is tried in its listed order, and `routingOf` treats it as `order` wherever the core asks about a routing (a turn's mark, `goesRound`, `sinks`, a rotate group's sessions, a group's heads). Smart, `usage` and `pace` weigh a subscription by its allowance (`allowances`), and a key by its own usage windows when magpie reads them (`keyAllowance`: a sub2api key given a 5-hour, day or 7-day limit, or a key bought as a plan, such as Kimi Code's or a GLM Coding Plan's); any other key has none. Among accounts a plugin reads as prepaid wallets (a window's `balance`, #3950), Smart, `usage` and `pace` put the one with more left first where they would otherwise tie, only within one provider and unit (`routes.Seat.Left`/`LeftIn`, see [provider plugins](provider-plugins.md#a-wallets-balance)): each kind is ordered in the places its own seats take, so a group weighing several providers' accounts as one pool orders each provider's wallets too (#4095, `TestGroupWalletsGoByWhatTheyHaveLeft`). `free` weighs by what a model costs there and nothing else: only a strategy with `routes.Strategy.ByFree` set (`routes.FreeFirst` is the one) has `weighRouted` fill `routes.Seat.Free`, from `provider.FreeModel` — the user's word that the whole provider costs them nothing (`Provider.CountFree`: the editor's Free for me, `magpie provider set free=yes`; jiabubu on Discord, ModelScope's free daily quota), else the vendor's own `catalog.Model.Free` word, else a list price of $0 on every count — so a pool routed any other way never reads a model list for it, and one routed `free` spends the members whose model costs nothing before those that spend the allowance or credits, each tier in its listed order (nothing free is left behind a paid one, and a pool with no free model behaves as `order`). A group routed `free` weighs its members whole, each over its own accounts or keys as its provider routes them. `fast` weighs by speed lately and nothing else: only a strategy with `routes.Strategy.BySpeed` set (`routes.Fastest`) has `weighRouted` fill `routes.Seat.TTFT` and `TPS`, from `speedOf` ([`speed.go`](../../internal/gateway/speed.go)): per `restID` (account or key, and model), a decayed average (half-life 20m) of a streamed answer's ms to its first content and of its output tokens a second as `usage.DecodeOf` counts them, written once as an answer ends (`noteTrySpeed`, beside `servedCandidate`) and read with one map lookup per candidate, never from the usage history; past an hour since its last answer a seat counts as not measured, the records are capped at 4096, and a restart forgets them. `routes.Fastest` ranks the awake by their first token plus 200 tokens at their pace (a seat with no pace at the measured seats' middle pace), keeps seats within a tenth of their band's fastest in listed order, and of a pool's requests with seats both measured and not, gives every fifth to one not measured (round the unmeasured, `probes`, so one is never starved); resting seats go after the awake, used-up ones (`UsedShare`) after those, and rests and failover are as for any routing. The trace's rows carry `lateTtft`/`lateTps` for the Routing page's story ("answered fastest lately — first token in 0.8s"). A non-streamed reply tells nothing (no first token), so a pool that never streams stays in listed order bar the probes. `cheap` (a group's only: `provider.normalize` drops it from a provider, whose keys and accounts all bill one price, and the CLI refuses it there) weighs by price now and nothing else: only a strategy with `routes.Strategy.ByPrice` set (`routes.Cheapest`) has `weighRouted` fill `routes.Seat.Priced`, `Cost` and `CacheCost`, from `provider.Provider.PriceAt` at `priceClock()` — the price Usage would count a call made then (the user's `ModelPrices`, else list or maker price, at the price rate and `RateAt`'s window, a `FreeModel` at 0), doubled in its vendor's peak hours by `catalog.Price.In` (`PeakOf`: DeepSeek's API, Command Code's and OpenCode Go's DeepSeek models). `routes.Cheapest` sorts stably by a million in plus a million out, a tie (within a millionth) by cache read, and unpriced seats after every priced one in listed order; rests and failover are as for any routing. The trace's rows carry `price` (`input`, `output`, `cacheRead`, `peak`) for the Routing page's story ("costs least on Ollama now — $0.150 in, $0.600 out a million tokens"). `TestCheapestFirstGroupFollowsPeakHours` holds the clock at a peak and an off-peak hour. A group routed `weight` (#1910) takes its members, not their keys, by smooth weighted round robin: `planLevel` makes each model member (its keys ordered by its own provider's routing) and each nested group one unit, and `weightedUnits` puts the round's pick (`routes.Round` over `group/`, keyed by the member's spelling, `Group.Weights`, 1 if unset) first and the rest in member order for failover; a unit whose head rests leaves the round, while one whose accounts are only near their limit (Smart's 90% band, not resting) keeps its share, the band ordering only its own accounts (`TestWeightedGroupGivesALowGroupItsShare`; Creat.wu on Discord read the Routing page's "kept for when the others can't" as the member passed over, so the page now tells a member behind another by a group's weights or order as such, `memberSplit` in the routing plugin's `client.js`), and a kept conversation moves the round's charge to the member that kept it (`wrrSeat`, `routes.MoveRound`). `weight` on a provider spreads its keys by each key's `Weight` and a subscription's accounts by each account's (`AccountWeights`, rubbzha on X): `keyWeight` gives a seat its `Weight`, 1 when none is set, and `routes.Weighted` takes them by smooth weighted round robin, a resting one leaving the round and a kept conversation staying as Stays says (`TestWeightedKeys`, `TestAccountWeightSharesRequests`). A lone key or account is weighed against nobody, but what it has left is still read into the trace (`weighRouted`), so the Routing page shows it as it does for several (#1016); all but used up, it keeps its conversation rather than being said to move (`affine`). `drain` (dzxx0496 on Discord: free accounts one after another, the first not taking the requests back once it renews) stays on one seat per pool (`routes.Drain`, which remembers the seat's `Key` per pool) until it is used up — a known window at 100% (`provider.SpentShareOf`, as In order) or resting out of quota or credit (`routes.Seat.Spent`, filled by `spentRest` from `restingOf`'s `failQuota`/`failCredit`) — then goes on to the next not used up in listed order and stays there, wrapping round; the others follow it in listed order for failover. A rate limit or a failure only rests the seat, tried last meanwhile, and the pool comes back to it; with every seat used up it stays put, and a seat that leaves the pool leaves it on the first not used up. A group routed `drain` pools its members' accounts and keys under `group/`, as Smart does. A restart forgets where each pool was, and it starts again at the first not used up (`TestDrainKeepsTheOneThatTookOver`). A failure rests a candidate (`failure`, `failureOf`). | [`routing.go`](../../internal/gateway/routing.go), [`weighted.go`](../../internal/gateway/weighted.go), [`internal/routes/`](../../internal/routes), [`internal/provider/routing.go`](../../internal/provider/routing.go) | +| Order of keys and accounts | `Routing`: smart (""), `order`, `rotate`, `usage` (least used, with an `usageHalfLife` of 1h), `pace`, `weight`, `free` (free first), `fast` (speed first), `drain` (until used up) or, a group's only, `cheap` (cheapest first). `weighRouted` reads each candidate into a `routes.Seat` and asks the strategy serving its routing (`routes.Find`, the router strategy point of [the plugin runtime](plugin-runtime.md#gateway-extension-points-p3-router-strategy)) for the order: Smart is `routes.Smart`, the core's; the others are `routes.Builtin`, registered by the built-in plugin `rotation`. With it off a routing no strategy serves is tried in its listed order, and `routingOf` treats it as `order` wherever the core asks about a routing (a turn's mark, `goesRound`, `sinks`, a rotate group's sessions, a group's heads). Smart, `usage` and `pace` weigh a subscription by its allowance (`allowances`), and a key by its own usage windows when magpie reads them (`keyAllowance`: a sub2api key given a 5-hour, day or 7-day limit, or a key bought as a plan, such as Kimi Code's or a GLM Coding Plan's); any other key has none. Among accounts a plugin reads as prepaid wallets (a window's `balance`, #3950), Smart, `usage` and `pace` put the one with more left first where they would otherwise tie, only within one provider and unit (`routes.Seat.Left`/`LeftIn`, see [provider plugins](provider-plugins.md#a-wallets-balance)): each kind is ordered in the places its own seats take, so a group weighing several providers' accounts as one pool orders each provider's wallets too (#4095, `TestGroupWalletsGoByWhatTheyHaveLeft`). `free` weighs by what a model costs there and nothing else: only a strategy with `routes.Strategy.ByFree` set (`routes.FreeFirst` is the one) has `weighRouted` fill `routes.Seat.Free`, from `provider.FreeModel` — the user's word that the whole provider costs them nothing (`Provider.CountFree`: the editor's Free for me, `magpie provider set free=yes`; jiabubu on Discord, ModelScope's free daily quota), else the vendor's own `catalog.Model.Free` word, else a list price of $0 on every count — so a pool routed any other way never reads a model list for it, and one routed `free` spends the members whose model costs nothing before those that spend the allowance or credits, each tier in its listed order (nothing free is left behind a paid one, and a pool with no free model behaves as `order`). A group routed `free` weighs its members whole, each over its own accounts or keys as its provider routes them. `fast` weighs by speed lately and nothing else: only a strategy with `routes.Strategy.BySpeed` set (`routes.Fastest`) has `weighRouted` fill `routes.Seat.TTFT` and `TPS`, from `speedOf` ([`speed.go`](../../internal/gateway/speed.go)): per `restID` (account or key, and model), a decayed average (half-life 20m) of a streamed answer's ms to its first content and of its output tokens a second as `usage.DecodeOf` counts them, written once as an answer ends (`noteTrySpeed`, beside `servedCandidate`) and read with one map lookup per candidate, never from the usage history; past an hour since its last answer a seat counts as not measured, the records are capped at 4096, and a restart forgets them. `routes.Fastest` ranks the awake by their first token plus 200 tokens at their pace (a seat with no pace at the measured seats' middle pace), keeps seats within a tenth of their band's fastest in listed order, and of a pool's requests with seats both measured and not, gives every fifth to one not measured (round the unmeasured, `probes`, so one is never starved); resting seats go after the awake, used-up ones (`UsedShare`) after those, and rests and failover are as for any routing. The trace's rows carry `lateTtft`/`lateTps` for the Routing page's story ("answered fastest lately — first token in 0.8s"). A non-streamed reply tells nothing (no first token), so a pool that never streams stays in listed order bar the probes. `cheap` (a group's only: `provider.normalize` drops it from a provider, whose keys and accounts all bill one price, and the CLI refuses it there) weighs by price now and nothing else: only a strategy with `routes.Strategy.ByPrice` set (`routes.Cheapest`) has `weighRouted` fill `routes.Seat.Priced`, `Cost` and `CacheCost`, from `provider.Provider.PriceAt` at `priceClock()` — the price Usage would count a call made then (the user's `ModelPrices`, else list or maker price, at the price rate and `RateAt`'s window, a `FreeModel` at 0), doubled in its vendor's peak hours by `catalog.Price.In` (`PeakOf`: DeepSeek's API, Command Code's and OpenCode Go's DeepSeek models, each at DeepSeek's hours; Ollama Cloud's deepseek-v4.1-flash and deepseek-v4-pro, dated tags too, at its own 12:00–18:00 UTC weekdays, `catalog.PeakOllama`). `routes.Cheapest` sorts stably by a million in plus a million out, a tie (within a millionth) by cache read, and unpriced seats after every priced one in listed order; rests and failover are as for any routing. The trace's rows carry `price` (`input`, `output`, `cacheRead`, `peak`) for the Routing page's story ("costs least on Ollama now — $0.150 in, $0.600 out a million tokens"). `TestCheapestFirstGroupFollowsPeakHours` holds the clock at a peak and an off-peak hour, and `TestCheapestFirstGroupFollowsOllamaOffPeak` at each edge of Ollama Cloud's hours, a Saturday, and in far zones. A group routed `weight` (#1910) takes its members, not their keys, by smooth weighted round robin: `planLevel` makes each model member (its keys ordered by its own provider's routing) and each nested group one unit, and `weightedUnits` puts the round's pick (`routes.Round` over `group/`, keyed by the member's spelling, `Group.Weights`, 1 if unset) first and the rest in member order for failover; a unit whose head rests leaves the round, while one whose accounts are only near their limit (Smart's 90% band, not resting) keeps its share, the band ordering only its own accounts (`TestWeightedGroupGivesALowGroupItsShare`; Creat.wu on Discord read the Routing page's "kept for when the others can't" as the member passed over, so the page now tells a member behind another by a group's weights or order as such, `memberSplit` in the routing plugin's `client.js`), and a kept conversation moves the round's charge to the member that kept it (`wrrSeat`, `routes.MoveRound`). `weight` on a provider spreads its keys by each key's `Weight` and a subscription's accounts by each account's (`AccountWeights`, rubbzha on X): `keyWeight` gives a seat its `Weight`, 1 when none is set, and `routes.Weighted` takes them by smooth weighted round robin, a resting one leaving the round and a kept conversation staying as Stays says (`TestWeightedKeys`, `TestAccountWeightSharesRequests`). A lone key or account is weighed against nobody, but what it has left is still read into the trace (`weighRouted`), so the Routing page shows it as it does for several (#1016); all but used up, it keeps its conversation rather than being said to move (`affine`). `drain` (dzxx0496 on Discord: free accounts one after another, the first not taking the requests back once it renews) stays on one seat per pool (`routes.Drain`, which remembers the seat's `Key` per pool) until it is used up — a known window at 100% (`provider.SpentShareOf`, as In order) or resting out of quota or credit (`routes.Seat.Spent`, filled by `spentRest` from `restingOf`'s `failQuota`/`failCredit`) — then goes on to the next not used up in listed order and stays there, wrapping round; the others follow it in listed order for failover. A rate limit or a failure only rests the seat, tried last meanwhile, and the pool comes back to it; with every seat used up it stays put, and a seat that leaves the pool leaves it on the first not used up. A group routed `drain` pools its members' accounts and keys under `group/`, as Smart does. A restart forgets where each pool was, and it starts again at the first not used up (`TestDrainKeepsTheOneThatTookOver`). A failure rests a candidate (`failure`, `failureOf`). | [`routing.go`](../../internal/gateway/routing.go), [`weighted.go`](../../internal/gateway/weighted.go), [`internal/routes/`](../../internal/routes), [`internal/provider/routing.go`](../../internal/provider/routing.go) | | Limits | Each key or account (a candidate's `who()`) has at most `MaxConcurrency` requests out at once (its own `AccountConcurrency` over it); one more waits in its lane's queue, bounded by `QueueLimit` and `QueueWait` and turned away with a 429 past either (`lanes.take`). One with no limit still counts its requests out in a lane of `Limit` 0, which never waits, so `Lanes` (`/v1/magpie/concurrency`, the GUI's `/api/lanes`) says how many run there too and the Providers page's pill shows it (chentuoyan on Discord, `TestLanesCountWithNoLimit`); a limit set while they are out counts them. `MaxRPM` (coeo91 on Discord: OpenRouter's free models take 20 a minute) bounds how many requests it sends the vendor in any rolling 60 seconds (`rpms`), counting each for a second more (`rpmSlack`), since the vendor counts a request when it arrives and the first on a new connection arrives later by its dial: one more waits for room in the minute, in the order they came, after it has its slot and right before it is sent. A wait that would be longer than 2 minutes (or the provider's `QueueWait`, when shorter: `rpmWait`) is turned away at once with a 429 whose `Retry-After` is when the minute has room; nothing rests for it. An agent gone while it waits gives its place back. Every request that reaches the vendor counts: each try of the candidate loop (a retry, the next key, a fallback) waits in `serve`, and the requests a try makes on the way and the gateway's own asks (count_tokens, System One's decisions, embeddings, drawing, Kimi's search) are counted by `rpmTransport` on `s.client` (`metered`, `paidFor`). count_tokens never waits: a candidate with no room is skipped, and the local estimate answers. A full lane or a minute with no room gives way to a ready key or account of the provider or the group (`laneMate`, `ready`); a fallback is never asked for want of either. A plugin's account sends through its own transport, so only its tries are counted, not a plugin's own extra requests. Set in the provider editor (Concurrency, Requests per minute, Queue size, Queue wait) or with `magpie provider account-concurrency`, `queue` and `rpm`; a subscription's are kept with its picks, and every account of it keeps them, those on beside the first as well (`withPicks`, called by `All` and `AlsoOn`; #1899: a second WorkBuddy AI account had none, and queued 62s with the wait set to 1s). | [`concurrency.go`](../../internal/gateway/concurrency.go), [`rpm.go`](../../internal/gateway/rpm.go), [`internal/provider/concurrency.go`](../../internal/provider/concurrency.go) | | Accounts at once | A provider's `MaxAccounts` (01huadalang on Discord: three ZCode accounts used at once got the exit address refused with a 405, two didn't) is how many of its keys or accounts take requests at the same time: `provider.AtOnce()` is the user's own value, else what its plugin declares (`maxAccounts` on the auth hook or in package.json's `magpie`, read by host.js `atOnceOf`; zcode says 2), else no limit; the user's 0 is no limit over the plugin's. `perKeyBarred` keeps the first N in the user's own order (`rank`, so a dragged list counts), preferring ones not resting, and hands the rest to `keepAtOnce`'s reserves: they go after everything else as asides with `candidate.reserve` set (`Weighed.Reserve`), so whatever the routing mode, a reserve is asked only once the kept ones failed or rest, and a kept one that rests gives its seat to the first reserve on the next request. Three guards keep a reserve from being reached for anything else: `laneMate` never spills a full lane onto one, a full queue (`laneErr`) drops the provider's reserves before passing on (`dropReserves`), so the request is turned away with the 429 instead, and session affinity keeps no conversation on a reserve once the kept ones can take it (`affine`'s "reserve"; Strict still holds). Leak known: a failure that rests nobody (a 5xx on one try) still passes that one request to the reserve, as it does to any next candidate. Set in the provider editor's Advanced (Accounts at once, beside Concurrency) or with `magpie provider at-once`; Routing's row says "in reserve · {n} at once" (`TestAtOnceKeepsFirstInUserOrder`, `TestAtOnceFullLaneWaitsForTheKept`, `TestAtOnceReserveTakesOverAndGivesBack`, `provider-at-once.test.cjs`). | [`fallback.go`](../../internal/gateway/fallback.go), [`concurrency.go`](../../internal/gateway/concurrency.go), [`internal/provider/concurrency.go`](../../internal/provider/concurrency.go) | | Sink | With `Sink` on, a key or account that answers 429 while it still has quota goes to the back, behind every one not rate limited since. Held in memory until restart, or until its rest is lifted by hand (Try now, `Unrest` calls `unsink`, `UnrestAll` `unsinkAll` for the key and each of its models), which puts it back in its place (`TestTryNowPutsASunkAccountBack`, `TestUnrestAllUnsinksTheModels`). Another magpie's model rate limited there, whose rest is the model's alone (`remoteModelRest`), sinks alone too (`restID`), and `sunkAt` reads a candidate's model before its key, so the remote's other models keep their place (#2167, ggbdpq; `TestRemoteMagpieRateLimitSinksTheModel`, `TestMagpieAddedByHandRateLimitSinksTheModel`). A group in a group sinks by its own Sink, within its own order (`sinkOwn`, #2255), and the group asked for then sinks the whole by its own; `TestNestedGroupSinksItsOwnOrder`. | [`sink.go`](../../internal/gateway/sink.go) | diff --git a/docs/subsystems/providers-accounts.md b/docs/subsystems/providers-accounts.md index 4c6e3f67a..94168d6df 100644 --- a/docs/subsystems/providers-accounts.md +++ b/docs/subsystems/providers-accounts.md @@ -18,7 +18,7 @@ keys and accounts per request is in [Gateway routing and fallback](gateway-routi | Part | Responsibility | Source | | --- | --- | --- | | Provider | `Provider` holds the endpoint bases for each `Protocol` (Chat, Responses, Anthropic, Gemini), the keys, `Fallback`, `Routing`, `Sink`, `Affinity`, concurrency and queue limits, `Headers`, `Proxy`, models, and balance settings. `BaseAPI` is the API a custom provider's editor shows its Base URL as: the one the user picked and saved, while it has a URL, so a provider with a chat URL beside its Responses one isn't shown as OpenAI compatible after Responses was picked. Requests go by which URLs are set; `Native`, the API agents' model files ask a model on, takes `BaseAPI` where it serves the model, after the OpenAI-model and Claude-on-Messages rules (nb5p on Discord: dsh asked a Responses relay's GPTs on Chat). A custom provider's `Gemini` URL is the base of Google's Gemini API, or of one that answers as it does (#1346): `GeminiBase` keeps it as the base (…/v1beta added to a bare host, a pasted endpoint or model list cut back), requests go to `models/{model}:streamGenerateContent?alt=sse` under it (`GeminiPath`) signed with `x-goog-api-key` (`AuthHeaders`), and its models are listed by `catalog.FetchGemini` (paged, only those serving generateContent). Factory's sign-in alone keeps its own `/generate` route and token (`FactoryGemini`). `Account` is set only for a subscription and is never saved (`json:"-"`). | [`provider.go`](../../internal/provider/provider.go) | -| Rate windows | A provider bills the hours it says at its own rate (#2463): `RateWindows`, each a span `HH:MM`–`HH:MM` on this computer's clock whose end may pass its start over midnight, the days it is on (`Days`, `time.Weekday`'s numbers, none for every day), and a rate from just over 0 to 1000 at three decimals. The first window that holds a call's time multiplies the price again, on top of `PriceRate` — a price the user set for a model included, which the price rate alone leaves as set — and outside every window the price rate alone counts. A call is priced at its own time wherever a cost is counted call by call — the Usage page and its CSV, a gateway key's cost limit, the gateway's sessions in Usage — by `EffectivePriceAt`, which `EffectivePriceIn` is at `time.Now()`, and its record's time is read on this computer's clock whatever zone it was written in (a call reported as `…Z`); the Sessions page sums a session's calls by model, not by time, so it prices them without any window (`BasePriceIn` in `sessions.priceOf`), the same at every hour it is read; the ledger's `Pricer` holds each provider's base price and windows once and reads each record's rate at the record's own time, so a window that opens mid-page prices only the calls inside it; a gateway block's rows (`blockPricer`, the Requests tab) take their price from a memo asked with no time, which `RateAt` reads as no window, and each row is put at its own window's rate there (`atWindow` before `Price.In`). A list price billed double at peak (`Peak`, DeepSeek's and the relays `PeakOf` names) is part of the base: the final price is that base, peak included, times the window's rate, so a provider with a `Peak` needs no window for the same hours: the order is the spec (the author, YangHonghang), so a 0.8 window on a shared DeepSeek key takes 0.8 off the peak price at peak, and a window set over the official peak hours would double them twice, which the editor's hint says under the windows. `/v1/models` prices its list at now (`EntryPricer`); the model list magpie writes into an agent's own config (`AgentPricer`, Pi's and omp's cost) leaves every window out, since nothing rewrites that file as a window opens or closes. `CheckRateWindows` says what is wrong with a set; the editor keeps the windows under Advanced, drawn by `ratewindows.js`, which app.js imports when an editor draws the field (`rateWindowsField`) so it adds nothing to the core's scripts — until it has loaded, a save leaves `rateWindows` out, which keeps them. A provider with windows shows what it bills at now on its row (`rateNow` in `/api/providers`, `rateNowOf` in the GUI's `providers.go`: `RateAt` on the server's clock, which calls are counted on, never the browser's); one with a price rate alone shows nothing new. Windows are kept with the provider: a save that leaves them out keeps them, null or an empty list clears them, and a signed-in account's survive its `Save` — the account branch and `withPicks` both go through one list, `accountSettings`, beside its `PriceRate`, or the editor's Save would quietly drop what it shows (#4738: two lists drifted, and `additionalTools`, extraBody, reply headers, its rests, `limitRestOff` and patience were each lost one way; `TestAccountSettingsKept`). | [`ratewindow.go`](../../internal/provider/ratewindow.go), [`models.go`](../../internal/provider/models.go), [`ledger.go`](../../internal/usage/ledger.go) (`Pricer`), [`app.js`](../../internal/gui/assets/app.js) (`rateWindowsField`), [`ratewindows.js`](../../internal/gui/assets/ratewindows.js), [`gui/providers.go`](../../internal/gui/providers.go) (`rateNowOf`) | +| Rate windows | A provider bills the hours it says at its own rate (#2463): `RateWindows`, each a span `HH:MM`–`HH:MM` on this computer's clock whose end may pass its start over midnight, the days it is on (`Days`, `time.Weekday`'s numbers, none for every day), and a rate from just over 0 to 1000 at three decimals. The first window that holds a call's time multiplies the price again, on top of `PriceRate` — a price the user set for a model included, which the price rate alone leaves as set — and outside every window the price rate alone counts. A call is priced at its own time wherever a cost is counted call by call — the Usage page and its CSV, a gateway key's cost limit, the gateway's sessions in Usage — by `EffectivePriceAt`, which `EffectivePriceIn` is at `time.Now()`, and its record's time is read on this computer's clock whatever zone it was written in (a call reported as `…Z`); the Sessions page sums a session's calls by model, not by time, so it prices them without any window (`BasePriceIn` in `sessions.priceOf`), the same at every hour it is read; the ledger's `Pricer` holds each provider's base price and windows once and reads each record's rate at the record's own time, so a window that opens mid-page prices only the calls inside it; a gateway block's rows (`blockPricer`, the Requests tab) take their price from a memo asked with no time, which `RateAt` reads as no window, and each row is put at its own window's rate there (`atWindow` before `Price.In`). A list price billed double at peak (`Peak`, DeepSeek's, Ollama Cloud's two DeepSeek models' and the relays `PeakOf` names) is part of the base: the final price is that base, peak included, times the window's rate, so a provider with a `Peak` needs no window for the same hours: the order is the spec (the author, YangHonghang), so a 0.8 window on a shared DeepSeek key takes 0.8 off the peak price at peak, and a window set over the official peak hours would double them twice, which the editor's hint says under the windows. `/v1/models` prices its list at now (`EntryPricer`); the model list magpie writes into an agent's own config (`AgentPricer`, Pi's and omp's cost) leaves every window out, since nothing rewrites that file as a window opens or closes. `CheckRateWindows` says what is wrong with a set; the editor keeps the windows under Advanced, drawn by `ratewindows.js`, which app.js imports when an editor draws the field (`rateWindowsField`) so it adds nothing to the core's scripts — until it has loaded, a save leaves `rateWindows` out, which keeps them. A provider with windows shows what it bills at now on its row (`rateNow` in `/api/providers`, `rateNowOf` in the GUI's `providers.go`: `RateAt` on the server's clock, which calls are counted on, never the browser's); one with a price rate alone shows nothing new. Windows are kept with the provider: a save that leaves them out keeps them, null or an empty list clears them, and a signed-in account's survive its `Save` — the account branch and `withPicks` both go through one list, `accountSettings`, beside its `PriceRate`, or the editor's Save would quietly drop what it shows (#4738: two lists drifted, and `additionalTools`, extraBody, reply headers, its rests, `limitRestOff` and patience were each lost one way; `TestAccountSettingsKept`). | [`ratewindow.go`](../../internal/provider/ratewindow.go), [`models.go`](../../internal/provider/models.go), [`ledger.go`](../../internal/usage/ledger.go) (`Pricer`), [`app.js`](../../internal/gui/assets/app.js) (`rateWindowsField`), [`ratewindows.js`](../../internal/gui/assets/ratewindows.js), [`gui/providers.go`](../../internal/gui/providers.go) (`rateNowOf`) | | Anthropic key header | A provider of the user's own on a third-party Anthropic API is sent its key as both `x-api-key` and `Authorization: Bearer` (`AuthHeaders`); Anthropic's own API, Bedrock, Azure, Vertex and every subscription account have their own and never this choice (`BothAuth` is false). Some services refuse the two together with a 401 (Aloha on Discord: "鉴权 header, x-api-key 和 Authorization 不可以同时存在"), so `Provider.AuthHeader` (`authHeader`: empty for both, `x-api-key` or `bearer`; anything else is read as empty) sends one alone, picked in the editor's Key header row (shown while `bothAuth` is true, or a custom provider's Anthropic URL is a third party's). Left at both, a 401 whose body `catalog.BothAuthRefused` tells as that refusal (it names both headers and says they can't be together, in Chinese or English) is asked once more with x-api-key alone, then Bearer alone (`RetryOneAuth`, in the gateway's `forwardOnce` and the provider test's `probe`; `catalog.fetchOne` for the model list through `listAuth`); the first not answered 401 or 403 is kept with `LearnAuthHeader`, which never changes a pick the user made. A request carrying the user's own `Authorization` or `x-api-key` header is never retried. | [`authheader.go`](../../internal/provider/authheader.go), [`test.go`](../../internal/provider/test.go), [`catalog/authheader.go`](../../internal/catalog/authheader.go), [`catalog/live.go`](../../internal/catalog/live.go) | | GLM Coding Plan key at pay as you go | Zhipu's and Z.ai's presets offer Pay as you go first (`/api/paas/v4`) and the Coding Plan (`/api/coding/paas/v4`, Responses at `/api/v1`); both share `/api/anthropic`, which bills the plan, so a plan's key left at Pay as you go worked in Claude Code and was refused 429 code 1113 "余额不足或无可用资源包" in Codex (@cleverpigo on X). Nothing in the key tells the two apart, so a Chat request to `open.bigmodel.cn` or `api.z.ai` at `/api/paas/v4` refused 1113 is asked once more at `/api/coding/paas/v4` (`RetryZhipuCoding`, in the gateway's `forwardOnce` and the provider test's `probe`). Served there, `LearnZhipuCoding` moves a saved provider with that one key, still at that URL, to the plan's OpenAI URL (and the preset's plan Responses URL when it has none); one with other keys stays and is asked again each time. Refused there too, the 1113 body keeps its code and gets both URLs and what to change in its message (`ZhipuNoBalanceHint`). A pay-as-you-go key with a balance is never answered 1113 and never sent to the plan's endpoint. | [`zhipu_coding.go`](../../internal/provider/zhipu_coding.go), [`test.go`](../../internal/provider/test.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 ` didn't take this key (): …` 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) | diff --git a/internal/catalog/peak.go b/internal/catalog/peak.go index c0dcd3ca0..a0a30a066 100644 --- a/internal/catalog/peak.go +++ b/internal/catalog/peak.go @@ -21,10 +21,17 @@ const ( // and OpenCode Go (https://opencode.ai/docs/go) bill DeepSeek's models // at, neither of which names a holiday PeakWeekdays Peak = "weekdays" + // PeakOllama is Ollama Cloud's: 12:00 to 18:00 UTC, Monday to Friday + // (https://ollama.com/pricing: off-peak outside 12:00 and 18:00 UTC on + // weekdays, and all of Saturday and Sunday), where its + // off-peak rows are half its peak ones and models.dev lists the + // off-peak row as the price. It names no holiday. + PeakOllama Peak = "ollama" ) // PeakFactor is what a call in the peak hours costs, times the off-peak -// list price: DeepSeek's off-peak rates are half its peak rates. +// list price: DeepSeek's off-peak rates are half its peak rates, and so +// are Ollama Cloud's. const PeakFactor = 2 // At is whether a call made at t is in the peak hours. A zero time, a @@ -37,7 +44,11 @@ func (k Peak) At(t time.Time) bool { if wd := u.Weekday(); wd == time.Saturday || wd == time.Sunday { return false } - if h := u.Hour(); !(h >= 1 && h < 4 || h >= 6 && h < 10) { + h := u.Hour() + if k == PeakOllama { + return h >= 12 && h < 18 + } + if !(h >= 1 && h < 4 || h >= 6 && h < 10) { return false } // the peak hours are 09:00 to 18:00 in China, so a holiday's date is diff --git a/internal/catalog/peak_test.go b/internal/catalog/peak_test.go index 7086a38fe..80ec68e6e 100644 --- a/internal/catalog/peak_test.go +++ b/internal/catalog/peak_test.go @@ -64,6 +64,50 @@ func TestPeakHours(t *testing.T) { } } +// Ollama Cloud's peak hours are 12:00 to 18:00 UTC, Monday to Friday, +// holidays too: each edge a minute either side, on a weekday, a weekend +// day and a Chinese holiday, in whatever zone the time is written in. +func TestOllamaPeakHours(t *testing.T) { + far := []*time.Location{time.UTC, time.FixedZone("+14", 14*3600), time.FixedZone("-11", -11*3600), time.FixedZone("+0545", 5*3600+45*60)} + edges := map[string]bool{ + "11:59": false, "12:00": true, "17:59": true, "18:00": false, + "00:00": false, "02:00": false, "23:59": false, "15:30": true, + } + for _, c := range []struct { + day string + weekday bool + }{ + {"2026-10-28", true}, // a Wednesday + {"2026-10-26", true}, // a Monday + {"2026-10-30", true}, // a Friday + {"2026-10-05", true}, // a Monday in China's National Day break + {"2026-10-31", false}, // a Saturday + {"2026-11-01", false}, // a Sunday + } { + for hm, peak := range edges { + v, err := time.Parse("2006-01-02 15:04", c.day+" "+hm) + if err != nil { + t.Fatal(err) + } + for _, z := range far { + if got := PeakOllama.At(v.In(z)); got != (peak && c.weekday) { + t.Errorf("ollama %s %s UTC in %s: peak %v", c.day, hm, z, got) + } + } + } + } + if PeakOllama.At(time.Time{}) { + t.Error("a call with no time is at peak") + } + pro := Price{Input: 0.66, Output: 1.98, CacheRead: 0.022, Peak: PeakOllama} + if got, want := pro.In(time.Date(2026, 10, 28, 12, 0, 0, 0, time.UTC)), (Price{Input: 1.32, Output: 3.96, CacheRead: 0.044}); !got.Same(want) { + t.Errorf("peak: %+v, want %+v", got, want) + } + if got, want := pro.In(time.Date(2026, 10, 28, 11, 59, 0, 0, time.UTC)), (Price{Input: 0.66, Output: 1.98, CacheRead: 0.022}); !got.Same(want) { + t.Errorf("off-peak: %+v, want %+v", got, want) + } +} + // A price with no Peak holds at every hour; a peak-billed one doubles in // its peak hours, every part of it, tiers too, and the price In gives is // one that holds (In again doesn't double it twice). diff --git a/internal/gateway/cheapest_test.go b/internal/gateway/cheapest_test.go index 449cb012a..0c9ecf1ce 100644 --- a/internal/gateway/cheapest_test.go +++ b/internal/gateway/cheapest_test.go @@ -121,3 +121,97 @@ func TestCheapestFirstIsAGroupsOnly(t *testing.T) { t.Fatalf("the group didn't keep Cheapest first: %+v", gs) } } + +// Ollama Cloud bills deepseek-v4.1-flash at half outside 12:00 to 18:00 +// UTC on weekdays and all of Saturday and Sunday (hayden4608 on Discord, +// https://ollama.com/pricing): $0.15/$0.60 then, $0.30/$1.20 in its peak +// hours. A relay at one $0.22/$0.88 goes behind Ollama Cloud off-peak and +// ahead of it at peak, at each edge a minute either side and on a +// Saturday, on the clock of a far zone too, and the relay's price is the +// same at every hour. +func TestCheapestFirstGroupFollowsOllamaOffPeak(t *testing.T) { + fresh(t) + up := httptest.NewServer(http.HandlerFunc(streamed)) + t.Cleanup(up.Close) + to, _ := url.Parse(up.URL) + for _, p := range []provider.Provider{ + {ID: "ollama-cloud", Preset: "ollama-cloud", Name: "Ollama Cloud", Key: "sk-oc", Chat: "https://ollama.com/v1", Models: []string{"deepseek-v4.1-flash"}}, + {ID: "rl", Name: "Relay", Key: "sk-rl", Chat: "https://relay.example/v1", Models: []string{"deepseek-v4.1-flash"}}, + } { + if err := provider.Save(p); err != nil { + t.Fatal(err) + } + } + f := func(v float64) *float64 { return &v } + if err := settings.Save(settings.Settings{ModelPrices: map[string]settings.ModelPrice{ + "ollama-cloud/deepseek-v4.1-flash": {Input: f(0.15), Output: f(0.60), CacheRead: f(0.003), CacheWrite: f(0)}, + "rl/deepseek-v4.1-flash": {Input: f(0.22), Output: f(0.88), CacheRead: f(0.01), CacheWrite: f(0)}, + }}); err != nil { + t.Fatal(err) + } + if err := provider.SaveGroup(provider.Group{ + Name: "O", Members: []string{"rl/deepseek-v4.1-flash", "ollama-cloud/deepseek-v4.1-flash"}, Routing: provider.Cheapest, + }); err != nil { + t.Fatal(err) + } + s := New() + s.client = &http.Client{Transport: roundTripFunc(func(r *http.Request) (*http.Response, error) { + r.URL.Scheme, r.URL.Host = to.Scheme, to.Host + return http.DefaultTransport.RoundTrip(r) + })} + ask := func(at time.Time) *Route { + t.Helper() + old := priceClock + priceClock = func() time.Time { return at } + defer func() { priceClock = old }() + code, body := postAs(t, s, "", `{"model":"group/o","stream":true,"messages":[{"role":"user","content":"x"}]}`) + if code != 200 { + t.Fatalf("code %d: %s", code, body) + } + return s.trace.routes[len(s.trace.routes)-1] + } + for _, c := range []struct { + at time.Time + peak bool + }{ + {time.Date(2026, 10, 28, 11, 59, 0, 0, time.UTC), false}, // a Wednesday + {time.Date(2026, 10, 28, 12, 0, 0, 0, time.UTC), true}, + {time.Date(2026, 10, 28, 17, 59, 0, 0, time.UTC), true}, + {time.Date(2026, 10, 28, 18, 0, 0, 0, time.UTC), false}, + {time.Date(2026, 10, 31, 14, 0, 0, 0, time.UTC), false}, // a Saturday + // 12:00 UTC on the Wednesday written in UTC+14 (Thursday 02:00 + // there), and 17:59 UTC in UTC-11 (Wednesday 06:59) + {time.Date(2026, 10, 29, 2, 0, 0, 0, time.FixedZone("+14", 14*3600)), true}, + {time.Date(2026, 10, 28, 6, 59, 0, 0, time.FixedZone("-11", -11*3600)), true}, + // Saturday 13:00 UTC, which is Sunday 03:00 in UTC+14 + {time.Date(2026, 11, 1, 3, 0, 0, 0, time.FixedZone("+14", 14*3600)), false}, + } { + r := ask(c.at) + want := "ollama-cloud" + if c.peak { + want = "rl" + } + if r.Order[0].Provider != want { + t.Fatalf("%v (%v UTC): Cheapest first went to %q first, want %q: %+v", c.at, c.at.UTC(), r.Order[0].Provider, want, r.Order) + } + for _, w := range r.Order { + if w.Price == nil { + t.Fatalf("%v: %s has no price: %+v", c.at, w.Provider, w) + } + switch w.Provider { + case "ollama-cloud": + in, out := 0.15, 0.60 + if c.peak { + in, out = 0.30, 1.20 + } + if w.Price.Input != in || w.Price.Output != out || w.Price.Peak != c.peak { + t.Fatalf("%v: Ollama Cloud's row %+v, want %v/%v peak %v", c.at, w.Price, in, out, c.peak) + } + case "rl": + if w.Price.Input != 0.22 || w.Price.Output != 0.88 || w.Price.Peak { + t.Fatalf("%v: the relay's row %+v, want its one price", c.at, w.Price) + } + } + } + } +} diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index 08e0a0257..77e76f1a2 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -11436,7 +11436,8 @@ function renderModels(p) { priceBox.title = m.remoteList ? t("What {id} costs, in US dollars per million tokens, as the Usage page counts it; empty: what the other magpie counts it at, shown greyed. A price set here isn't multiplied by the provider's price rate", { id: m.id }) : t("What {id} costs, in US dollars per million tokens, as the Usage page counts it; empty: its list price, shown greyed. A price set here isn't multiplied by the provider's price rate", { id: m.id }); - if (m.list?.peak) priceBox.title += "\n" + t("Off-peak price, the list's or one set here: the Usage page doubles it from 01:00 to 04:00 and 06:00 to 10:00 UTC, Monday to Friday{x}", { x: m.list.peak == "deepseek" ? t(", except on Chinese public holidays") : "" }); + if (m.list?.peak == "ollama") priceBox.title += "\n" + t("Off-peak price, the list's or one set here: the Usage page doubles it from 12:00 to 18:00 UTC, Monday to Friday"); + else if (m.list?.peak) priceBox.title += "\n" + t("Off-peak price, the list's or one set here: the Usage page doubles it from 01:00 to 04:00 and 06:00 to 10:00 UTC, Monday to Friday{x}", { x: m.list.peak == "deepseek" ? t(", except on Chinese public holidays") : "" }); priceBox.append(el("span", "", t("Price, $ / 1M tokens"))); const typed = draft.priceTyped?.[id]; const cell = (value, placeholder, k, label) => { diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js index fe0c3c132..b2ee88827 100644 --- a/internal/gui/assets/i18n.js +++ b/internal/gui/assets/i18n.js @@ -1781,8 +1781,8 @@ const I18N = { "Speed first: {who} hasn't answered {model} lately, so it takes this request to be measured \u2014 one request in five goes to one not measured.": "速度优先:{who} 最近没回答过 {model},所以这个请求给它,好测一下速度——每五个请求有一个给没测过的。", "Speed first: none has answered {model} lately, so {who}, first in the list, goes first and its answer measures it.": "速度优先:最近都没回答过 {model},所以按列出的顺序先用 {who},它的回答会测出速度。", "Cheapest first": "最便宜优先", - "Requests go to the member whose model costs least now, by its price a million tokens in and out at this hour — DeepSeek's peak hours count double — and the cheaper cache read when two cost the same; those that cost the same keep their listed order, and one with no known price goes last.": "请求先发给此刻模型最便宜的成员:看此时每百万输入、输出 token 的价格——DeepSeek 的高峰时段按双倍算——价格相同时看缓存读取哪个便宜;价格相同的按列出的顺序,不知道价格的排最后。", - "Cheapest first: the member whose model costs least now goes first, by its price a million tokens in and out at this hour — so DeepSeek's own API, at double price in its peak hours, goes behind a provider charging less then, and ahead of it off-peak. Those that cost the same keep their listed order; one with no known price goes last.": "最便宜优先:此刻模型最便宜的成员先用,看此时每百万输入、输出 token 的价格——所以 DeepSeek 官方 API 在高峰时段双倍价格时,排在当时收费更低的服务商后面,低谷时段则排在它前面。价格相同的按列出的顺序;不知道价格的排最后。", + "Requests go to the member whose model costs least now, by its price a million tokens in and out at this hour — a vendor's peak hours count double where it bills them so, as DeepSeek and Ollama Cloud do — and the cheaper cache read when two cost the same; those that cost the same keep their listed order, and one with no known price goes last.": "请求先发给此刻模型最便宜的成员:看此时每百万输入、输出 token 的价格——按高峰时段双倍计价的服务商(如 DeepSeek、Ollama Cloud),高峰时段按双倍算——价格相同时看缓存读取哪个便宜;价格相同的按列出的顺序,不知道价格的排最后。", + "Cheapest first: the member whose model costs least now goes first, by its price a million tokens in and out at this hour — so a model billed double in its vendor's peak hours, as DeepSeek's own API and Ollama Cloud's DeepSeek models are, goes behind a provider charging less then, and ahead of it off-peak. Those that cost the same keep their listed order; one with no known price goes last.": "最便宜优先:此刻模型最便宜的成员先用,看此时每百万输入、输出 token 的价格——所以在服务商高峰时段双倍计价的模型(如 DeepSeek 官方 API、Ollama Cloud 的 DeepSeek 模型),高峰时段排在当时收费更低的服务商后面,低谷时段则排在它前面。价格相同的按列出的顺序;不知道价格的排最后。", "{in} in, {out} out a million tokens": "每百万 token 输入 {in}、输出 {out}", "it costs least now, even at its peak price — {price}.": "即使按高峰价格,它此刻也最便宜——{price}。", "Cheapest first: {model} costs least on {who} now, even at its peak price — {price}.": "最便宜优先:即使按高峰价格,{model} 此刻在 {who} 上也最便宜——{price}。", @@ -2513,6 +2513,7 @@ const I18N = { "Its own name, every reasoning level it has, whether it sees images, the API it is asked on, the model it is the same as, its own id, and its list price": "恢复默认名称、全部推理档位、是否支持图片、请求所用的协议、它等同的模型、它自己的 ID,以及官方价格", "What {id} costs, in US dollars per million tokens, as the Usage page counts it; empty: its list price, shown greyed. A price set here isn't multiplied by the provider's price rate": "{id} 的价格,单位为美元 / 百万 tokens,用量页按它计费;留空即官方价格(灰字所示)。这里设的价格不再乘以供应商的价格倍率", "Off-peak price, the list's or one set here: the Usage page doubles it from 01:00 to 04:00 and 06:00 to 10:00 UTC, Monday to Friday{x}": "闲时价(官方价格或在此设置的价格):周一至周五 UTC 01:00–04:00 与 06:00–10:00{x},用量页按两倍计", + "Off-peak price, the list's or one set here: the Usage page doubles it from 12:00 to 18:00 UTC, Monday to Friday": "闲时价(官方价格或在此设置的价格):周一至周五 UTC 12:00–18:00,用量页按两倍计", ", except on Chinese public holidays": "(中国法定节假日除外)", "What {id} costs, in US dollars per million tokens, as the Usage page counts it; empty: what the other magpie counts it at, shown greyed. A price set here isn't multiplied by the provider's price rate": "{id} 的价格,单位为美元 / 百万 tokens,用量页按它计费;留空即另一台 magpie 计费用的价格(灰字所示)。这里设的价格不再乘以供应商的价格倍率", "Price, $ / 1M tokens": "价格($ / 百万 tokens)", @@ -4331,7 +4332,7 @@ const I18N = { "Rate windows": "时段倍率", "Add a window": "添加时段", "Inside a window a call costs the official price times its rate, on top of the price rate; outside every window the price rate alone counts. The first window that holds a call wins. Times are on the clock of the computer magpie runs on, and 22:00–6:00 crosses midnight. No day ticked is every day. A price you set for a model is scaled by the window too. Changing the windows prices the calls already counted again, as a changed price rate does.": "时段内的调用按官方价乘以该时段的倍率计费,叠加在价格倍率之上;时段之外只按价格倍率。调用命中第一个满足的时段。时间按运行 magpie 的那台电脑的时钟,22:00–6:00 表示跨零点。不勾任何星期表示每天。为模型单独设的价格同样按该倍率缩放。修改时段后,已记录的调用也按新时段重算,与修改价格倍率相同。", - "DeepSeek's own API, Command Code and OpenCode Go already count their DeepSeek models' peak hours at double: don't add those hours as a window, or they count twice.": "DeepSeek 官方 API、Command Code 和 OpenCode Go 的 DeepSeek 模型已按官方高峰时段双倍计价:不要再把这些时段设为时段倍率,否则会重复计算。", + "DeepSeek's own API, Command Code, OpenCode Go and Ollama Cloud already count their DeepSeek models' peak hours at double: don't add those hours as a window, or they count twice.": "DeepSeek 官方 API、Command Code、OpenCode Go 和 Ollama Cloud 的 DeepSeek 模型已按各自的高峰时段双倍计价:不要再把这些时段设为时段倍率,否则会重复计算。", "Window starts at": "时段开始于", "Window ends at": "时段结束于", "Rate in this window": "该时段的倍率", @@ -6124,8 +6125,8 @@ const I18N = { "Speed first: {who} hasn't answered {model} lately, so it takes this request to be measured \u2014 one request in five goes to one not measured.": "速度優先:{who} 最近沒回答過 {model},所以這個請求給它,好測一下速度——每五個請求有一個給沒測過的。", "Speed first: none has answered {model} lately, so {who}, first in the list, goes first and its answer measures it.": "速度優先:最近都沒回答過 {model},所以按列出的順序先用 {who},它的回答會測出速度。", "Cheapest first": "最便宜優先", - "Requests go to the member whose model costs least now, by its price a million tokens in and out at this hour — DeepSeek's peak hours count double — and the cheaper cache read when two cost the same; those that cost the same keep their listed order, and one with no known price goes last.": "請求先發給此刻模型最便宜的成員:看此時每百萬輸入、輸出 token 的價格——DeepSeek 的尖峰時段按雙倍算——價格相同時看快取讀取哪個便宜;價格相同的按列出的順序,不知道價格的排最後。", - "Cheapest first: the member whose model costs least now goes first, by its price a million tokens in and out at this hour — so DeepSeek's own API, at double price in its peak hours, goes behind a provider charging less then, and ahead of it off-peak. Those that cost the same keep their listed order; one with no known price goes last.": "最便宜優先:此刻模型最便宜的成員先用,看此時每百萬輸入、輸出 token 的價格——所以 DeepSeek 官方 API 在尖峰時段雙倍價格時,排在當時收費更低的服務商後面,離峰時段則排在它前面。價格相同的按列出的順序;不知道價格的排最後。", + "Requests go to the member whose model costs least now, by its price a million tokens in and out at this hour — a vendor's peak hours count double where it bills them so, as DeepSeek and Ollama Cloud do — and the cheaper cache read when two cost the same; those that cost the same keep their listed order, and one with no known price goes last.": "請求先發給此刻模型最便宜的成員:看此時每百萬輸入、輸出 token 的價格——按尖峰時段雙倍計價的服務商(如 DeepSeek、Ollama Cloud),尖峰時段按雙倍算——價格相同時看快取讀取哪個便宜;價格相同的按列出的順序,不知道價格的排最後。", + "Cheapest first: the member whose model costs least now goes first, by its price a million tokens in and out at this hour — so a model billed double in its vendor's peak hours, as DeepSeek's own API and Ollama Cloud's DeepSeek models are, goes behind a provider charging less then, and ahead of it off-peak. Those that cost the same keep their listed order; one with no known price goes last.": "最便宜優先:此刻模型最便宜的成員先用,看此時每百萬輸入、輸出 token 的價格——所以在服務商尖峰時段雙倍計價的模型(如 DeepSeek 官方 API、Ollama Cloud 的 DeepSeek 模型),尖峰時段排在當時收費更低的服務商後面,離峰時段則排在它前面。價格相同的按列出的順序;不知道價格的排最後。", "{in} in, {out} out a million tokens": "每百萬 token 輸入 {in}、輸出 {out}", "it costs least now, even at its peak price — {price}.": "即使按尖峰價格,它此刻也最便宜——{price}。", "Cheapest first: {model} costs least on {who} now, even at its peak price — {price}.": "最便宜優先:即使按尖峰價格,{model} 此刻在 {who} 上也最便宜——{price}。", @@ -6834,6 +6835,7 @@ const I18N = { "Its own name, every reasoning level it has, whether it sees images, the API it is asked on, the model it is the same as, its own id, and its list price": "恢復預設名稱、全部推理檔位、是否支援圖片、請求所用的協議、它等同的模型、它自己的 ID,以及官方價格", "What {id} costs, in US dollars per million tokens, as the Usage page counts it; empty: its list price, shown greyed. A price set here isn't multiplied by the provider's price rate": "{id} 的價格,單位為美元 / 百萬 tokens,用量頁按它計費;留空即官方價格(灰字所示)。這裡設的價格不再乘以供應商的價格倍率", "Off-peak price, the list's or one set here: the Usage page doubles it from 01:00 to 04:00 and 06:00 to 10:00 UTC, Monday to Friday{x}": "離峰價(官方價格或在此設定的價格):週一至週五 UTC 01:00–04:00 與 06:00–10:00{x},用量頁按兩倍計", + "Off-peak price, the list's or one set here: the Usage page doubles it from 12:00 to 18:00 UTC, Monday to Friday": "離峰價(官方價格或在此設定的價格):週一至週五 UTC 12:00–18:00,用量頁按兩倍計", ", except on Chinese public holidays": "(中國法定節假日除外)", "What {id} costs, in US dollars per million tokens, as the Usage page counts it; empty: what the other magpie counts it at, shown greyed. A price set here isn't multiplied by the provider's price rate": "{id} 的價格,單位為美元 / 百萬 tokens,用量頁按它計費;留空即另一台 magpie 計費用的價格(灰字所示)。這裡設的價格不再乘以供應商的價格倍率", "Price, $ / 1M tokens": "價格($ / 百萬 tokens)", @@ -8669,7 +8671,7 @@ const I18N = { "Rate windows": "時段倍率", "Add a window": "新增時段", "Inside a window a call costs the official price times its rate, on top of the price rate; outside every window the price rate alone counts. The first window that holds a call wins. Times are on the clock of the computer magpie runs on, and 22:00–6:00 crosses midnight. No day ticked is every day. A price you set for a model is scaled by the window too. Changing the windows prices the calls already counted again, as a changed price rate does.": "時段內的呼叫以官方價乘上該時段的倍率計費,疊加在價格倍率之上;時段之外只按價格倍率。呼叫命中第一個符合的時段。時間按執行 magpie 的那台電腦的時鐘,22:00–6:00 表示跨午夜。不勾任何星期表示每天。為模型單獨設的價格同樣按該倍率縮放。修改時段後,已記錄的呼叫也依新時段重新計算,與修改價格倍率相同。", - "DeepSeek's own API, Command Code and OpenCode Go already count their DeepSeek models' peak hours at double: don't add those hours as a window, or they count twice.": "DeepSeek 官方 API、Command Code 和 OpenCode Go 的 DeepSeek 模型已按官方尖峰時段雙倍計價:不要再把這些時段設為時段倍率,否則會重複計算。", + "DeepSeek's own API, Command Code, OpenCode Go and Ollama Cloud already count their DeepSeek models' peak hours at double: don't add those hours as a window, or they count twice.": "DeepSeek 官方 API、Command Code、OpenCode Go 和 Ollama Cloud 的 DeepSeek 模型已按各自的尖峰時段雙倍計價:不要再把這些時段設為時段倍率,否則會重複計算。", "Window starts at": "時段開始於", "Window ends at": "時段結束於", "Rate in this window": "該時段的倍率", @@ -10443,8 +10445,8 @@ const I18N = { "Speed first: {who} hasn't answered {model} lately, so it takes this request to be measured \u2014 one request in five goes to one not measured.": "速度優先:{who} は最近 {model} に応答していないため、測るためにこのリクエストを受けます。5 件に 1 件は測っていないものに回ります。", "Speed first: none has answered {model} lately, so {who}, first in the list, goes first and its answer measures it.": "速度優先:最近 {model} に応答したものがないため、並び順で最初の {who} が先に使われ、その応答で速さを測ります。", "Cheapest first": "最安優先", - "Requests go to the member whose model costs least now, by its price a million tokens in and out at this hour — DeepSeek's peak hours count double — and the cheaper cache read when two cost the same; those that cost the same keep their listed order, and one with no known price goes last.": "リクエストは、いまモデルが最も安いメンバーへ先に送られます。この時間帯の入力・出力 100 万トークンあたりの価格で比べ(DeepSeek のピーク時間帯は 2 倍)、同じ価格ならキャッシュ読み取りの安い方が先です。同じ価格のものは設定順で、価格が分からないものは最後です。", - "Cheapest first: the member whose model costs least now goes first, by its price a million tokens in and out at this hour — so DeepSeek's own API, at double price in its peak hours, goes behind a provider charging less then, and ahead of it off-peak. Those that cost the same keep their listed order; one with no known price goes last.": "最安優先:いまモデルが最も安いメンバーが先です。この時間帯の入力・出力 100 万トークンあたりの価格で比べるので、ピーク時間帯に 2 倍になる DeepSeek 公式 API は、その時間はより安いプロバイダーの後ろに、オフピークにはその前に来ます。同じ価格のものは設定順、価格が分からないものは最後です。", + "Requests go to the member whose model costs least now, by its price a million tokens in and out at this hour — a vendor's peak hours count double where it bills them so, as DeepSeek and Ollama Cloud do — and the cheaper cache read when two cost the same; those that cost the same keep their listed order, and one with no known price goes last.": "リクエストは、いまモデルが最も安いメンバーへ先に送られます。この時間帯の入力・出力 100 万トークンあたりの価格で比べ(DeepSeek や Ollama Cloud のようにピーク時間帯を 2 倍で請求するベンダーは、その時間帯は 2 倍)、同じ価格ならキャッシュ読み取りの安い方が先です。同じ価格のものは設定順で、価格が分からないものは最後です。", + "Cheapest first: the member whose model costs least now goes first, by its price a million tokens in and out at this hour — so a model billed double in its vendor's peak hours, as DeepSeek's own API and Ollama Cloud's DeepSeek models are, goes behind a provider charging less then, and ahead of it off-peak. Those that cost the same keep their listed order; one with no known price goes last.": "最安優先:いまモデルが最も安いメンバーが先です。この時間帯の入力・出力 100 万トークンあたりの価格で比べるので、DeepSeek 公式 API や Ollama Cloud の DeepSeek モデルのようにベンダーのピーク時間帯に 2 倍になるモデルは、その時間はより安いプロバイダーの後ろに、オフピークにはその前に来ます。同じ価格のものは設定順、価格が分からないものは最後です。", "{in} in, {out} out a million tokens": "100 万トークンあたり入力 {in}、出力 {out}", "it costs least now, even at its peak price — {price}.": "ピーク価格でも、いま最も安いためです({price})。", "Cheapest first: {model} costs least on {who} now, even at its peak price — {price}.": "最安優先:ピーク価格でも、{model} はいま {who} で最も安いです({price})。", @@ -11173,6 +11175,7 @@ const I18N = { "Its own name, every reasoning level it has, whether it sees images, the API it is asked on, the model it is the same as, its own id, and its list price": "元の名前、すべての推論レベル、画像対応の有無、リクエストに使う API、同じモデルの指定、元の ID、公式価格", "What {id} costs, in US dollars per million tokens, as the Usage page counts it; empty: its list price, shown greyed. A price set here isn't multiplied by the provider's price rate": "{id} の価格(米ドル / 100 万トークン)。使用量ページはこれで計算します。空欄なら公式価格(灰色で表示)。ここで設定した価格にはプロバイダーの価格倍率は掛かりません", "Off-peak price, the list's or one set here: the Usage page doubles it from 01:00 to 04:00 and 06:00 to 10:00 UTC, Monday to Friday{x}": "公式価格もここで設定した価格もオフピーク料金です。月曜から金曜の UTC 01:00–04:00 と 06:00–10:00{x}は、使用量ページで 2 倍として計算します", + "Off-peak price, the list's or one set here: the Usage page doubles it from 12:00 to 18:00 UTC, Monday to Friday": "公式価格もここで設定した価格もオフピーク料金です。月曜から金曜の UTC 12:00–18:00 は、使用量ページで 2 倍として計算します", ", except on Chinese public holidays": "(中国の法定休日を除く)", "What {id} costs, in US dollars per million tokens, as the Usage page counts it; empty: what the other magpie counts it at, shown greyed. A price set here isn't multiplied by the provider's price rate": "{id} の価格(米ドル / 100 万トークン)。使用量ページはこれで計算します。空欄なら相手の magpie が計算に使う価格(灰色で表示)。ここで設定した価格にはプロバイダーの価格倍率は掛かりません", "Price, $ / 1M tokens": "価格($ / 100 万トークン)", @@ -13009,7 +13012,7 @@ const I18N = { "Rate windows": "時間帯倍率", "Add a window": "時間帯を追加", "Inside a window a call costs the official price times its rate, on top of the price rate; outside every window the price rate alone counts. The first window that holds a call wins. Times are on the clock of the computer magpie runs on, and 22:00–6:00 crosses midnight. No day ticked is every day. A price you set for a model is scaled by the window too. Changing the windows prices the calls already counted again, as a changed price rate does.": "時間帯内の呼び出しは公式価格にその時間帯の倍率を掛けた額で計上され、価格倍率にさらに重ねられます。時間帯の外では価格倍率のみが適用されます。呼び出しは最初に一致した時間帯の倍率です。時刻は magpie が動いているコンピュータの時計で、22:00–6:00 は深夜0時をまたぎます。曜日を1つも選ばない場合は毎日です。モデルに個別に設定した価格も同様にその倍率が掛かります。時間帯を変更すると、記録済みの呼び出しも新しい時間帯で計算し直されます(価格倍率の変更と同じです)。", - "DeepSeek's own API, Command Code and OpenCode Go already count their DeepSeek models' peak hours at double: don't add those hours as a window, or they count twice.": "DeepSeek 公式 API、Command Code、OpenCode Go の DeepSeek モデルは公式のピーク時間帯をすでに 2 倍で計上しています。その時間帯を時間帯倍率として追加しないでください。二重に計上されます。", + "DeepSeek's own API, Command Code, OpenCode Go and Ollama Cloud already count their DeepSeek models' peak hours at double: don't add those hours as a window, or they count twice.": "DeepSeek 公式 API、Command Code、OpenCode Go、Ollama Cloud の DeepSeek モデルは、それぞれのピーク時間帯をすでに 2 倍で計上しています。その時間帯を時間帯倍率として追加しないでください。二重に計上されます。", "Window starts at": "時間帯の開始時刻", "Window ends at": "時間帯の終了時刻", "Rate in this window": "この時間帯の倍率", @@ -14793,8 +14796,8 @@ const I18N = { "Speed first: {who} hasn't answered {model} lately, so it takes this request to be measured \u2014 one request in five goes to one not measured.": "Schnellste zuerst: {who} hat {model} zuletzt nicht beantwortet und bekommt diese Anfrage, um gemessen zu werden — eine von fünf Anfragen geht an einen nicht Gemessenen.", "Speed first: none has answered {model} lately, so {who}, first in the list, goes first and its answer measures it.": "Schnellste zuerst: Keiner hat {model} zuletzt beantwortet, daher geht {who}, der Erste in der Liste, zuerst, und seine Antwort misst ihn.", "Cheapest first": "Günstigste zuerst", - "Requests go to the member whose model costs least now, by its price a million tokens in and out at this hour — DeepSeek's peak hours count double — and the cheaper cache read when two cost the same; those that cost the same keep their listed order, and one with no known price goes last.": "Anfragen gehen an das Mitglied, dessen Modell jetzt am wenigsten kostet, nach seinem Preis je Million Tokens Eingabe und Ausgabe zu dieser Stunde — DeepSeeks Spitzenzeiten zählen doppelt — und bei gleichem Preis nach dem günstigeren Cache-Lesen; gleich teure behalten ihre Reihenfolge, eines ohne bekannten Preis kommt zuletzt.", - "Cheapest first: the member whose model costs least now goes first, by its price a million tokens in and out at this hour — so DeepSeek's own API, at double price in its peak hours, goes behind a provider charging less then, and ahead of it off-peak. Those that cost the same keep their listed order; one with no known price goes last.": "Günstigste zuerst: Das Mitglied, dessen Modell jetzt am wenigsten kostet, kommt zuerst, nach seinem Preis je Million Tokens Eingabe und Ausgabe zu dieser Stunde — so steht DeepSeeks eigene API, in ihren Spitzenzeiten zum doppelten Preis, dann hinter einem Anbieter, der weniger verlangt, und außerhalb davor. Gleich teure behalten ihre Reihenfolge; eines ohne bekannten Preis kommt zuletzt.", + "Requests go to the member whose model costs least now, by its price a million tokens in and out at this hour — a vendor's peak hours count double where it bills them so, as DeepSeek and Ollama Cloud do — and the cheaper cache read when two cost the same; those that cost the same keep their listed order, and one with no known price goes last.": "Anfragen gehen an das Mitglied, dessen Modell jetzt am wenigsten kostet, nach seinem Preis je Million Tokens Eingabe und Ausgabe zu dieser Stunde — Spitzenzeiten zählen doppelt, wo ein Anbieter sie so abrechnet, wie DeepSeek und Ollama Cloud — und bei gleichem Preis nach dem günstigeren Cache-Lesen; gleich teure behalten ihre Reihenfolge, eines ohne bekannten Preis kommt zuletzt.", + "Cheapest first: the member whose model costs least now goes first, by its price a million tokens in and out at this hour — so a model billed double in its vendor's peak hours, as DeepSeek's own API and Ollama Cloud's DeepSeek models are, goes behind a provider charging less then, and ahead of it off-peak. Those that cost the same keep their listed order; one with no known price goes last.": "Günstigste zuerst: Das Mitglied, dessen Modell jetzt am wenigsten kostet, kommt zuerst, nach seinem Preis je Million Tokens Eingabe und Ausgabe zu dieser Stunde — so steht ein Modell, das in den Spitzenzeiten seines Anbieters doppelt kostet, wie DeepSeeks eigene API und die DeepSeek-Modelle von Ollama Cloud, dann hinter einem Anbieter, der weniger verlangt, und außerhalb davor. Gleich teure behalten ihre Reihenfolge; eines ohne bekannten Preis kommt zuletzt.", "{in} in, {out} out a million tokens": "{in} Eingabe, {out} Ausgabe je Million Tokens", "it costs least now, even at its peak price — {price}.": "es kostet jetzt am wenigsten, sogar zum Spitzenpreis — {price}.", "Cheapest first: {model} costs least on {who} now, even at its peak price — {price}.": "Günstigste zuerst: {model} kostet jetzt bei {who} am wenigsten, sogar zum Spitzenpreis — {price}.", @@ -15523,6 +15526,7 @@ const I18N = { "Its own name, every reasoning level it has, whether it sees images, the API it is asked on, the model it is the same as, its own id, and its list price": "Eigener Name, alle Reasoning-Stufen, Bildunterstützung, die angefragte API, das Modell, dem es entspricht, die eigene ID und der Listenpreis", "What {id} costs, in US dollars per million tokens, as the Usage page counts it; empty: its list price, shown greyed. A price set here isn't multiplied by the provider's price rate": "Was {id} kostet, in US-Dollar pro Million Tokens, wie die Nutzungsseite rechnet; leer: der Listenpreis (grau). Ein hier gesetzter Preis wird nicht mit dem Preisfaktor des Anbieters multipliziert", "Off-peak price, the list's or one set here: the Usage page doubles it from 01:00 to 04:00 and 06:00 to 10:00 UTC, Monday to Friday{x}": "Listenpreis oder hier gesetzter Preis gilt außerhalb der Spitzenzeit: Montag bis Freitag von 01:00 bis 04:00 und 06:00 bis 10:00 UTC{x} zählt ihn die Nutzungsseite doppelt", + "Off-peak price, the list's or one set here: the Usage page doubles it from 12:00 to 18:00 UTC, Monday to Friday": "Listenpreis oder hier gesetzter Preis gilt außerhalb der Spitzenzeit: Montag bis Freitag von 12:00 bis 18:00 UTC zählt ihn die Nutzungsseite doppelt", ", except on Chinese public holidays": ", außer an chinesischen Feiertagen,", "What {id} costs, in US dollars per million tokens, as the Usage page counts it; empty: what the other magpie counts it at, shown greyed. A price set here isn't multiplied by the provider's price rate": "Was {id} kostet, in US-Dollar pro Million Tokens, wie die Nutzungsseite rechnet; leer: der Preis, mit dem das andere magpie rechnet (grau). Ein hier gesetzter Preis wird nicht mit dem Preisfaktor des Anbieters multipliziert", "Price, $ / 1M tokens": "Preis, $ / 1 Mio. Tokens", @@ -17349,7 +17353,7 @@ const I18N = { "Rate windows": "Zeitfenster", "Add a window": "Zeitfenster hinzufügen", "Inside a window a call costs the official price times its rate, on top of the price rate; outside every window the price rate alone counts. The first window that holds a call wins. Times are on the clock of the computer magpie runs on, and 22:00–6:00 crosses midnight. No day ticked is every day. A price you set for a model is scaled by the window too. Changing the windows prices the calls already counted again, as a changed price rate does.": "Innerhalb eines Zeitfensters kostet ein Aufruf den offiziellen Preis mal dessen Rate, zusätzlich zum Preisfaktor; außerhalb aller Zeitfenster zählt nur der Preisfaktor. Das erste Zeitfenster, das den Aufruf hält, gewinnt. Zeiten gelten nach der Uhr des Computers, auf dem magpie läuft; 22:00–6:00 geht über Mitternacht. Kein Wochentag angehakt heißt jeder Tag. Ein selbst gesetzter Modellpreis wird ebenfalls mit der Rate skaliert. Werden die Zeitfenster geändert, werden auch bereits gezählte Aufrufe neu berechnet, wie bei einem geänderten Preisfaktor.", - "DeepSeek's own API, Command Code and OpenCode Go already count their DeepSeek models' peak hours at double: don't add those hours as a window, or they count twice.": "DeepSeeks eigene API, Command Code und OpenCode Go rechnen ihre DeepSeek-Modelle in den Spitzenzeiten schon doppelt: diese Stunden nicht noch einmal als Zeitfenster eintragen, sonst zählen sie zweifach.", + "DeepSeek's own API, Command Code, OpenCode Go and Ollama Cloud already count their DeepSeek models' peak hours at double: don't add those hours as a window, or they count twice.": "DeepSeeks eigene API, Command Code, OpenCode Go und Ollama Cloud rechnen ihre DeepSeek-Modelle in den Spitzenzeiten schon doppelt: diese Stunden nicht noch einmal als Zeitfenster eintragen, sonst zählen sie zweifach.", "Window starts at": "Zeitfenster beginnt um", "Window ends at": "Zeitfenster endet um", "Rate in this window": "Rate in diesem Zeitfenster", diff --git a/internal/gui/assets/plugins/routing/client.js b/internal/gui/assets/plugins/routing/client.js index db20eb552..406242be3 100644 --- a/internal/gui/assets/plugins/routing/client.js +++ b/internal/gui/assets/plugins/routing/client.js @@ -540,7 +540,7 @@ function routingPage(part) { // say them (app.js ROUTINGS), so every language is already spoken weight: ["By weight", "Requests spread over the keys or accounts by the weight set beside each: one weighing 3 takes three requests for every one weighing 1 takes, evenly over a few requests. One that fails is passed over while it rests, and the others share its requests; a conversation stays with it as Stays says."], free: ["Free first", "Requests go to what costs nothing first: the models their vendor serves at no cost to this subscription's allowance or credits, in their listed order, and only when those can't answer to one that spends them. Nothing that cost nothing is left unused."], - cheap: ["Cheapest first", "Requests go to the member whose model costs least now, by its price a million tokens in and out at this hour — DeepSeek's peak hours count double — and the cheaper cache read when two cost the same; those that cost the same keep their listed order, and one with no known price goes last."], + cheap: ["Cheapest first", "Requests go to the member whose model costs least now, by its price a million tokens in and out at this hour — a vendor's peak hours count double where it bills them so, as DeepSeek and Ollama Cloud do — and the cheaper cache read when two cost the same; those that cost the same keep their listed order, and one with no known price goes last."], fast: ["Speed first", "Requests go to the one that has answered this model fastest lately, by its time to the first token and how fast it writes; those within a tenth of each other keep their listed order. One not measured lately gets one request in five, so it is measured again, and one that fails is passed over while it rests."], }; // modeOf: a routing's name and what it does, a JS gateway plugin's @@ -5155,7 +5155,7 @@ function routingPage(part) { weight: GROUP_WEIGHT, free: "Free first: the members whose model its vendor serves at no cost to the subscription's allowance or credits go first, then the rest — each whole, over its own accounts or keys as its provider routes them. The free ones are tried before any that spends, so nothing that costs nothing is left unused.", fast: "Speed first: the member that answered fastest lately goes first, by its time to the first token and how fast it writes, each of its accounts or keys weighed on its own; those within a tenth keep their listed order, and one not measured lately gets one request in five, so it is measured again.", - cheap: "Cheapest first: the member whose model costs least now goes first, by its price a million tokens in and out at this hour — so DeepSeek's own API, at double price in its peak hours, goes behind a provider charging less then, and ahead of it off-peak. Those that cost the same keep their listed order; one with no known price goes last.", + cheap: "Cheapest first: the member whose model costs least now goes first, by its price a million tokens in and out at this hour — so a model billed double in its vendor's peak hours, as DeepSeek's own API and Ollama Cloud's DeepSeek models are, goes behind a provider charging less then, and ahead of it off-peak. Those that cost the same keep their listed order; one with no known price goes last.", manual: "Manual: every request goes to the model you pick on the group's card, over its own accounts or keys; the others, and the rules, wait until you pick another — none takes over when it fails.", }; // a group in the group, and a provider set to route other than Smart, is diff --git a/internal/gui/assets/ratewindows.js b/internal/gui/assets/ratewindows.js index 81622b2f4..677c023f8 100644 --- a/internal/gui/assets/ratewindows.js +++ b/internal/gui/assets/ratewindows.js @@ -13,7 +13,7 @@ window.rateWindowsPaint = function paint(box, d) { const help = el("div", "hint", t("Inside a window a call costs the official price times its rate, on top of the price rate; outside every window the price rate alone counts. The first window that holds a call wins. Times are on the clock of the computer magpie runs on, and 22:00–6:00 crosses midnight. No day ticked is every day. A price you set for a model is scaled by the window too. Changing the windows prices the calls already counted again, as a changed price rate does.")); // a list price with the vendor's own peak has it already (#2463, // the author): a window over the same hours would double it again - help.append(el("div", "", t("DeepSeek's own API, Command Code and OpenCode Go already count their DeepSeek models' peak hours at double: don't add those hours as a window, or they count twice."))); + help.append(el("div", "", t("DeepSeek's own API, Command Code, OpenCode Go and Ollama Cloud already count their DeepSeek models' peak hours at double: don't add those hours as a window, or they count twice."))); help.id = "rate-windows-help"; box.after(help); box.setAttribute("role", "group"); diff --git a/internal/gui/tests/model-price-edit.test.cjs b/internal/gui/tests/model-price-edit.test.cjs index e812ff3c0..c5eb2986a 100644 --- a/internal/gui/tests/model-price-edit.test.cjs +++ b/internal/gui/tests/model-price-edit.test.cjs @@ -27,6 +27,8 @@ function serve(lang, posts) { // billed by the hour (treeMan on Discord): the list price is off-peak { id: "model-5", name: "Model 5", on: true, efforts: [], images: false, list: { ...list, peak: "deepseek" } }, { id: "model-6", name: "Model 6", on: true, efforts: [], images: false, list: { ...list, peak: "weekdays" } }, + // Ollama Cloud's: its own hours, 12:00 to 18:00 UTC (hayden4608 on Discord) + { id: "model-7", name: "Model 7", on: true, efforts: [], images: false, list: { ...list, peak: "ollama" } }, ]; const provider = { id: "relay", name: "Relay", icon: "generic", chat: "https://relay.example/v1", responses: "", anthropic: "", models, agents: [], key: { set: true, masked: "sk-…1234" }, ready: true }; const providers = { providers: [provider], presets: [], excluded: [], gateway: { running: true, window: true } }; @@ -91,6 +93,12 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.match(await row("model-5").locator(".mprice").getAttribute("title"), holiday); assert.match(await row("model-6").locator(".mprice").getAttribute("title"), peak); assert.doesNotMatch(await row("model-6").locator(".mprice").getAttribute("title"), holiday); + const ollama = await row("model-7").locator(".mprice").getAttribute("title"); + assert.match(ollama, peak); + assert.match(ollama, zh ? /周一至周五 UTC 12:00–18:00/ : /from 12:00 to 18:00 UTC, Monday to Friday/); + assert.doesNotMatch(ollama, /01:00/); + assert.doesNotMatch(ollama, holiday); + assert.doesNotMatch(await row("model-6").locator(".mprice").getAttribute("title"), /12:00/); // a part typed, the others the list's; Restore default drops a price const y = await page.evaluate(() => scrollY); diff --git a/internal/gui/tests/provider-rate-windows.test.cjs b/internal/gui/tests/provider-rate-windows.test.cjs index d95ef3d44..73d176bf4 100644 --- a/internal/gui/tests/provider-rate-windows.test.cjs +++ b/internal/gui/tests/provider-rate-windows.test.cjs @@ -105,7 +105,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert(zh.label && zh.add && zh.hint && zh.bad, "every string has its Chinese"); // the vendors whose list price has its peak already are named under // the windows, in the page's own language - const peak = "DeepSeek's own API, Command Code and OpenCode Go already count their DeepSeek models' peak hours at double: don't add those hours as a window, or they count twice."; + const peak = "DeepSeek's own API, Command Code, OpenCode Go and Ollama Cloud already count their DeepSeek models' peak hours at double: don't add those hours as a window, or they count twice."; const peakText = await page.evaluate(([lang, k]) => lang === "en" ? k : I18N[lang]?.[k], [lang, peak]); assert(peakText, "the peak note has its " + lang); assert((await page.locator(".editor .rate-windows + .hint").innerText()).includes(peakText.trim()), "the peak note is shown"); diff --git a/internal/gui/tests/routing-cheapest-first.test.cjs b/internal/gui/tests/routing-cheapest-first.test.cjs index a40dd5321..9bf08b095 100644 --- a/internal/gui/tests/routing-cheapest-first.test.cjs +++ b/internal/gui/tests/routing-cheapest-first.test.cjs @@ -82,7 +82,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", const price = await say("{in} in, {out} out a million tokens", { in: "$0.150", out: "$0.600" }); assert.equal(await why(), await say("Cheapest first: {model} costs least on {who} now — {price}.", { who: "ollama-cloud", model: "deepseek-v4-flash", price })); assert.equal((await page.locator(".rt-mode").textContent()).trim(), - await say("Requests go to the member whose model costs least now, by its price a million tokens in and out at this hour — DeepSeek's peak hours count double — and the cheaper cache read when two cost the same; those that cost the same keep their listed order, and one with no known price goes last.")); + await say("Requests go to the member whose model costs least now, by its price a million tokens in and out at this hour — a vendor's peak hours count double where it bills them so, as DeepSeek and Ollama Cloud do — and the cheaper cache read when two cost the same; those that cost the same keep their listed order, and one with no known price goes last.")); if (lang !== "en") assert.notEqual(await say("Cheapest first"), "Cheapest first", `${lang} names Cheapest first`); assert.deepEqual(errors, []); }); diff --git a/internal/provider/peak.go b/internal/provider/peak.go index b79c5790a..4143f2187 100644 --- a/internal/provider/peak.go +++ b/internal/provider/peak.go @@ -25,6 +25,9 @@ type peakBill struct { // models are the ids it bills so, without a maker's prefix // ("deepseek/"); nil: every model it serves models []string + // tagged: a listed model with a tag after a colon is the same model + // (Ollama's dated deepseek-v4.1-flash:1017 beside deepseek-v4.1-flash) + tagged bool } var peakBills = []peakBill{ @@ -39,6 +42,12 @@ var peakBills = []peakBill{ // OpenCode Go's (https://opencode.ai/docs/go): Off-Peak and Peak rows {at: func(b string) bool { return openCodeGateway(b) == "go" }, ids: []string{"opencode-go"}, peak: catalog.PeakWeekdays, models: []string{"deepseek-v4.1-flash", "deepseek-v4-pro"}}, + // Ollama Cloud's (https://ollama.com/pricing): the two models with an + // Off-Peak row, at half the price 12:00 to 18:00 UTC on weekdays, + // which models.dev lists as their price; every other model there is + // one price at every hour + {at: func(b string) bool { return HostOf(b) == "ollama.com" }, ids: []string{"ollama-cloud"}, peak: catalog.PeakOllama, + models: []string{"deepseek-v4.1-flash", "deepseek-v4-pro"}, tagged: true}, } // PeakOf is the hours a call to model at p is billed double in, by the @@ -58,7 +67,9 @@ func (p Provider) PeakOf(model string) catalog.Peak { looked := false for _, b := range peakBills { if b.models != nil && !slices.Contains(b.models, m) { - continue + if i := strings.IndexByte(m, ':'); !b.tagged || i < 0 || !slices.Contains(b.models, m[:i]) { + continue + } } if !looked { urls = buf[:0] diff --git a/internal/provider/peak_test.go b/internal/provider/peak_test.go index f13d5150f..af66a06df 100644 --- a/internal/provider/peak_test.go +++ b/internal/provider/peak_test.go @@ -51,6 +51,21 @@ func TestPeakOf(t *testing.T) { {"lookalike host", Provider{ID: "x", Chat: "https://api.deepseek.com.evil.example/v1"}, "deepseek-flash", ""}, {"removed deepseek", Provider{ID: "deepseek"}, "deepseek-flash", catalog.PeakDeepSeek}, {"openai", preset("openai"), "gpt-6-astra", ""}, + // Ollama Cloud: the two models its pricing page gives an Off-Peak + // row, their dated tags too, and nothing else it serves + {"ollama cloud flash", preset("ollama-cloud"), "deepseek-v4.1-flash", catalog.PeakOllama}, + {"ollama cloud pro", preset("ollama-cloud"), "deepseek-v4-pro", catalog.PeakOllama}, + {"ollama cloud dated flash", preset("ollama-cloud"), "deepseek-v4.1-flash:1017", catalog.PeakOllama}, + {"ollama cloud dated pro", preset("ollama-cloud"), "deepseek-v4-pro:0813", catalog.PeakOllama}, + {"ollama cloud v4-flash", preset("ollama-cloud"), "deepseek-v4-flash", ""}, + {"ollama cloud glm", preset("ollama-cloud"), "glm-5.3", ""}, + {"ollama cloud gpt-oss", preset("ollama-cloud"), "gpt-oss:120b", ""}, + {"ollama cloud lookalike tag", preset("ollama-cloud"), "deepseek-v4-pro-max:1", ""}, + {"removed ollama cloud", Provider{ID: "ollama-cloud"}, "deepseek-v4-pro", catalog.PeakOllama}, + {"ollama local", preset("ollama"), "deepseek-v4-pro", ""}, + {"relay named ollama cloud", Provider{ID: "ollama-cloud", Preset: "ollama-cloud", Chat: "https://relay.example/v1"}, "deepseek-v4-pro", ""}, + {"ollama lookalike host", Provider{ID: "x", Chat: "https://ollama.com.evil.example/v1"}, "deepseek-v4-pro", ""}, + {"opencode go at ollama's model", preset("opencode-go"), "deepseek-v4-pro:0813", ""}, } { if got := c.p.PeakOf(c.model); got != c.want { t.Errorf("%s %s: %q, want %q", c.name, c.model, got, c.want) @@ -160,6 +175,118 @@ func TestPriceOfPeak(t *testing.T) { } } +// ollamaCloudCatalog is models.dev's api.json as magpie had it on +// 2026-11-01, these entries byte for byte (descriptions and the like left +// out): Ollama Cloud's DeepSeek models at their Off-Peak row of +// https://ollama.com/pricing, its GLM at its one price, and DeepSeek's own +// API beside it. +const ollamaCloudCatalog = `{ +"ollama-cloud":{"id":"ollama-cloud","api":"https://ollama.com/v1","name":"Ollama Cloud","models":{ +"deepseek-v4.1-flash":{"id":"deepseek-v4.1-flash","cost":{"input":0.15,"output":0.6,"cache_read":0.003}}, +"deepseek-v4.1-flash:1017":{"id":"deepseek-v4.1-flash:1017","cost":{"input":0.15,"output":0.6,"cache_read":0.003}}, +"deepseek-v4-pro":{"id":"deepseek-v4-pro","cost":{"input":0.66,"output":1.98,"cache_read":0.022}}, +"glm-5.3":{"id":"glm-5.3","cost":{"input":1.4,"output":4.4,"cache_read":0.26}}}}, +"deepseek":{"id":"deepseek","api":"https://api.deepseek.com","name":"DeepSeek","models":{ +"deepseek-v4-pro":{"id":"deepseek-v4-pro","cost":{"input":0.66,"output":1.98,"cache_read":0.013}}}} +}` + +// Ollama Cloud's DeepSeek V4.1 Flash and V4 Pro cost their listed +// (off-peak) price outside 12:00 to 18:00 UTC on weekdays and all of +// Saturday and Sunday, and double in those hours, which is its pricing page's peak +// row ($0.30/$1.20, $1.32/$3.96). Every edge is checked a minute either +// side, on the clock of the far zones a call can be written in. Its GLM, +// and DeepSeek's own API in Ollama's peak hours, cost what they did. +func TestOllamaCloudOffPeakPrice(t *testing.T) { + home := t.TempDir() + t.Setenv("HOME", home) + t.Setenv("USERPROFILE", home) + t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config")) + t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache")) + if err := os.MkdirAll(filepath.Dir(catalog.CachePath()), 0o700); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(catalog.CachePath(), []byte(ollamaCloudCatalog), 0o600); err != nil { + t.Fatal(err) + } + catalog.Reset() + t.Cleanup(catalog.Reset) + oc, err := FromPreset("ollama-cloud") + if err != nil { + t.Fatal(err) + } + ds, err := FromPreset("deepseek") + if err != nil { + t.Fatal(err) + } + none := settings.Settings{} + price := func(p Provider, model string, tm time.Time) catalog.Price { + t.Helper() + pr, ok := p.PriceAt(none, model, tm) + if !ok { + t.Fatalf("%s %s: unpriced", p.ID, model) + } + return pr.In(tm) + } + zones := []*time.Location{time.UTC, time.FixedZone("+14", 14*3600), time.FixedZone("-11", -11*3600)} + utc := func(day, hm string) time.Time { + v, err := time.Parse("2006-01-02 15:04", day+" "+hm) + if err != nil { + t.Fatal(err) + } + return v + } + for _, c := range []struct { + day, hm string + peak bool + }{ + {"2026-10-28", "11:59", false}, // a Wednesday + {"2026-10-28", "12:00", true}, + {"2026-10-28", "17:59", true}, + {"2026-10-28", "18:00", false}, + {"2026-10-28", "02:00", false}, // DeepSeek's peak, not Ollama's + {"2026-10-26", "12:00", true}, // a Monday + {"2026-10-30", "17:59", true}, // a Friday + {"2026-10-05", "13:00", true}, // a Chinese holiday: Ollama names none + {"2026-10-31", "12:00", false}, // a Saturday + {"2026-11-01", "17:59", false}, // a Sunday + } { + for _, z := range zones { + tm := utc(c.day, c.hm).In(z) + name := c.day + " " + c.hm + " UTC in " + z.String() + f, pro := price(oc, "deepseek-v4.1-flash", tm), price(oc, "deepseek-v4-pro", tm) + dated := price(oc, "deepseek-v4.1-flash:1017", tm) + wantF := catalog.Price{Input: 0.15, Output: 0.6, CacheRead: 0.003} + wantP := catalog.Price{Input: 0.66, Output: 1.98, CacheRead: 0.022} + if c.peak { + wantF, wantP = wantF.Times(2), wantP.Times(2) + } + if !f.Same(wantF) || !dated.Same(wantF) { + t.Errorf("%s: flash %+v, dated %+v, want %+v", name, f, dated, wantF) + } + if !pro.Same(wantP) { + t.Errorf("%s: pro %+v, want %+v", name, pro, wantP) + } + if g := price(oc, "glm-5.3", tm); !g.Same(catalog.Price{Input: 1.4, Output: 4.4, CacheRead: 0.26}) { + t.Errorf("%s: glm-5.3 %+v, want its one price", name, g) + } + // DeepSeek's own API keeps its own hours: off-peak at Ollama's + // peak, at peak at 02:00 on a weekday that isn't a holiday + dsWant := catalog.Price{Input: 0.66, Output: 1.98, CacheRead: 0.013} + if catalog.PeakDeepSeek.At(tm) { + dsWant = dsWant.Times(2) + } + if d := price(ds, "deepseek-v4-pro", tm); !d.Same(dsWant) { + t.Errorf("%s: deepseek's own %+v, want %+v", name, d, dsWant) + } + } + } + // the page's peak row, to the cent + peak := price(oc, "deepseek-v4-pro", utc("2026-10-28", "15:00")) + if peak.Input != 1.32 || peak.Output != 3.96 || peak.CacheRead != 0.044 { + t.Errorf("deepseek-v4-pro at peak: %+v, want $1.32/$3.96/$0.044", peak) + } +} + // commandCodeCatalog is models.dev's api.json as magpie had it on // 2026-10-30, these entries byte for byte (descriptions and the like left // out). DeepSeek lists V4.1 Flash only as deepseek-flash, by a dated diff --git a/site/public/docs/ja/start.html b/site/public/docs/ja/start.html index a285813db..d1df9aeba 100644 --- a/site/public/docs/ja/start.html +++ b/site/public/docs/ja/start.html @@ -183,7 +183,7 @@ 週のペース pace更新までの 1 時間あたりの週の枠の残りが最も多いアカウント、つまりリセット時に失う分が最も多いもの。これにより各メンバーの週の枠がリセットで無駄になりにくくなります。週の枠がなく 5 時間枠だけのアカウント(Claude Enterprise)は、更新までの 1 時間あたりの 5 時間枠の残りで判断されるので、ほぼ常に最初になります。使用率が 90% 以上のものは、他が応答できなくなるまで待ちます。キーは最近送ったトークン数で判断します。 重み順 weightグループ編集画面で各モデルの横に設定した重み(1〜1000、未設定は 1)に応じてリクエストを分けます。重み 3 のモデルは重み 1 のモデルが 1 件受けるごとに 3 件受け、まとめてではなく均等に散らします。各モデルは自分のプロバイダーのルーティングで自分のアカウントやキーを使い、グループ内のグループは 1 つとして数えます。失敗して休んでいるものはその回から外れ、失敗したときは次のモデルが代わりに答えます。 速度優先 fastこのモデルに最近いちばん速く応答したメンバー、アカウント、キーが先です。最初のトークンまでの時間と出力の速さで比べ、新しい応答ほど重く数えます。差が 1 割以内のものは並び順のままです。1 時間測っていないものには 5 件に 1 件を回すので、一度遅かったチャネルもまた試されます。失敗して休んでいるものは最後です。測るのはストリーミングの応答だけで、再起動すると測り直します。 - 最安優先 cheapルーティンググループのみ。いまモデルが最も安いメンバーが先です。Usage が数えるのと同じく、この時間帯の入力・出力 100 万トークンあたりの価格で比べます:自分で設定した価格、なければ定価に、プロバイダの価格倍率と時間帯倍率をかけたもの。DeepSeek 公式 API、Command Code と OpenCode Go の DeepSeek モデルはピーク時間帯(平日 UTC 01:00–04:00 と 06:00–10:00)に 2 倍になるので、2 つのプロバイダにある同じ DeepSeek モデルはその時間に安い方へ送られます。同じ価格のものは順番どおり、価格が分からないものは最後です。 + 最安優先 cheapルーティンググループのみ。いまモデルが最も安いメンバーが先です。Usage が数えるのと同じく、この時間帯の入力・出力 100 万トークンあたりの価格で比べます:自分で設定した価格、なければ定価に、プロバイダの価格倍率と時間帯倍率をかけたもの。DeepSeek 公式 API、Command Code と OpenCode Go の DeepSeek モデルはピーク時間帯(平日 UTC 01:00–04:00 と 06:00–10:00)に、Ollama Cloud の DeepSeek V4.1 Flash と V4 Pro は自社のピーク時間帯(平日 UTC 12:00–18:00、それ以外は半額)に 2 倍になるので、2 つのプロバイダにある同じ DeepSeek モデルはその時間に安い方へ送られます。同じ価格のものは順番どおり、価格が分からないものは最後です。
diff --git a/site/public/docs/start.html b/site/public/docs/start.html index bf1c876bf..935d110e1 100644 --- a/site/public/docs/start.html +++ b/site/public/docs/start.html @@ -183,7 +183,7 @@ - +
維持会話が、応答したアカウントやキーに留まる期間
Weekly pace paceThe account with the most of its week left per hour until it renews — the one with the most to lose at its reset — so less of each member’s week is lost at its reset; an account with five hours and no week (Claude Enterprise) by what its five hours have left per hour until they renew, so almost always first. One at 90% or more waits until the others can’t answer. A key by the tokens sent it lately.
By weight weightEach model takes its share of the requests by the weight set beside it in the group editor (1 to 1000, 1 if unset): one weighing 3 takes three for every one a model weighing 1 takes, spread out rather than in bursts. Each model is tried whole over its own accounts or keys, as its provider routes them, and a group in the group counts as one. One resting after a failure leaves the round; the next model is the fallback when one fails.
Speed first fastThe member, account or key that answered this model fastest lately: the time to its first token and how fast it writes, newer answers counting more. Those within a tenth of each other keep their order. One not measured in the last hour gets one request in five, so a channel that was slow once is tried again; one resting after a failure goes last. Only streamed replies are measured, and a restart measures again from scratch.
Cheapest first cheapGroups only. The member whose model costs least now, by its price a million tokens in and out at this hour as Usage counts it: your own price for it, else its list price, at the provider’s price rate and rate windows. DeepSeek’s own API, Command Code’s and OpenCode Go’s DeepSeek models cost double in their peak hours (weekdays 01:00–04:00 and 06:00–10:00 UTC), so a DeepSeek model listed on two providers goes to the one cheaper at that hour. Members that cost the same keep their order; one with no known price goes last.
Cheapest first cheapGroups only. The member whose model costs least now, by its price a million tokens in and out at this hour as Usage counts it: your own price for it, else its list price, at the provider’s price rate and rate windows. DeepSeek’s own API, Command Code’s and OpenCode Go’s DeepSeek models cost double in their peak hours (weekdays 01:00–04:00 and 06:00–10:00 UTC), and Ollama Cloud’s DeepSeek V4.1 Flash and V4 Pro in its own (weekdays 12:00–18:00 UTC, half price the rest of the time), so a DeepSeek model listed on two providers goes to the one cheaper at that hour. Members that cost the same keep their order; one with no known price goes last.
diff --git a/site/public/docs/zh/start.html b/site/public/docs/zh/start.html index 4befc3c5d..4a1649471 100644 --- a/site/public/docs/zh/start.html +++ b/site/public/docs/zh/start.html @@ -183,7 +183,7 @@ - +
StaysHow long a conversation stays with the account or key that answered it
重置前用完 pace每周剩余额度除以距重置的小时数,最高的账号排第一——重置时损失最多的那个——少让成员的周额度到重置时作废;只有 5 小时额度、没有周额度的账号(如 Claude Enterprise)按 5 小时窗口的剩余额度除以距它重置的小时数算,所以几乎总排第一。用到 90% 以上的等其他账号都答不了时才用。Key 按最近发给它的 token 数排。
按权重 weight每个模型按群组编辑器里它旁边设的权重(1 到 1000,不设为 1)分得请求:权重 3 的模型每拿三个,权重 1 的拿一个,均匀穿插而不是成批。每个模型按它自己提供方的路由用自己的账号或 Key,群组里的群组算一个成员。失败后歇着的那个退出这一轮;一个失败时,下一个模型接上。
速度优先 fast最近回答这个模型最快的成员、账号或 Key 先用:看首字时间和输出速度,越新的回答算得越重。相差不到一成的保持原来的顺序。一小时内没测过的每五个请求分到一个,慢过一次的渠道还会再试;失败后歇着的排最后。只测流式回复,重启后重新测。
最便宜优先 cheap仅限路由组。此刻模型最便宜的成员先用,按 Usage 计费的方式算这个时段每百万输入、输出 token 的价格:你自己设的价格,否则用标价,再乘以提供方的价格倍率和分时倍率。DeepSeek 官方 API、Command Code 和 OpenCode Go 的 DeepSeek 模型在高峰时段(工作日 UTC 01:00–04:00 和 06:00–10:00)双倍计价,所以同一个 DeepSeek 模型挂在两个提供方上时,会交给这个时段更便宜的那个。价格相同的保持原来的顺序;不知道价格的排最后。
最便宜优先 cheap仅限路由组。此刻模型最便宜的成员先用,按 Usage 计费的方式算这个时段每百万输入、输出 token 的价格:你自己设的价格,否则用标价,再乘以提供方的价格倍率和分时倍率。DeepSeek 官方 API、Command Code 和 OpenCode Go 的 DeepSeek 模型在高峰时段(工作日 UTC 01:00–04:00 和 06:00–10:00)双倍计价,Ollama Cloud 的 DeepSeek V4.1 Flash 和 V4 Pro 则按它自己的高峰时段(工作日 UTC 12:00–18:00,其余时间半价),所以同一个 DeepSeek 模型挂在两个提供方上时,会交给这个时段更便宜的那个。价格相同的保持原来的顺序;不知道价格的排最后。
会话保持会话在回答过它的账号或 Key 上留多久