mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-30 16:23:31 +00:00
Merge pull request #5183 from rick147/codex/feat-openai-reset-credit-cache
feat(openai): refresh reset credit state after quota reset
This commit is contained in:
@@ -834,21 +834,51 @@ export interface OpenAIQuotaResetResult {
|
||||
code: string
|
||||
credit?: OpenAIQuotaResetCredit | null
|
||||
windows_reset: number
|
||||
quota?: OpenAIQuotaUsage | null
|
||||
account?: Account | null
|
||||
cache_refreshed: boolean
|
||||
account_state_recovered: boolean
|
||||
warning_code?:
|
||||
| 'reset_credit_cache_refresh_failed'
|
||||
| 'account_state_recovery_failed'
|
||||
| 'account_state_refresh_failed'
|
||||
}
|
||||
|
||||
/** Usage payload plus whether the reset-credit snapshot was persisted. */
|
||||
export interface OpenAIQuotaRefreshResult extends OpenAIQuotaUsage {
|
||||
cache_persisted: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Query OpenAI/Codex rate-limit usage for an OAuth account.
|
||||
* Query the upstream quota AND persist the reset-credit snapshot on the account
|
||||
* so the card can be rehydrated without an upstream round-trip. It is a POST
|
||||
* because it writes account state (and must therefore be audited).
|
||||
*
|
||||
* The read-only `GET /admin/openai/accounts/:id/quota` endpoint still exists for
|
||||
* API consumers; the panel always wants the snapshot persisted, so it has no
|
||||
* client binding here.
|
||||
*/
|
||||
export async function queryOpenAIQuota(id: number): Promise<OpenAIQuotaUsage> {
|
||||
const { data } = await apiClient.get<OpenAIQuotaUsage>(`/admin/openai/accounts/${id}/quota`)
|
||||
export async function refreshOpenAIQuota(id: number): Promise<OpenAIQuotaRefreshResult> {
|
||||
const { data } = await apiClient.post<OpenAIQuotaRefreshResult>(
|
||||
`/admin/openai/accounts/${id}/quota/refresh`
|
||||
)
|
||||
return data
|
||||
}
|
||||
|
||||
/**
|
||||
* Consume one rate-limit-reset credit for an OpenAI/Codex OAuth account.
|
||||
*
|
||||
* The credit is non-refundable and the endpoint chains an upstream reset with an
|
||||
* upstream re-query, so it needs a larger budget than the default client
|
||||
* timeout: aborting locally would report a successful consumption as a failure
|
||||
* and invite a retry that spends a second credit.
|
||||
*/
|
||||
export async function resetOpenAIQuota(id: number): Promise<OpenAIQuotaResetResult> {
|
||||
const { data } = await apiClient.post<OpenAIQuotaResetResult>(`/admin/openai/accounts/${id}/reset-quota`)
|
||||
const { data } = await apiClient.post<OpenAIQuotaResetResult>(
|
||||
`/admin/openai/accounts/${id}/reset-quota`,
|
||||
undefined,
|
||||
{ timeout: 90_000 }
|
||||
)
|
||||
return data
|
||||
}
|
||||
|
||||
@@ -985,7 +1015,7 @@ export const accountsAPI = {
|
||||
batchRefresh,
|
||||
setPrivacy,
|
||||
revertProxyFallback,
|
||||
queryOpenAIQuota,
|
||||
refreshOpenAIQuota,
|
||||
resetOpenAIQuota,
|
||||
createSparkShadow,
|
||||
getUpstreamBillingProbeSettings,
|
||||
|
||||
Reference in New Issue
Block a user