farion1231/cc-switch · error · Error

Provider key is required for

Error message

Provider key is required for ${appId}

What it means

In createProvider, the appIds opencode/openclaw/hermes/pi derive the new provider's stable ID from providerInput.providerKey, unless category is 'omo' or 'omo-slim' (which get a prefixed generated UUID). For any other category on those apps a falsy providerKey aborts with 'Provider key is required for <appId>' before the Provider object is built. All other appIds fall through to generateUUID() and never reach this branch.

Solutions

  1. Supply providerInput.providerKey (e.g. 'anthropic', 'openrouter') when creating providers on opencode/openclaw/hermes/pi
  2. Or set category to 'omo'/'omo-slim' so the mutation generates a prefixed UUID id instead
  3. Gate the form's submit action on a non-empty provider key so the mutation never fires incomplete

Example fix

// before
createProvider({
  appId: 'opencode',
  providerInput: { category: 'custom', providerKey: '' },
});

// after
createProvider({
  appId: 'opencode',
  providerInput: { category: 'custom', providerKey: 'anthropic' },
});
Defensive patterns

Strategy: validation

Validate before calling

const NEEDS_PROVIDER_KEY = new Set(['opencode', 'openclaw', 'hermes', 'pi']);
const needsKey =
  NEEDS_PROVIDER_KEY.has(appId) &&
  providerInput.category !== 'omo' &&
  providerInput.category !== 'omo-slim';
if (needsKey && !providerInput.providerKey?.trim()) {
  // block submit: show "select a preset / enter provider key"
}

Try / catch

try {
  await createProvider({ appId, providerInput });
} catch (error) {
  if (error instanceof Error && error.message.startsWith('Provider key is required')) {
    // focus the preset/key selector in the form
  } else {
    throw error;
  }
}

Prevention

When it happens

Trigger: createProvider({ appId: 'opencode', providerInput: { category: 'custom', providerKey: '' } }) — a preset-driven form that failed to attach a providerKey, or a hand-built/test mutation call.

Common situations: Custom-provider form submitted without selecting a preset (the preset normally supplies the key); an import path that dropped providerKey; calling the mutation directly in tests.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of farion1231/cc-switch@0b5da51016 (2026-08-20). Data as JSON: /api/errors/145f9920340e97da. Report an issue: GitHub.

Appendix: source

Thrown at src/lib/query/mutations.ts:77

      }

      let id: string;

      if (
        appId === "opencode" ||
        appId === "openclaw" ||
        appId === "hermes" ||
        appId === "pi"
      ) {
        if (
          providerInput.category === "omo" ||
          providerInput.category === "omo-slim"
        ) {
          const prefix = providerInput.category === "omo" ? "omo" : "omo-slim";
          id = `${prefix}-${generateUUID()}`;
        } else {
          if (!providerInput.providerKey) {
            throw new Error(`Provider key is required for ${appId}`);
          }
          id = providerInput.providerKey;
        }
      } else {
        id = generateUUID();
      }

      const newProvider: Provider = {
        ...rest,
        id,
        createdAt: Date.now(),
      };
      delete (newProvider as any).providerKey;

      await providersApi.add(newProvider, appId, addToLive);
      return newProvider;
    },
    onSuccess: async () => {

View on GitHub (pinned to 0b5da51016)