router-for-me/CLIProxyAPI · error

invalid auth weight: %w

Error message

invalid auth weight: %w

What it means

Wrapped error from coreauth.ValidateAuthWeight inside Host.buildAuthFromFileData. Auth metadata may carry a weight field controlling round-robin distribution; a weight that fails validation (wrong type, out of allowed range, negative) aborts the build before the record is used.

Source

Thrown at internal/pluginhost/auth_callbacks.go:355

		Status:   coreauth.StatusActive,
		Attributes: map[string]string{
			"path":   path,
			"source": path,
		},
		Metadata:  metadata,
		CreatedAt: time.Now().UTC(),
		UpdatedAt: time.Now().UTC(),
	}
	if manager := h.currentAuthManager(); manager != nil {
		if existing, ok := manager.GetByID(authID); ok {
			auth.CreatedAt = existing.CreatedAt
			auth.LastRefreshedAt = existing.LastRefreshedAt
			auth.NextRetryAfter = existing.NextRetryAfter
			auth.Runtime = existing.Runtime
		}
	}
	if errWeight := coreauth.ValidateAuthWeight(auth); errWeight != nil {
		return nil, fmt.Errorf("invalid auth weight: %w", errWeight)
	}
	coreauth.ApplyCustomHeadersFromMetadata(auth)
	return auth, nil
}

func (h *Host) upsertAuthRecord(ctx context.Context, auth *coreauth.Auth) error {
	manager := h.currentAuthManager()
	if manager == nil || auth == nil {
		return nil
	}
	if existing, ok := manager.GetByID(auth.ID); ok {
		auth.CreatedAt = existing.CreatedAt
		_, errUpdate := manager.Update(ctx, auth)
		return errUpdate
	}
	_, errRegister := manager.Register(ctx, auth)
	return errRegister
}

View on GitHub (pinned to 78f0c4079e)

Solutions

  1. Inspect the wrapped message for the exact weight rule violated
  2. Fix or remove the weight field in the auth file (fall back to the default) and retry
  3. After upgrading, re-validate existing auth files against the new weight constraints

Example fix

// before
{"type": "gemini", "weight": "high"}

// after
{"type": "gemini", "weight": 3}
Defensive patterns

Strategy: validation

Validate before calling

// before saving, mirror the host check:
if w, ok := metadata["weight"]; ok {
    if _, ok := w.(float64); !ok {
        // remove or fix the weight field before saving
    }
}

Try / catch

if err != nil && strings.Contains(err.Error(), "invalid auth weight") {
    // strip weight from the file to fall back to default and retry
}

Prevention

When it happens

Trigger: Auth file or plugin-supplied AuthData contains an invalid 'weight' value — e.g. a string, zero/negative number, or a value beyond the accepted maximum defined by coreauth.

Common situations: Hand-edited auth file adding a weight key with a bad format; plugin emitting weight as string; older file written before weight rules tightened by a version upgrade.

Related errors


AI-assisted analysis of router-for-me/CLIProxyAPI@78f0c4079e (2026-08-15). Data as JSON: /api/errors/f077311087aa366d. Report an issue: GitHub.