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
- Inspect the wrapped message for the exact weight rule violated
- Fix or remove the weight field in the auth file (fall back to the default) and retry
- 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
- Keep weight as a number within the documented range or omit it
- Re-validate auth files after upgrading the proxy
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
- invalid auth file name
- auth file name must end with .json
- json is required
- invalid auth json: %w
- auth path is empty
AI-assisted analysis of router-for-me/CLIProxyAPI@78f0c4079e (2026-08-15).
Data as JSON: /api/errors/f077311087aa366d.
Report an issue: GitHub.