Wei-Shaw/sub2api · error
account type is required
Error message
account type is required
What it means
Returned by validateDataAccount (backend/internal/handler/admin/account_data.go:686) when an accounts[] entry has name and platform but an empty type after TrimSpace. Type must then be one of the allowed values (oauth, setup_token, api_key, upstream — anything else yields the separate 'account type is invalid' error).
Source
Thrown at backend/internal/handler/admin/account_data.go:686
}
if item.Status != "" {
normalizedStatus := normalizeProxyStatus(item.Status)
if normalizedStatus != service.StatusActive && normalizedStatus != "inactive" {
return fmt.Errorf("proxy status is invalid: %s", item.Status)
}
}
return nil
}
func validateDataAccount(item DataAccount) error {
if strings.TrimSpace(item.Name) == "" {
return errors.New("account name is required")
}
if strings.TrimSpace(item.Platform) == "" {
return errors.New("account platform is required")
}
if strings.TrimSpace(item.Type) == "" {
return errors.New("account type is required")
}
if len(item.Credentials) == 0 {
return errors.New("account credentials is required")
}
switch item.Type {
case service.AccountTypeOAuth, service.AccountTypeSetupToken, service.AccountTypeAPIKey, service.AccountTypeUpstream:
default:
return fmt.Errorf("account type is invalid: %s", item.Type)
}
if item.RateMultiplier != nil && *item.RateMultiplier < 0 {
return errors.New("rate_multiplier must be >= 0")
}
if item.Concurrency < 0 {
return errors.New("concurrency must be >= 0")
}
if item.Priority < 0 {
return errors.New("priority must be >= 0")
}View on GitHub (pinned to 073e92d171)
Solutions
- Set type to one of the supported values: oauth, setup_token, api_key, or upstream.
- Verify the string exactly matches (lowercase, underscore style).
- If importing a new account kind, upgrade the backend or convert the entry to a supported type.
Example fix
// before
{ "name": "main", "platform": "openai", "credentials": { ... } }
// after
{ "name": "main", "platform": "openai", "type": "oauth", "credentials": { ... } } Defensive patterns
Strategy: type-guard
Validate before calling
const ACCOUNT_TYPES = new Set(['oauth', 'setup_token', 'api_key', 'upstream'])
function hasValidAccountType(entry: Record<string, unknown>): boolean {
return typeof entry.type === 'string' && ACCOUNT_TYPES.has(entry.type)
} Type guard
const ACCOUNT_TYPES = ['oauth', 'setup_token', 'api_key', 'upstream'] as const
function isAccountType(t: unknown): t is (typeof ACCOUNT_TYPES)[number] {
return typeof t === 'string' && (ACCOUNT_TYPES as readonly string[]).includes(t)
} Prevention
- Use the exact lowercase identifiers from service.AccountType* constants.
- Reject unknown types client-side with a dropdown instead of free text.
- When new account kinds appear upstream, confirm this backend version supports them before importing.
When it happens
Trigger: An account object with the type key missing or blank; a numeric/boolean type that fails to deserialize into the string field, leaving it empty.
Common situations: Payloads converted from YAML/CSV where the type column was empty; enum values quoted differently; new account kinds not yet supported by this backend version.
Related errors
- account name is required
- account platform is required
- account credentials is required
- rate_multiplier must be >= 0
- concurrency must be >= 0
AI-assisted analysis of Wei-Shaw/sub2api@073e92d171 (2026-08-15).
Data as JSON: /api/errors/fe5f7814944ba5da.
Report an issue: GitHub.