MCPcopy Create free account
hub / github.com/arctic-cli/interface / fetchCodexUsage

Function fetchCodexUsage

packages/arctic/src/provider/usage.ts:741–771  ·  view source on GitHub ↗
(input: {
    provider: Provider.Info
  })

Source from the content-addressed store, hash-verified

739 }
740
741 async function fetchCodexUsage(input: {
742 provider: Provider.Info
743 }): Promise<Omit<Record, "providerID" | "providerName" | "fetchedAt">> {
744 const directAuth = await Auth.get(input.provider.id)
745 const baseKey = input.provider.baseProvider ?? input.provider.id
746 const baseAuth = baseKey !== input.provider.id ? await Auth.get(baseKey) : undefined
747 const auth = directAuth ?? baseAuth
748 if (!auth) {
749 throw new Error("Codex authentication is required. Run `arctic auth codex` to connect your account.")
750 }
751
752 const authKey = directAuth ? input.provider.id : baseKey
753 const { accessToken, accountId } = await resolveCodexCredentials(auth, authKey)
754 const payload = await fetchCodexUsagePayload({
755 baseUrl: resolveCodexBaseUrl(auth),
756 accessToken,
757 accountId,
758 })
759 const rateLimit = payload.rate_limit ?? undefined
760
761 return {
762 planType: payload.plan_type,
763 allowed: rateLimit?.allowed,
764 limitReached: rateLimit?.limit_reached,
765 limits: {
766 primary: mapCodexWindow(rateLimit?.primary_window, "5h"),
767 secondary: mapCodexWindow(rateLimit?.secondary_window, "Weekly"),
768 },
769 credits: mapCredits(payload.credits),
770 }
771 }
772
773 function mapCodexWindow(
774 window: CodexRateLimitWindowSnapshot | null | undefined,

Callers

nothing calls this directly

Calls 6

fetchCodexUsagePayloadFunction · 0.90
resolveCodexCredentialsFunction · 0.85
resolveCodexBaseUrlFunction · 0.85
mapCodexWindowFunction · 0.85
mapCreditsFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected