{"record":{"id":"8575da77b0015e90","repo":"LykosAI/StabilityMatrix","slug":"api-key-is-required","errorCode":null,"errorMessage":"API key is required","messagePattern":"API key is required","errorType":"validation","errorClass":"ValidationException","httpStatus":null,"severity":"warning","filePath":"StabilityMatrix.Avalonia/ViewModels/Settings/AccountSettingsViewModel.cs","lineNumber":338,"sourceCode":"    }\n\n    [RelayCommand(CanExecute = nameof(IsInitialUpdateFinished))]\n    private async Task ConnectCivit()\n    {\n        if (!await BeforeConnectCheck())\n            return;\n\n        var textFields = new TextBoxField[]\n        {\n            new()\n            {\n                Label = Resources.Label_ApiKey,\n                IsPassword = true, // Added this line\n                Validator = s =>\n                {\n                    if (string.IsNullOrWhiteSpace(s))\n                    {\n                        throw new ValidationException(\"API key is required\");\n                    }\n                },\n            },\n        };\n\n        var dialog = DialogHelper.CreateTextEntryDialog(\n            \"Connect CivitAI Account\",\n            \"\"\"\n            Login to [CivitAI](https://civitai.com/) and head to your [Account](https://civitai.com/user/account) page\n\n            Add a new API key and paste it below\n            \"\"\",\n            \"avares://StabilityMatrix.Avalonia/Assets/guide-civitai-api.webp\",\n            textFields\n        );\n        dialog.PrimaryButtonText = Resources.Action_Connect;\n\n        if (await dialog.ShowAsync() != ContentDialogResult.Primary || textFields[0].Text is not { } apiToken)","sourceCodeStart":320,"sourceCodeEnd":356,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Avalonia/ViewModels/Settings/AccountSettingsViewModel.cs#L320-L356","documentation":"ConnectCivit in AccountSettingsViewModel builds an API-key text-entry dialog with a validator that throws ValidationException('API key is required') when the input is null or whitespace. It prevents starting a Civitai connection with a blank key.","triggerScenarios":"Submitting the 'Connect Civitai' API key dialog (AccountSettingsViewModel.cs:338) with an empty or whitespace-only key.","commonSituations":"Clicking Connect before pasting the key; pasting into the wrong field; clipboard containing only whitespace; password-masked field hiding that nothing was entered.","solutions":["Paste your Civitai API key (from civitai.com account settings) into the field before confirming.","Trim surrounding whitespace from the pasted key.","Regenerate the API key on the Civitai website if the old one was revoked."],"exampleFix":"// before\nValidator = s => { if (string.IsNullOrWhiteSpace(s)) throw new ValidationException(\"API key is required\"); };\n// after\nValidator = s => { if (string.IsNullOrWhiteSpace(s)) throw new ValidationException(\"API key is required\");\n    if (s.Trim().Length < 8) throw new ValidationException(\"API key looks too short\"); };","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(apiKey)) {\n    // prompt user first; do not open Connect dialog\n    return;\n}","typeGuard":"bool HasApiKey(string? s) => !string.IsNullOrWhiteSpace(s);","tryCatchPattern":"try { await viewModel.ConnectCivit(); }\ncatch (ValidationException ex) { ShowStatus(ex.Message); }","preventionTips":["Copy the Civitai API key from account settings before opening the dialog.","Trim pasted keys; masked fields can hide trailing spaces.","Verify the key is still valid/regenerate if the site revoked it."],"tags":["validation","api-key","authentication"],"backgroundTag":"missing-api-key","analyzedSha":"af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002","analyzedAt":"2026-09-12T19:02:43.389Z","contentChangedAt":"2026-09-12T19:02:43.389Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}