can1357/oh-my-pi · error · ProviderHttpError

OpenCode Go usage endpoint returned ${response.status}${deta

Error message

OpenCode Go usage endpoint returned ${response.status}${detail ? `: ${detail}` : ""}

What it means

Thrown by fetchOpenCodeGoUsage when the OpenCode Go usage endpoint returns 401 (missing/invalid key) or 403 (no Go subscription). It deliberately throws — instead of returning null like other statuses — so checkCredentials can mark the credential ok:false (definitively bad) rather than ok:null (unknown). The message may include an upstream error detail read from the response body.

Source

Thrown at packages/ai/src/usage/opencode-go.ts:121

	const url = `${normalizeBaseUrl(params.baseUrl)}${USAGE_PATH}`;
	let payload: unknown;
	try {
		const response = await ctx.fetch(url, {
			headers: {
				accept: "application/json",
				authorization: `Bearer ${credential.apiKey}`,
			},
			signal: params.signal,
		});
		if (!response.ok) {
			// 401 (missing/invalid key) and 403 (no Go subscription) must throw
			// so checkCredentials flags the credential as ok:false rather than
			// ok:null (unknown). Other non-ok statuses are transient — return
			// null so the cached last-good report serves through them.
			if (response.status === 401 || response.status === 403) {
				const detail = await readUpstreamErrorMessage(response);
				throw new ProviderHttpError(
					`OpenCode Go usage endpoint returned ${response.status}${detail ? `: ${detail}` : ""}`,
					response.status,
				);
			}
			ctx.logger?.warn("OpenCode Go usage fetch failed", {
				status: response.status,
				statusText: response.statusText,
			});
			return null;
		}
		payload = (await response.json()) as unknown;
	} catch (error) {
		if (error instanceof ProviderHttpError) throw error;
		ctx.logger?.warn("OpenCode Go usage fetch error", { error: String(error) });
		return null;
	}

	if (!isRecord(payload) || !isRecord(payload.usage)) {

View on GitHub (pinned to 9690622007)

Solutions

  1. For 401, set/replace the OpenCode API key with a valid current credential and retry.
  2. For 403, verify the account has an active OpenCode Go subscription, or upgrade the plan.
  3. Strip whitespace/quotes from the configured key and confirm it belongs to the intended account.
  4. If the key is correct, re-run checkCredentials to confirm ok:false vs ok:null and contact support with the embedded detail.

Example fix

// before
export OPENCODE_API_KEY=sk-example-placeholder
// after
export OPENCODE_API_KEY=sk-live-actual-key-from-dashboard
Defensive patterns

Strategy: validation

Validate before calling

const key = process.env.OPENCODE_API_KEY?.trim();
if (!key) throw new Error("OPENCODE_API_KEY is required for OpenCode Go usage");
const cred = await goProvider.checkCredentials();
if (cred.ok === false) throw new Error(`OpenCode Go credential invalid: check key/subscription`);

Try / catch

try {
	const usage = await goProvider.fetchUsage(params);
} catch (err) {
	if (err instanceof AIError.ProviderHttpError && err.status === 401) {
		// invalid key: reconfigure credential
	} else if (err instanceof AIError.ProviderHttpError && err.status === 403) {
		// no Go subscription: surface upgrade path
	} else throw err;
}

Prevention

When it happens

Trigger: Calling the OpenCode Go usage/credential check with an API key that is absent, revoked, or malformed (401), or with a valid key on an account without an OpenCode Go subscription (403).

Common situations: OPENCODE_API_KEY env var unset or containing a placeholder; key rotated or revoked server-side; subscription lapsed or never purchased; key pasted with whitespace or wrong account.

Related errors


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