musistudio/claude-code-router · error · Error

Provider account credential was not found.

Error message

Provider account credential was not found.

What it means

Thrown by codexResetProvider when no provider account target matches the given credential. The service searches providerAccountTargets(provider) for an account whose credential runtime ID equals the requested credentialId (or any account when credentialId is empty); if none matches, this error is raised.

Source

Thrown at packages/core/src/providers/account-service.ts:489

  return providerAccount && providerApiKey(provider) ? [{ account: providerAccount, provider }] : [];
}

function codexResetProvider(config: AppConfig, providerName: string, credentialId: string | undefined): GatewayProviderConfig {
  const normalizedProviderName = normalizeProviderName(providerName);
  const provider = config.Providers.find((candidate) =>
    isGatewayProviderEnabled(candidate) &&
    normalizeProviderName(candidate.name) === normalizedProviderName
  );
  if (!provider) {
    throw new Error("Provider account was not found.");
  }

  const target = providerAccountTargets(provider).find((candidate) => {
    const candidateCredentialId = candidate.credential ? providerCredentialRuntimeId(candidate.provider, candidate.credential) : undefined;
    return !credentialId || candidateCredentialId === credentialId;
  });
  if (!target) {
    throw new Error("Provider account credential was not found.");
  }
  if (!providerAccountHasCodexResetCreditsConnector(target.account)) {
    throw new Error("Provider account does not support Codex manual reset credits.");
  }

  return target.credential
    ? providerWithCredentialApiKey(target.provider, target.credential, target.account)
    : { ...target.provider, account: target.account };
}

function providerAccountHasCodexResetCreditsConnector(account: ProviderAccountConfig): boolean {
  return normalizeConnectors(account).some((connector) =>
    connector.type === "http-json" &&
    /\/wham\/rate-limit-reset-credits(?:$|[?#/])/i.test(connector.endpoint.trim())
  );
}

function providerAccountUnavailableSnapshots(provider: GatewayProviderConfig): ProviderAccountSnapshot[] {

View on GitHub (pinned to 99f24806c6)

Solutions

  1. Verify the credentialId exists in the provider's accounts config before calling
  2. Re-import or re-authenticate the provider account to regenerate credentials
  3. Pass an empty credentialId to select the first matching target

Example fix

// before
await codexResetProvider(provider, staleCredentialId);
// after
const target = providerAccountTargets(provider).find(t => !credentialId || providerCredentialRuntimeId(t.provider, t.credential) === credentialId);
if (!target) throw new Error('credential missing — re-authenticate');
await codexResetProvider(provider, credentialId);
Defensive patterns

Strategy: validation

Validate before calling

const targets = providerAccountTargets(provider);
const ok = !credentialId || targets.some(t => t.credential && providerCredentialRuntimeId(t.provider, t.credential) === credentialId);
if (!ok) throw new Error('re-authenticate provider before reset');

Try / catch

catch (e) { if (e.message.includes('credential was not found')) await reauthAndReimportProvider(); else throw e; }

Prevention

When it happens

Trigger: Calling codexResetProvider(provider, credentialId) where credentialId does not match any configured account credential, or where the provider has no account targets at all.

Common situations: Credential was removed or rotated after the caller captured its ID; stale credential reference in stored config; provider imported without any account connector.

Related errors


AI-assisted analysis of musistudio/claude-code-router@99f24806c6 (2026-08-27). Data as JSON: /api/errors/a99949b3a3756b42. Report an issue: GitHub.