Wei-Shaw/sub2api · error

priority must be >= 0

Error message

priority must be >= 0

What it means

Thrown by the admin account import validator (validateAccountImportItem) when an imported account item has a Priority field below zero. The check runs after account-type and rate_multiplier/concurrency checks, guarding numeric sanity before accounts are persisted. It is a pure payload-validation error, not a system failure.

Source

Thrown at backend/internal/handler/admin/account_data.go:703

	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")
	}
	return nil
}

func defaultProxyName(name string) string {
	if strings.TrimSpace(name) == "" {
		return "imported-proxy"
	}
	return name
}

// enrichCredentialsFromIDToken performs best-effort extraction of user info fields
// (email, plan_type, chatgpt_account_id, etc.) from id_token in credentials.
// Only applies to OpenAI OAuth accounts. Skips expired token errors silently.
// Existing credential values are never overwritten — only missing fields are filled.
func enrichCredentialsFromIDToken(item *DataAccount) {
	if item.Credentials == nil {
		return

View on GitHub (pinned to 073e92d171)

Solutions

  1. Set priority to 0 or a positive integer in the imported item and resubmit the import
  2. Check the preceding validation errors (account type, rate_multiplier, concurrency) in the same payload — they are validated first and may also fire
  3. If importing from CSV/JSON exports, sanitize numeric fields (clamp negatives to 0) before upload

Example fix

// before
{"type": "oauth", "name": "acct-1", "priority": -1}
// after
{"type": "oauth", "name": "acct-1", "priority": 0}
Defensive patterns

Strategy: validation

Validate before calling

// Go: sanitize account import items before submit
for i := range items {
    if items[i].Priority < 0 { items[i].Priority = 0 }
    if items[i].Concurrency < 0 { items[i].Concurrency = 0 }
    if items[i].RateMultiplier != nil && *items[i].RateMultiplier < 0 { items[i].RateMultiplier = nil }
}

Prevention

When it happens

Trigger: POST/PUT to the admin account import endpoint with a JSON item whose priority is negative (e.g. "priority": -1). Also triggered by clients that model priority as a signed value and send -1 to mean 'lowest'.

Common situations: Bulk import scripts generated from spreadsheets containing negative numbers; UIs that allow -1 as a sentinel for 'no priority'; confusion with systems where lower number = higher priority and 0 is reserved.

Related errors


AI-assisted analysis of Wei-Shaw/sub2api@073e92d171 (2026-08-15). Data as JSON: /api/errors/19e05d91152d7201. Report an issue: GitHub.