musistudio/claude-code-router · error · Error

ZCode provider API key was not found in ZCode config.

Error message

ZCode provider API key was not found in ZCode config.

What it means

importZcodeProvider requires a configured provider (with API key) in the ZCode config; readZcodeConfiguredProvider returned null so there is nothing to import.

Source

Thrown at packages/core/src/agents/local-providers/zcode.ts:94

      detail: "ZCode login was detected, but no usable provider API key was found in ZCode config.",
      id: "zcode-api",
      importable: false,
      kind: "zcode",
      modelDisplayNames,
      models,
      name: "ZCode API",
      protocol: "anthropic_messages",
      sourceFile: credentials.sourceFile,
      status: "locked"
    };
  }
  return missingCandidate("zcode", "zcode-api", "ZCode API", "anthropic_messages", models, modelDisplayNames);
}

export function importZcodeProvider(candidate: LocalAgentProviderCandidate, providerNames: string[]): LocalAgentProviderImportResult {
  const configuredProvider = readZcodeConfiguredProvider();
  if (!configuredProvider) {
    throw new Error("ZCode provider API key was not found in ZCode config.");
  }
  const provider = providerPayload(
    {
      ...candidate,
      modelDisplayNames: configuredProvider.models.length > 0 ? configuredProvider.modelDisplayNames : candidate.modelDisplayNames,
      models: configuredProvider.models.length > 0 ? configuredProvider.models : candidate.models
    },
    uniqueProviderName(providerNames, "ZCode API"),
    configuredProvider.baseUrl,
    zcodeProviderAccountConfig(configuredProvider.baseUrl)
  );
  return {
    candidate,
    provider,
    providerPlugins: [
      apiKeyAuthPlugin("zcode-api-key", configuredProvider.apiKey),
      apiKeyAuthPlugin("zcode-api-key-internal", configuredProvider.apiKey, providerInternalNamePlaceholder)
    ]

View on GitHub (pinned to 99f24806c6)

Solutions

  1. Run `zcode` and configure a provider with an API key, then retry import.
  2. Check the ZCode config file exists and contains the provider+key fields readZcodeConfiguredProvider expects.
  3. Update the app if ZCode changed its config schema.
Defensive patterns

Strategy: validation

Validate before calling

if (!readZcodeConfiguredProvider()) promptZcodeSetup();

Type guard

function zcodeReady(p: unknown): p is { apiKey: string; models: string[] } { return !!p && typeof (p as any).apiKey === 'string'; }

Try / catch

catch (e) { if ((e as Error).message.includes('ZCode provider API key')) showZcodeConfigHelp(); }

Prevention

When it happens

Trigger: Importing the zcode candidate when ~/.zcode config lacks a provider entry or has no API key.

Common situations: ZCode CLI installed but never configured, config file moved/renamed between versions, or key field renamed.

Understand the failure class

Background: "API key is required" / "API key not found" / "No API key was set": the missing-api-key error family across 16 libraries — this error's family across 16 libraries.

Related errors


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