SigNoz/signoz · error

api_key_invalid_input

api_key_invalid_input

Error message

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

What it means

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.

Source

Thrown at pkg/types/serviceaccounttypes/factor_api_key.go:23

	"regexp"
	"time"

	"github.com/SigNoz/signoz/pkg/errors"
	"github.com/SigNoz/signoz/pkg/types"
	"github.com/SigNoz/signoz/pkg/valuer"
	"github.com/uptrace/bun"
)

var (
	factorAPIKeyNameRegex = regexp.MustCompile("^[a-z][a-z0-9-]{0,79}$")
)

var (
	ErrCodeAPIKeyInvalidInput  = errors.MustNewCode("api_key_invalid_input")
	ErrCodeAPIKeyAlreadyExists = errors.MustNewCode("api_key_already_exists")
	ErrCodeAPIKeytNotFound     = errors.MustNewCode("api_key_not_found")
	ErrCodeAPIKeyExpired       = errors.MustNewCode("api_key_expired")
	errInvalidAPIKeyName       = 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")
)

type FactorAPIKey struct {
	bun.BaseModel `bun:"table:factor_api_key,alias:factor_api_key"`

	types.Identifiable
	types.TimeAuditable
	Name             string      `bun:"name"`
	Key              string      `bun:"key"`
	ExpiresAt        uint64      `bun:"expires_at"`
	LastObservedAt   time.Time   `bun:"last_observed_at"`
	ServiceAccountID valuer.UUID `bun:"service_account_id"`
}

type GettableFactorAPIKeyWithKey struct {
	types.Identifiable
	Key string `json:"key" required:"true"`
}

View on GitHub (pinned to 5069bf80b0)

Solutions

  1. Rename to lowercase-hyphen form, e.g. my-api-key
  2. Strip/replace underscores and uppercase letters before submission
  3. Truncate to 80 characters
  4. Add a client-side regex check: ^[a-z][a-z0-9-]{0,79}$

Example fix

// before
{"name":"Prod Key #1"}
// after
{"name":"prod-key-1"}
Defensive patterns

Strategy: validation

Validate before calling

const NAME_RE = /^[a-z][a-z0-9-]{0,79}$/;
if (!NAME_RE.test(keyName)) throw new Error('invalid API key name');

Type guard

function isValidAPIKeyName(n: string): boolean { return /^[a-z][a-z0-9-]{0,79}$/.test(n); }

Prevention

When it happens

Trigger: Creating an API key named 'MyKey', 'key_1', '2key', '-key', empty, or longer than 80 characters.

Common situations: Using human display names or emails as key names; underscores carried over from other systems; automated generators producing uppercase/underscored names.

Related errors


AI-assisted analysis of SigNoz/signoz@5069bf80b0 (2026-08-28). Data as JSON: /api/errors/ba6ed90b9bb56b3f. Report an issue: GitHub.