can1357/oh-my-pi · error · AIError.ProviderHttpError

${response.status} ${response.statusText}: ${text}

Error message

${response.status} ${response.statusText}: ${text}

What it means

This AIError.ProviderHttpError is thrown by the GitHub Copilot usage fetcher (fetchJson) whenever the GitHub API responds with a non-OK HTTP status. It carries the numeric status code and embeds the status text plus the raw response body so the caller can see exactly what GitHub rejected and why. It is the generic upstream-HTTP-failure path for all Copilot usage endpoint calls.

Source

Thrown at packages/ai/src/usage/github-copilot.ts:147

	const quotaId = typeof value.quota_id === "string" ? value.quota_id : "";
	const quotaRemaining = toNumber(value.quota_remaining) ?? remaining;
	return {
		entitlement,
		overage_count: overageCount,
		overage_permitted: overagePermitted,
		percent_remaining: percentRemaining,
		quota_id: quotaId,
		quota_remaining: quotaRemaining,
		remaining,
		unlimited,
	};
}

async function fetchJson(ctx: UsageFetchContext, url: string, init: RequestInit): Promise<unknown> {
	const response = await ctx.fetch(url, init);
	if (!response.ok) {
		const text = await response.text();
		throw new AIError.ProviderHttpError(`${response.status} ${response.statusText}: ${text}`, response.status);
	}
	return response.json();
}

async function resolveGitHubUsername(
	ctx: UsageFetchContext,
	baseUrl: string,
	token: string,
	signal?: AbortSignal,
): Promise<string | undefined> {
	try {
		const data = await fetchJson(ctx, `${baseUrl}/user`, {
			headers: {
				Accept: "application/vnd.github+json",
				Authorization: `Bearer ${token}`,
				"X-GitHub-Api-Version": "2022-11-28",
			},
			signal,

View on GitHub (pinned to 9690622007)

Solutions

  1. Read the embedded status and body text to identify the exact GitHub rejection, then fix the credential or request accordingly.
  2. For 401/403, re-authenticate: generate a fresh GitHub token with Copilot access or verify the account has an active Copilot subscription.
  3. For 429/5xx, retry later with backoff — the failure is transient server-side.
  4. Verify any custom GitHub API base URL (proxy/enterprise) is correct and reachable.

Example fix

// before: calling usage fetch with stale token
const usage = await copilot.usage(params);
// after: guard credential first
const cred = await copilot.checkCredentials();
if (!cred.ok) throw new Error(`GitHub credential invalid: ${cred.reason}`);
const usage = await copilot.usage(params);
Defensive patterns

Strategy: try-catch

Validate before calling

const token = process.env.GITHUB_TOKEN;
if (!token) throw new Error("GITHUB_TOKEN is not set");
// optionally probe credential first
const cred = await copilot.checkCredentials();
if (cred.ok === false) throw new Error(`Copilot credential rejected: ${cred.reason}`);

Type guard

function isProviderHttpError(e: unknown): e is AIError.ProviderHttpError {
	return e instanceof AIError.ProviderHttpError && typeof e.status === "number";
}

Try / catch

try {
	const usage = await copilot.usage(params);
} catch (err) {
	if (err instanceof AIError.ProviderHttpError && (err.status === 401 || err.status === 403)) {
		// prompt re-auth / subscription check
	} else if (err instanceof AIError.ProviderHttpError && err.status >= 500) {
		// transient: retry with backoff
	} else throw err;
}

Prevention

When it happens

Trigger: Any call through fetchJson (used by fetchInternalUsage for /copilot_internal/user and fetchBillingUsage for the billing endpoint) where ctx.fetch returns response.ok === false — e.g. 401 from an expired GitHub token, 403 from missing Copilot subscription, 404 from wrong API base URL, 5xx from GitHub outages.

Common situations: Expired or revoked GitHub personal access token; token lacking Copilot access; GH_TOKEN/GITHUB_TOKEN env pointing at an account without a Copilot subscription; corporate proxy intercepting api.github.com; GitHub rate limiting (429).

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/6712ef06b07d939c. Report an issue: GitHub.