feat(quota): Moonshot Open Platform balance and TPD lock for custom nodes - #12590
Open
HouMinXi wants to merge 10 commits into
Open
feat(quota): Moonshot Open Platform balance and TPD lock for custom nodes#12590HouMinXi wants to merge 10 commits into
HouMinXi wants to merge 10 commits into
Conversation
Identify prepaid Open Platform keys by api.moonshot.cn / api.moonshot.ai on the connection baseUrl. Custom compatible-node uuids stay out of the static usage tables. Coding Plan (api.kimi.com/coding) is not this host. Signed-off-by: Minxi Hou <houminxi@gmail.com>
Organization TPD rate limit is a daily cap, not a short 429. Put it in both QUOTA_PATTERNS and TERMINAL_QUOTA_PATTERNS so a Retry-After hint cannot downgrade it. Engine overloaded stays rate_limit. Signed-off-by: Minxi Hou <houminxi@gmail.com>
IANA timezone + local hour, no default. Convert via Intl parts so the endpoint is the operator's wall clock, not process-local midnight. parseTpdLimitFromText reads limit: from the 429 body. Signed-off-by: Minxi Hou <houminxi@gmail.com>
Custom openai-compatible-* ids used to skip creditsExhausted. Open Platform empty-wallet text now still marks the account exhausted. TPD cooldown uses the node clock or Reset header; without either it falls through to short 429 instead of process-local midnight. Signed-off-by: Minxi Hou <houminxi@gmail.com>
GET {origin}/v1/users/me/balance before the usage switch so custom
compatible-node uuids do not fall through to 'not implemented'.
Register moonshot/kimi fetchers at chat and instrumentation startup.
Origin stays on the connection host (.cn vs .ai).
Signed-off-by: Minxi Hou <houminxi@gmail.com>
supportsProviderQuota now matches Open Platform hosts, not just the static usage list. Provider Limits and the home widget use that predicate so mnative uuid connections appear. Apikey allowlist stays for other providers. Signed-off-by: Minxi Hou <houminxi@gmail.com>
Add provider_nodes.daily_quota_reset_timezone/hour (migration 172). Operator fills IANA timezone + local hour in the compatible-node editor. Unknown timezone and hour 24 are rejected. Empty clock stays valid. Signed-off-by: HouMinXi <houminxi@gmail.com> Signed-off-by: Minxi Hou <houminxi@gmail.com>
Startup scans provider_nodes and registers id+prefix fetchers when the baseUrl host is api.moonshot.cn/.ai. Create/update re-register. markAccountUnavailable forwards the node daily-reset clock into checkFallbackError so TPD cools until the configured hour. Signed-off-by: HouMinXi <houminxi@gmail.com> Signed-off-by: Minxi Hou <houminxi@gmail.com>
Self-service dropped providerSpecificData, so uuid nodes always looked unsupported. Keep the host on the connection, await fetcher register on node create, label .cn balance as CNY. Signed-off-by: Minxi Hou <houminxi@gmail.com>
Own growth at existing chokepoints: migration 172 guard, Moonshot fetcher registration, TPD node-clock lock, and TPD tests. Signed-off-by: Minxi Hou <houminxi@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Custom OpenAI-compatible nodes aimed at
api.moonshot.cn/api.moonshot.aishowed no balance on the dashboard. TPD and empty-wallet 429s also failed to stick, so combostrict-randomkept drawing prepaid keys that were already dead for the day.This change treats those hosts as Moonshot Open Platform:
GET /v1/users/me/balance, classify TPD and insufficient-balance 429s as quota, and lock the connection until the node daily-reset clock (IANA timezone + hour) or a Reset header. No clock and no header uses the short 429 cooldown. The TPD ceiling is read fromlimit: Nin the error text.Test plan
135/135 pass on
upstream/release/v3.8.51@2a6d45abe. DroppingproviderSpecificDatafrom self-service, or forcing USD on.cn, turns the two new tests red.Notes for reviewers
api.moonshot.cn/api.moonshot.ai), not a static provider-id list.daily_quota_reset_timezone/daily_quota_reset_houronprovider_nodes. An empty clock is valid..cnbalance is labeled CNY;.aistays USD.Not in this PR
strict-randomto one target per key (account pick stays in auth)