mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-07 16:18:29 +08:00
/v1/sub2api/billing is a key-scoped sub2api convention: any API-key account whose base_url points at a sub2api-compatible upstream answers it regardless of the account platform. Widen probe eligibility from platform=openai to every API-key account (OAuth/Bedrock stay excluded: no static key to present). - central predicate exported as IsUpstreamBillingProbeIdentity; runner, manual probe, SetAccountEnabled, admin create/update/bulk validation and CRS reconcile all follow it - probe target resolution reads credentials.api_key/base_url directly. OpenAI keeps its official-default base URL and openai transport profile. Other platforms whose base_url is empty or points at an official provider API domain (anthropic.com, googleapis.com, x.ai, grok.com, openai.com - matched on the normalized hostname, port and trailing dot stripped, as the exact host or any subdomain) persist "unsupported" without sending a request: the create form fills empty base_url with official defaults and offers official regional presets (e.g. us-east-1.api.x.ai), and official APIs cannot answer /v1/sub2api/billing, so probing would only send the account key to a nonexistent official path - due-scan SQL, BulkUpdate probe WHERE, UpdateCredentials stale-snapshot CASE and proxy-change invalidation drop their platform filters (type='apikey' retained) - frontend: rate cell, edit/create/bulk modals gate on type==='apikey'; the antigravity upstream create flow (its own helper and form section) shows the auto-probe toggle and passes upstream_billing_probe_enabled; bulk WS-mode section stays OpenAI-only; settings copy de-scoped - tests: multiplatform service unit tests (relay success, official/empty base_url unsupported without request, normalized official-host matrix, OpenAI defaults preserved), real-PostgreSQL due-scan coverage for openai/anthropic/grok plus oauth/disabled exclusion, updated sqlmock/CRS/frontend specs; probe stays opt-in per account