LykosAI/StabilityMatrix · warning · ValidationException
API key is required
Error message
API key is required
What it means
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.
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.
Example fix
// before
Validator = s => { if (string.IsNullOrWhiteSpace(s)) throw new ValidationException("API key is required"); };
// after
Validator = s => { if (string.IsNullOrWhiteSpace(s)) throw new ValidationException("API key is required");
if (s.Trim().Length < 8) throw new ValidationException("API key looks too short"); }; Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrWhiteSpace(apiKey)) {
// prompt user first; do not open Connect dialog
return;
} Type guard
bool HasApiKey(string? s) => !string.IsNullOrWhiteSpace(s);
Try / catch
try { await viewModel.ConnectCivit(); }
catch (ValidationException ex) { ShowStatus(ex.Message); } Prevention
- 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.
When it happens
Trigger: Submitting the 'Connect Civitai' API key dialog (AccountSettingsViewModel.cs:338) with an empty or whitespace-only key.
Common situations: Clicking Connect before pasting the key; pasting into the wrong field; clipboard containing only whitespace; password-masked field hiding that nothing was entered.
Understand the failure class
Background: "API key is required" / "API key not found" / "No API key was set": the missing-api-key error family across 16 libraries — this error's family across 16 libraries.
Related errors
- Token is required
- Resources.Validation_ApiKeyRequired
- Length cannot be null when latentType is Hunyuan
- Invalid Token
- Lykos account must be connected in to manage OAuth…
AI-assisted analysis of LykosAI/StabilityMatrix@af93d6ef57 (2026-09-12).
Data as JSON: /api/errors/8575da77b0015e90.
Report an issue: GitHub.
Appendix: source
Thrown at StabilityMatrix.Avalonia/ViewModels/Settings/AccountSettingsViewModel.cs:338
}
[RelayCommand(CanExecute = nameof(IsInitialUpdateFinished))]
private async Task ConnectCivit()
{
if (!await BeforeConnectCheck())
return;
var textFields = new TextBoxField[]
{
new()
{
Label = Resources.Label_ApiKey,
IsPassword = true, // Added this line
Validator = s =>
{
if (string.IsNullOrWhiteSpace(s))
{
throw new ValidationException("API key is required");
}
},
},
};
var dialog = DialogHelper.CreateTextEntryDialog(
"Connect CivitAI Account",
"""
Login to [CivitAI](https://civitai.com/) and head to your [Account](https://civitai.com/user/account) page
Add a new API key and paste it below
""",
"avares://StabilityMatrix.Avalonia/Assets/guide-civitai-api.webp",
textFields
);
dialog.PrimaryButtonText = Resources.Action_Connect;
if (await dialog.ShowAsync() != ContentDialogResult.Primary || textFields[0].Text is not { } apiToken)View on GitHub (pinned to af93d6ef57)