farion1231/cc-switch · warning · PiFormValidationError

Enter the API key for this preset

Error message

Enter the API key for this preset

What it means

When creating a provider from a preset, PiProviderForm requires the preset's credential up front: submit() throws pi.form.credentialRequired (focusing #pi-api-key) if selectedPreset is truthy and apiKey.length === 0. Presets describe providers whose APIs all need authentication, so the key is part of the minimum viable create payload. Custom configurations and edit mode are exempt.

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 0b5da51016)

Solutions

  1. Paste the API key issued by the preset's provider (e.g. from its dashboard) into the API key field and resubmit.
  2. If you do not have a key yet, switch to the 'custom' configuration instead of a preset — the requirement only applies to selectedPreset.
  3. Check that switching presets did not wipe an already-entered key before submitting.

Example fix

// before
const selectedPreset = PRESETS[0];
const apiKey = ""; // forgot to fill
submit(identity); // throws 'Enter the API key for this preset'

// after
const apiKey = "sk-..."; // real key from the provider dashboard
submit(identity);
Defensive patterns

Strategy: validation

Validate before calling

const needsKey = !isEdit && selectedPreset !== null;
if (needsKey && apiKey.length === 0) highlight("#pi-api-key", "API key required for presets");

Try / catch

catch (e) {
  if (e instanceof PiFormValidationError) { setFormError(e.message); document.querySelector("#pi-api-key")?.focus(); return; }
  throw e;
}

Prevention

When it happens

Trigger: Selecting any bundled preset, leaving the API key field empty, and clicking save; also fires when the key state was reset after a preset switch but the field was not refilled.

Common situations: User intends to add the key later and tries to save a placeholder provider; a preset switch handler clears apiKey but the user does not notice the now-empty field; clipboard paste silently failed.

Related errors


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