Skip to content

添加了令牌分组,令牌选择删除 - #33

Merged
Calcium-Ion merged 15 commits into
QuantumNous:luxlzz6from
luxlzz6:main
Jan 8, 2024
Merged

Calcium-Ion merged 15 commits into
QuantumNous:luxlzz6from
luxlzz6:main

Conversation

@luxlzz6

@luxlzz6 luxlzz6 commented Dec 20, 2023

Copy link
Copy Markdown
Contributor

No description provided.

@Calcium-Ion
Calcium-Ion changed the base branch from main to luxlzz6 January 8, 2024 06:19
@Calcium-Ion
Calcium-Ion merged commit 86700b0 into QuantumNous:luxlzz6 Jan 8, 2024
x22x22 pushed a commit to x22x22/new-api that referenced this pull request Apr 24, 2026
@randomradio

Copy link
Copy Markdown

Runtime money pricing follow-up pushed in 2e8857ea.

What changed:

  • Runtime ModelPriceHelper now checks enabled retail_pricing_policies with money_usage_pricing first in money billing mode, before falling back to ModelRatio / ModelPrice compatibility paths.
  • PriceData now carries a money pricing snapshot: endpoint, mode, settlement currency, pre-consumed amount micros, actual amount micros, pricing hash/version, and feature JSON.
  • BillingSession, wallet funding, subscription funding, and token budgets now prefer exact amount_micros when a money pricing quote exists. Legacy quota remains as a compatibility/logging quantity.
  • Text settlement now recomputes actual money usage from returned usage and settles wallet/token/subscription by exact micros.
  • Added a retail policy quote helper in service/money_pricing.
  • Fixed Postgres JSON driver compatibility by returning JSON strings from driver.Valuer implementations and accepting both string/[]byte in scans.
  • Updated tests so model/service money tests can run against TEST_POSTGRES_DSN; Postgres mode migrates once per package and setup only clears data.

Verification:

  • go test ./... -> 555 passed / 91 packages.
  • Neon/Postgres isolated schema targeted tests passed for model/service money runtime paths.
  • cd web/default && bun run typecheck && bun run format:check passed.
  • cd web/default && bun run build passed.

Postgres note: used the unpooled Neon host for schema-isolated tests because the pooler rejects startup search_path options. Temporary codex_money_test_* schemas were cleaned up afterward.

@randomradio

Copy link
Copy Markdown

Update: runtime money usage settlement follow-up pushed in 7c8a9658.

Summary:

  • Added shared runtime money usage quote helpers for non-video API settlement.
  • Audio and realtime final settlement now recompute actual amount_micros from retail_pricing_policies.money_usage_pricing and settle wallet/token budgets by exact micros.
  • Realtime intermediate WSS usage now defers money-mode charging to the billing session final settlement, avoiding duplicate money charges; legacy quota mode still uses Reserve.
  • Violation fee can now use a violation money usage rate when configured, with legacy Grok fee calculation retained as fallback.
  • Added TEST_POSTGRES_SCHEMA and TEST_POSTGRES_SIMPLE_PROTOCOL test env support for safer Postgres test isolation.

Verification:

  • rtk go test ./service -run 'TestPostAudioConsumeQuotaUsesMoneyUsageExactAmount|TestPostWssConsumeQuotaUsesMoneyUsageExactAmount|TestPreWssConsumeQuotaDefersMoneyBillingSessionSettlement|TestChargeViolationFeeUsesMoneyUsageExactAmount' -count=1 ✅\n- rtk go test ./service ./model -run 'Money|Pricing|Billing|Quota|Audio|Wss|Violation|Subscription' -count=1 ✅\n- rtk go test ./... ✅ (559 passed in 91 packages)\n- cd web/default && rtk bun run typecheck ✅\n\nPostgres/Neon note:\n- I attempted the requested Neon-backed Go tests using the provided DSN, plus isolated schema/database variants. The Go/pgx test process consistently hung during GORM AutoMigrate/DDL or early DML while Neon showed the backend session idle / waiting for client read. I added test env support to avoid public schema mutation, but the Neon driver/session hang remains external to this code path. Local full Go tests and the new exact-money runtime tests are green.

jiutubaba pushed a commit to jiutubaba/fx-api that referenced this pull request May 17, 2026
* refactor: 自定义业务错误

* refactor: 隐藏服务器错误与统一 panic 响应
lingozhi referenced this pull request in lingozhi/new-api Jul 17, 2026
Measured over 262 prod requests, all six channels serving the SAME model at the
SAME reasoning effort — so the spread is the channel, not the request:

  #41 1275ms (n=90)   #51 1328ms (n=66)   #42 2337ms (n=17)
  #33 3388ms (n=24)   #45 3537ms (n=52)   #57 8133ms (n=8)

Bucketing by uncached prompt tokens holds p50 flat (1612/1934/2073/1802 for
0-2k/2-6k/6-20k/20k+), which rules out prefill volume as the cause. Meanwhile
~100% of requests are affinity-pinned, so the health-weighted selection that was
supposed to steer around slow channels almost never runs — the only exit is
IsChannelFastEnoughForAffinity, and `score > 0.1` with `score = 1/(1+latency)`
only fires past 9s. #45 and #57 kept their sticky traffic forever; 33% of
requests were pinned to a channel 2.6x+ slower than the one next to it.

