farion1231/cc-switch · warning · PiFormValidationError

pi.form.credentialRequired

Error message

pi.form.credentialRequired

What it means

Thrown by PiProviderForm's submit() when creating (!isEdit) with a real preset selected (selectedPreset non-null) and the API key field still empty (PiProviderForm.tsx:1089-1094). Presets describe hosted endpoints that require a credential, so the form blocks creation until one is supplied. Choosing 'Custom' (which leaves selectedPreset null) skips this requirement even in create mode. fieldSelector '#pi-api-key' focuses the key input.

Source

Thrown at src/components/providers/forms/PiProviderForm.tsx:1091

          "#pi-settings-config",
        );
      }
      const trimmedName = identity.name.trim();
      const trimmedKey = providerKey.trim();
      if (!trimmedName) {
        throw new PiFormValidationError(
          t("pi.form.nameRequired"),
          'input[name="name"]',
        );
      }
      if (!isEdit && !trimmedKey) {
        throw new PiFormValidationError(
          t("pi.form.providerKeyRequired"),
          "#pi-provider-key",
        );
      }
      if (!isEdit && selectedPreset && apiKey.length === 0) {
        throw new PiFormValidationError(
          t("pi.form.credentialRequired"),
          "#pi-api-key",
        );
      }
      if (!isEdit && models.length === 0) {
        throw new PiFormValidationError(
          t("pi.form.modelRequired"),
          "#pi-add-model",
          true,
        );
      }

      const headers = normalizeRequestHeaders(providerHeaders);
      const seen = new Set<string>();
      const normalizedModels = models.map((model, index) => {
        // Pi treats model IDs as opaque strings. Trimming would rename an
        // imported model.
        const id = model.id;

View on GitHub (pinned to a2e22f3302)

Solutions

  1. Paste the provider's API key into the credential field, then save
  2. Open the preset's apiKeyUrl (form shows the link when selectedPreset.apiKeyUrl exists) to obtain a key
  3. Switch the preset to 'Custom' if the endpoint genuinely needs no credential
Defensive patterns

Strategy: validation

Validate before calling

if (!isEdit && selectedPreset !== null && apiKey.length === 0) {
  setFormError(t("pi.form.credentialRequired"));
  return;
}

Try / catch

try {
  await submit(identity);
} catch (error) {
  if (error instanceof Error && error.name === "PiFormValidationError") { /* focus '#pi-api-key' */ return; }
  throw error;
}

Prevention

When it happens

Trigger: Selecting a hosted preset and clicking Save before pasting an API key; using a key-helper flow but leaving the manual key empty when the preset has no apiKeyUrl; switching presets after clearing the key.

Common situations: User intends to fetch the key later; user selects the wrong preset for a local/no-auth gateway; key stored in a password manager and the paste was missed.

Related errors


AI-assisted analysis of farion1231/cc-switch@a2e22f3302 (2026-08-16). Data as JSON: /api/errors/5aac680b722f7e23. Report an issue: GitHub.