{"record":{"id":"988f1826b5f12003","repo":"farion1231/cc-switch","slug":"enter-the-api-key-for-this-preset","errorCode":null,"errorMessage":"Enter the API key for this preset","messagePattern":"Enter the API key for this preset","errorType":"validation","errorClass":"PiFormValidationError","httpStatus":null,"severity":"warning","filePath":"src/components/providers/forms/PiProviderForm.tsx","lineNumber":1091,"sourceCode":"          \"#pi-settings-config\",\n        );\n      }\n      const trimmedName = identity.name.trim();\n      const trimmedKey = providerKey.trim();\n      if (!trimmedName) {\n        throw new PiFormValidationError(\n          t(\"pi.form.nameRequired\"),\n          'input[name=\"name\"]',\n        );\n      }\n      if (!isEdit && !trimmedKey) {\n        throw new PiFormValidationError(\n          t(\"pi.form.providerKeyRequired\"),\n          \"#pi-provider-key\",\n        );\n      }\n      if (!isEdit && selectedPreset && apiKey.length === 0) {\n        throw new PiFormValidationError(\n          t(\"pi.form.credentialRequired\"),\n          \"#pi-api-key\",\n        );\n      }\n      if (!isEdit && models.length === 0) {\n        throw new PiFormValidationError(\n          t(\"pi.form.modelRequired\"),\n          \"#pi-add-model\",\n          true,\n        );\n      }\n\n      const headers = normalizeRequestHeaders(providerHeaders);\n      const seen = new Set<string>();\n      const normalizedModels = models.map((model, index) => {\n        // Pi treats model IDs as opaque strings. Trimming would rename an\n        // imported model.\n        const id = model.id;","sourceCodeStart":1073,"sourceCodeEnd":1109,"githubUrl":"https://github.com/farion1231/cc-switch/blob/0b5da510168914b251481654a568c3ffacd62cf4/src/components/providers/forms/PiProviderForm.tsx#L1073-L1109","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Paste the API key issued by the preset's provider (e.g. from its dashboard) into the API key field and resubmit.","If you do not have a key yet, switch to the 'custom' configuration instead of a preset — the requirement only applies to selectedPreset.","Check that switching presets did not wipe an already-entered key before submitting."],"exampleFix":"// before\nconst selectedPreset = PRESETS[0];\nconst apiKey = \"\"; // forgot to fill\nsubmit(identity); // throws 'Enter the API key for this preset'\n\n// after\nconst apiKey = \"sk-...\"; // real key from the provider dashboard\nsubmit(identity);","handlingStrategy":"validation","validationCode":"const needsKey = !isEdit && selectedPreset !== null;\nif (needsKey && apiKey.length === 0) highlight(\"#pi-api-key\", \"API key required for presets\");","typeGuard":null,"tryCatchPattern":"catch (e) {\n  if (e instanceof PiFormValidationError) { setFormError(e.message); document.querySelector(\"#pi-api-key\")?.focus(); return; }\n  throw e;\n}","preventionTips":["Disable preset-based submit until the key field is non-empty.","When switching presets, preserve or deliberately clear apiKey and re-notify the user."],"tags":["pi","form-validation","api-key","preset"],"backgroundTag":"missing-api-credentials","analyzedSha":"0b5da510168914b251481654a568c3ffacd62cf4","analyzedAt":"2026-08-20T14:29:00.113Z","contentChangedAt":"2026-08-20T14:29:00.113Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}