Release relative to the best peer for the same model+path instead: leave only
when the sticky is BOTH slower than 2s absolute and >2x that peer. The absolute
floor stops churn over gaps nobody can feel (0.3s vs 0.15s is 2x), the ratio
stops churn for gains too small to repay a migration. #42 at 1.83x stays.

The reason this could not just be turned on: migration causes a cold prompt
cache by construction, and a cold 240k-token prefill measured 23348ms. That one
number breaks two mechanisms at once, both of which then punish the channel we
just chose *for being the fastest*:

  - the latency EWMA, which is shared by every affinity key on the channel, so
    one migration would make the destination look slow to all of them and
    stampede them off it, each paying its own cold prefill;
  - cooldownSlowChannelIfNeeded, an entirely separate path that yanks a channel
    out of rotation for 30 minutes past 30s FRT — 23.3s is 78% of that.

So the release is gated three ways. ColdCacheStart marks the attempt and keeps
its latency out of both mechanisms (failures still count — a cold start is no
excuse for erroring). A per-key cooldown stops one key bouncing. A global
minimum interval drains a slow channel one key at a time, because the slow
verdict is per-channel: without it every key pinned to #45 leaves on the same
tick and their cold prefills land on #41 together, making it genuinely slow —
a cascade no latency-exclusion can prevent, since that load is real.

Circuit-open releases stay unconditional and never reach AcquireChannelHealth,
or a rate-limited key would be parked on a tripped channel and a paying request
would become its half-open probe.

Accepted: weighted re-selection can hand a released key back to the same slow
channel (~12.5% by weight). Not excluded — that risks a 503, and the cache
there is still warm, so the only cost is the 10-minute slot.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Firesuiry pushed a commit to Firesuiry/tako-newapi that referenced this pull request Aug 27, 2026
…QuantumNous#33)

Collapse standalone search onto the existing channel ability pool.
POST /v1/search now selects web_search (or x_search for grok_x) with
priority/weight instead of brand virtual models or a random whitelist.
Channel-level RPM/RPD plus optional ability overrides apply to all
capabilities, and 429 parks the channel briefly. Billing uses
standalone_web_search to avoid colliding with chat tool prices.
salem-2007 added a commit to salem-2007/new-api that referenced this pull request Sep 10, 2026
leicanxi added a commit to leicanxi/flowbee-api that referenced this pull request Oct 5, 2026
QuantumNous#33:此前「免费模型调用速率」这条规则只在福利页讲,而进钱包、进概览的人远多于
进福利页的人,多数用户不知道它存在。本轮加露出点,不改名词。
- 概览第 2 步「添加额度」右侧一行浅灰提示:`1 档 · 距 2 档还差 ¥0.943`
- 钱包标题下一行两个入口胶囊:`免费模型调用速率·1 档(余额决定)` / `福利(免费余额)`
- 档位解析收敛为唯一实现 lib/welfare-tier.ts(福利页 / 钱包 / 概览三处共用),
  并把「余额低于最低档 = 未解锁(level -1)」锁进单测 —— 按 0 起步会把未解锁
  用户误标成 1 档,改造QuantumNous#23 修过一次
- 钱包页与福利页拿到最新 self 后回写登录态:此前充值后概览那行提示不会刷新,
  看着像充值没生效
- 术语沿用「速率 / N 档」,不用「等级 + Lv」——Lv 会被读成累积型会员等级,
  而真实规则是余额随时决定档位、余额降了会掉档
- 福利页摘要条补「每分钟次数用完后会优先使用补贴通道」(auto 令牌的实际去向)

QuantumNous#34:顶栏的语言切换换成福利页入口(Gift 图标 -> /invite)。语言切换属低频设置,
而福利页有签到 / 邀请的免费余额,值得常年露在顶栏。原实现保留为注释便于回滚。

附带两处:
- 后台赞助审核列表加订单状态列与筛选,只统计 success —— 点开支付页但未付款的
  pending 记录与真实支持长得一样,不标状态会把人数和金额算高
- 补上 .gitignore 的 *.db-wal / *.db-shm(启用 WAL 后漏配的两条)
yuanjie-ai pushed a commit to apiduo/apiduo that referenced this pull request Nov 18, 2026
priority 是回退链而不是隔离手段:GetRandomSatisfiedChannel 的 retry 直接
是降序优先级层的索引,RetryTimes=1 刚好够降一层。当前 QuantumNous#29(p1) → QuantumNous#33(p0)
就是这条链。

断链实测(QuantumNous#29 base_url 指向 127.0.0.1:1):60ms 返回 202、落点 channel_id=33、
platform=local-image-async、57 秒出图、只有回退渠道被计费。

同时留档三条否决点:504/524 不重试(造断链不能用超时)、LocalError 不重试、
2xx/NoRetry 不重试(任务已接受就不换渠道,避免二次计费)。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants