{"record":{"id":"ba6ed90b9bb56b3f","repo":"SigNoz/signoz","slug":"api-key-invalid-input","errorCode":"api_key_invalid_input","errorMessage":"name must start with a lowercase letter (a-z), contain only lowercase letters, numbers (0-9), and hyphens (-), and be at most 80 characters long","messagePattern":"name must start with a lowercase letter \\(a-z\\), contain only lowercase letters, numbers \\(0-9\\), and hyphens \\(-\\), and be at most 80 characters long","errorType":"validation","errorClass":null,"httpStatus":400,"severity":"error","filePath":"pkg/types/serviceaccounttypes/factor_api_key.go","lineNumber":23,"sourceCode":"\t\"regexp\"\n\t\"time\"\n\n\t\"github.com/SigNoz/signoz/pkg/errors\"\n\t\"github.com/SigNoz/signoz/pkg/types\"\n\t\"github.com/SigNoz/signoz/pkg/valuer\"\n\t\"github.com/uptrace/bun\"\n)\n\nvar (\n\tfactorAPIKeyNameRegex = regexp.MustCompile(\"^[a-z][a-z0-9-]{0,79}$\")\n)\n\nvar (\n\tErrCodeAPIKeyInvalidInput  = errors.MustNewCode(\"api_key_invalid_input\")\n\tErrCodeAPIKeyAlreadyExists = errors.MustNewCode(\"api_key_already_exists\")\n\tErrCodeAPIKeytNotFound     = errors.MustNewCode(\"api_key_not_found\")\n\tErrCodeAPIKeyExpired       = errors.MustNewCode(\"api_key_expired\")\n\terrInvalidAPIKeyName       = errors.New(errors.TypeInvalidInput, ErrCodeAPIKeyInvalidInput, \"name must start with a lowercase letter (a-z), contain only lowercase letters, numbers (0-9), and hyphens (-), and be at most 80 characters long\")\n)\n\ntype FactorAPIKey struct {\n\tbun.BaseModel `bun:\"table:factor_api_key,alias:factor_api_key\"`\n\n\ttypes.Identifiable\n\ttypes.TimeAuditable\n\tName             string      `bun:\"name\"`\n\tKey              string      `bun:\"key\"`\n\tExpiresAt        uint64      `bun:\"expires_at\"`\n\tLastObservedAt   time.Time   `bun:\"last_observed_at\"`\n\tServiceAccountID valuer.UUID `bun:\"service_account_id\"`\n}\n\ntype GettableFactorAPIKeyWithKey struct {\n\ttypes.Identifiable\n\tKey string `json:\"key\" required:\"true\"`\n}","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/types/serviceaccounttypes/factor_api_key.go#L5-L41","documentation":"errInvalidAPIKeyName is a package-level sentinel enforcing API key naming rules: must start with a lowercase letter, contain only a-z, 0-9, and hyphens, and be at most 80 chars. PostableFactorAPIKey.UnmarshalJSON returns it when the name fails the regex.","triggerScenarios":"Creating an API key named 'MyKey', 'key_1', '2key', '-key', empty, or longer than 80 characters.","commonSituations":"Using human display names or emails as key names; underscores carried over from other systems; automated generators producing uppercase/underscored names.","solutions":["Rename to lowercase-hyphen form, e.g. my-api-key","Strip/replace underscores and uppercase letters before submission","Truncate to 80 characters","Add a client-side regex check: ^[a-z][a-z0-9-]{0,79}$"],"exampleFix":"// before\n{\"name\":\"Prod Key #1\"}\n// after\n{\"name\":\"prod-key-1\"}\n","handlingStrategy":"validation","validationCode":"const NAME_RE = /^[a-z][a-z0-9-]{0,79}$/;\nif (!NAME_RE.test(keyName)) throw new Error('invalid API key name');","typeGuard":"function isValidAPIKeyName(n: string): boolean { return /^[a-z][a-z0-9-]{0,79}$/.test(n); }","tryCatchPattern":null,"preventionTips":["slugify() names before submission","Enforce length limit 80 in the UI"],"tags":["api-key","naming","validation","go"],"backgroundTag":"identifier-naming-validation","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}