AlistGo/alist · error

api_key is empty

Error message

api_key is empty

What it means

Thrown by Yunpan360 Init() when auth_type is set to "api_key" but the api_key field is blank after trimming. The driver immediately needs the API key to call openUserInfo (open API auth + validation), so an empty key cannot proceed. Configuration is trimmed first, so a whitespace-only value also triggers this.

Source

Thrown at drivers/yunpan360/driver.go:73

		d.SubChannel = defaultSubChannel
	}
	d.EcsEnv = strings.ToLower(strings.TrimSpace(d.EcsEnv))
	if d.EcsEnv == "" {
		d.EcsEnv = openEnvProd
	}
	d.Cookie = strings.TrimSpace(d.Cookie)
	d.APIKey = strings.TrimSpace(d.APIKey)
	d.OwnerQID = strings.TrimSpace(d.OwnerQID)
	d.DownloadToken = strings.TrimSpace(d.DownloadToken)
	d.cachedOpenAuth = nil
	d.openAuthExpire = time.Time{}
	d.cachedCookieSession = nil
	d.cookieSessionExpire = time.Time{}

	switch d.authMode() {
	case authTypeAPIKey:
		if d.APIKey == "" {
			return errors.New("api_key is empty")
		}
		_, err := d.openUserInfo(ctx)
		return err
	case authTypeCookie:
		if d.Cookie == "" {
			return errors.New("cookie is empty")
		}
		// Web download URLs require browser-session headers; force local proxying
		// so AList can forward Referer/Origin instead of exposing a bare 302 URL.
		d.WebProxy = true
		_, err := d.listCookiePage(ctx, d.RootFolderPath, 0, 1)
		return err
	default:
		return errors.New("invalid auth_type")
	}
}

func (d *Yunpan360) Drop(ctx context.Context) error {

View on GitHub (pinned to 843d9dc814)

Solutions

  1. Set the api_key field in the yunpan360 storage config to the key obtained from 360's open API
  2. If you meant to use browser-cookie auth, set auth_type back to "cookie" and fill cookie instead
  3. Re-save the storage config after editing so Init() runs again
Defensive patterns

Strategy: validation

Validate before calling

if cfg.AuthType == "api_key" && strings.TrimSpace(cfg.APIKey) == "" {
    return errors.New("auth_type=api_key requires a non-empty api_key")
}

Prevention

When it happens

Trigger: Storage config with auth_type="api_key" and an empty/whitespace api_key field; the key was cleared during a config edit or never filled when switching from cookie to api_key mode.

Common situations: Switching auth modes in the AList admin UI without filling the new credential; automation/terraform that templates the driver config and omits api_key; trailing spaces that were assumed to be the problem but the field is genuinely empty.

Related errors


AI-assisted analysis of AlistGo/alist@843d9dc814 (2026-08-15). Data as JSON: /api/errors/99a1a361456c7757. Report an issue: GitHub.