farion1231/cc-switch · warning · PiFormValidationError

Add at least one model

Error message

Add at least one model

What it means

PiProviderForm refuses to create a provider with an empty model list: submit() throws pi.form.modelRequired when !isEdit && models.length === 0, focusing #pi-add-model and setting revealAdvanced so the models section (an advanced field) is expanded. Pi routes requests per model id, so a provider without at least one model is unusable.

Source

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

        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;
        if (id.length === 0) {
          throw new PiFormValidationError(
            t("pi.form.modelIdRequired", { index: index + 1 }),
            `#pi-model-id-${model.key}`,
            true,
          );

View on GitHub (pinned to 0b5da51016)

Solutions

  1. Open the models section (it auto-expands via revealAdvanced) and add at least one model with its id.
  2. If you imported a preset that normally seeds models, re-select the preset so model rows are populated, then submit.
  3. For programmatic submissions, ensure the models array passed to the form state contains >= 1 entry.

Example fix

// before
const models: ModelRow[] = []; // no rows added
submit(identity); // throws 'Add at least one model'

// after
const models = [{ key: "m1", id: "gemini-2.5-pro", name: "Gemini 2.5 Pro", /* ... */ }];
submit(identity);
Defensive patterns

Strategy: validation

Validate before calling

const modelsOk = isEdit || models.length > 0;
if (!modelsOk) expandAdvanced("#pi-add-model"); // and show inline hint

Try / catch

catch (e) {
  if (e instanceof PiFormValidationError && e.revealAdvanced) { setAdvancedOpen(true); setFormError(e.message); return; }
  throw e;
}

Prevention

When it happens

Trigger: Submitting the create form without having pressed 'Add model' even once; deleting the last model row (which leaves models as []) and saving.

Common situations: Users fill identity/transport fields and assume models are optional; the models section is collapsed under 'Advanced' and gets overlooked; a removed default model row empties the list.

Related errors


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