QuantumNous/new-api · error · Error

Failed to fetch reset credit details

Error message

Failed to fetch reset credit details

What it means

Set as resetCreditsError inside codex-usage-dialog when loading reset-credit details fails. The effect first guards on channelId being present and on isLoadingResetCredits/force, then calls getCodexResetCredits(channelId); a success=false response or thrown request stores the error message in component state instead of a toast.

Source

Thrown at web/src/features/channels/components/dialogs/codex-usage-dialog.tsx:986

      ? response?.message?.trim() || t('Failed to fetch usage')
      : ''

  const loadResetCredits = useCallback(
    async (force = false) => {
      if (!channelId) {
        setResetCreditsError(t('Channel ID is required'))
        return
      }
      if (isLoadingResetCredits || (!force && resetCreditsResponse)) {
        return
      }

      setIsLoadingResetCredits(true)
      setResetCreditsError('')
      try {
        const res = await getCodexResetCredits(channelId)
        if (!res.success) {
          throw new Error(
            res.message || t('Failed to fetch reset credit details')
          )
        }
        setResetCreditsResponse(res)
      } catch (error) {
        setResetCreditsError(
          error instanceof Error
            ? error.message
            : t('Failed to fetch reset credit details')
        )
      } finally {
        setIsLoadingResetCredits(false)
      }
    },
    [channelId, isLoadingResetCredits, resetCreditsResponse, t]
  )

  const handleResetCreditsOpenChange = (nextOpen: boolean) => {

View on GitHub (pinned to e2c7aa7b10)

Solutions

  1. Read the exact resetCreditsError text rendered in the dialog — when res.message exists it carries the backend reason
  2. Re-save the channel's Codex credential and reopen the dialog to re-trigger the fetch
  3. Verify the channel id still resolves (channel not deleted) and your session is valid
  4. Check backend logs for the upstream reset-credits call (status code and body)

Example fix

// before
const res = await getCodexResetCredits(channelId)
if (!res.success) {
  throw new Error(res.message || t('Failed to fetch reset credit details'))
}
// after - keep last good data on refresh failure
const res = await getCodexResetCredits(channelId)
if (!res.success) {
  throw new Error(res.message || t('Failed to fetch reset credit details'))
}
setResetCreditsResponse((prev) => (force ? res : res ?? prev))
Defensive patterns

Strategy: try-catch

Validate before calling

if (!channelId) { setResetCreditsError(t('Channel ID is required')); return }
if (isLoadingResetCredits || (!force && resetCreditsResponse)) return

Type guard

const hasChannelId = (id: string | number | null | undefined): boolean =>
  id !== null && id !== undefined && id !== ''

Try / catch

setIsLoadingResetCredits(true)
setResetCreditsError('')
try {
  const res = await getCodexResetCredits(channelId)
  if (!res.success) throw new Error(res.message || t('Failed to fetch reset credit details'))
  setResetCreditsResponse(res)
} catch (error) {
  setResetCreditsError(error instanceof Error ? error.message : t('Failed to fetch reset credit details'))
} finally {
  setIsLoadingResetCredits(false)
}

Prevention

When it happens

Trigger: Opening the reset-credits section of the Codex usage dialog for a channel whose id is set, where getCodexResetCredits resolves success=false (upstream error, invalid credential) or the request rejects (network/session). Also triggered with force=true when re-fetching after a previous failure.

Common situations: Codex credential lacks permission to read reset-credit windows; upstream API changed shape; admin token expired while the dialog was open; backend proxy cannot reach the Codex billing endpoint.

Related errors


AI-assisted analysis of QuantumNous/new-api@e2c7aa7b10 (2026-08-15). Data as JSON: /api/errors/d738fcdfb4b1304e. Report an issue: GitHub.