mastra-ai/mastra · warning

No Copilot bearer token

Error message

No Copilot bearer token

What it means

getCopilotModelCatalog fetches the live GitHub Copilot model list and requires a Copilot OAuth bearer token. It calls storage.getApiKey('github-copilot'), which refreshes the token if expired; if that returns nothing, it throws 'No Copilot bearer token'. Internally the error is caught, a hard-coded fallback model list is cached, and a warning is logged, so callers usually just get the fallback catalog.

Source

Thrown at mastracode/sdk/src/providers/github-copilot.ts:375

  storage.reload();

  const cred = storage.get(COPILOT_PROVIDER_ID);
  if (!cred || cred.type !== 'oauth') {
    return [];
  }

  const now = Date.now();
  if (catalogCache && now - catalogCache.fetchedAt < catalogCache.ttl) {
    return catalogCache.models;
  }

  if (inflightFetch) return inflightFetch;

  inflightFetch = (async (): Promise<CopilotModelEntry[]> => {
    try {
      // getApiKey() refreshes the Copilot bearer if it has expired.
      const accessToken = await storage.getApiKey(COPILOT_PROVIDER_ID);
      if (!accessToken) throw new Error('No Copilot bearer token');
      storage.reload();

      const refreshed = storage.get(COPILOT_PROVIDER_ID);
      const enterpriseUrl = (refreshed as GitHubCopilotCredentials | undefined)?.enterpriseUrl;
      const baseUrl = getGitHubCopilotBaseUrl(accessToken, enterpriseUrl);

      const controller = new AbortController();
      const timer = setTimeout(() => controller.abort(), CATALOG_FETCH_TIMEOUT_MS);
      try {
        const models = await fetchCopilotModels({
          baseUrl,
          bearerToken: accessToken,
          signal: controller.signal,
        });
        catalogCache = { fetchedAt: Date.now(), ttl: CATALOG_TTL_MS, models };
        return models;
      } finally {
        clearTimeout(timer);

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Run the Copilot OAuth login/refresh flow (e.g. the SDK's copilot login command) to store a fresh bearer token.
  2. Check the stored credential file for the 'github-copilot' entry and ensure it contains a valid access/refresh token, not just an empty oauth record.
  3. Verify the injected authStorage (if passing opts.authStorage) actually contains Copilot credentials.
  4. Ignore-and-degrade if acceptable: the library catches this and falls back to a hard-coded model list.

Example fix

// before
const models = await getCopilotModelCatalog(); // warns and returns fallback if no token
// after
const cred = authStorage.get('github-copilot');
if (!cred || cred.type !== 'oauth' || !(await authStorage.getApiKey('github-copilot'))) {
  await runCopilotLogin(); // refresh credentials first
}
const models = await getCopilotModelCatalog();
Defensive patterns

Strategy: fallback

Validate before calling

const cred = storage.get('github-copilot');
const token = cred?.type === 'oauth' ? await storage.getApiKey('github-copilot') : null;
if (!token) console.warn('Copilot not authenticated; catalog will use fallback models');

Type guard

function hasCopilotCredential(s: CredentialStore): boolean {
  const c = s.get('github-copilot');
  return !!c && c.type === 'oauth';
}

Try / catch

let models: CopilotModelEntry[];
try {
  models = await getCopilotModelCatalog();
} catch (e) {
  models = COPILOT_FALLBACK_MODELS; // library also degrades internally
}

Prevention

When it happens

Trigger: Calling getCopilotModelCatalog (directly or via copilotModels/models listing) when the stored 'github-copilot' credential exists and is type 'oauth' (passing the cred check), but storage.getApiKey('github-copilot') returns null/undefined — i.e. no stored API key/access token and refresh fails or no refresh token is present.

Common situations: User logged out of GitHub Copilot while a stale oauth credential record remains; expired refresh token so getApiKey cannot mint a new bearer; a custom AuthStorage/credentialStore injected that has the provider entry but no key material; corrupted credentials file after a version migration.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/a6069b360fe57b0b. Report an issue: GitHub.