router-for-me/CLIProxyAPI · error

auth not found for auth_index %s

Error message

auth not found for auth_index %s

What it means

Thrown by Host.authByIndex when the auth manager is available but no registered auth entry has an Index equal to the requested auth_index after EnsureIndex() normalization. It is a straightforward lookup miss: the credential identified by that index is not currently loaded.

Source

Thrown at internal/pluginhost/auth_callbacks.go:233

func (h *Host) authByIndex(authIndex string) (*coreauth.Auth, error) {
	authIndex = strings.TrimSpace(authIndex)
	if authIndex == "" {
		return nil, fmt.Errorf("auth_index is required")
	}
	manager := h.currentAuthManager()
	if manager == nil {
		return nil, fmt.Errorf("core auth manager unavailable")
	}
	for _, auth := range manager.List() {
		if auth == nil {
			continue
		}
		auth.EnsureIndex()
		if auth.Index == authIndex {
			return auth, nil
		}
	}
	return nil, fmt.Errorf("auth not found for auth_index %s", authIndex)
}

func (h *Host) authPhysicalJSONByIndex(authIndex string) (*coreauth.Auth, []byte, error) {
	auth, errGet := h.authByIndex(authIndex)
	if errGet != nil {
		return nil, nil, errGet
	}
	path := strings.TrimSpace(authAttribute(auth, "path"))
	if path == "" {
		return nil, nil, fmt.Errorf("auth file path not found for auth_index %s", authIndex)
	}
	data, errRead := os.ReadFile(path)
	if errRead != nil {
		if os.IsNotExist(errRead) {
			return nil, nil, fmt.Errorf("auth file not found for auth_index %s", authIndex)
		}
		return nil, nil, fmt.Errorf("failed to read auth file: %w", errRead)
	}

View on GitHub (pinned to 78f0c4079e)

Solutions

  1. Re-list auths via the host auth-list callback and use a currently valid index
  2. Verify the expected auth file still exists in the configured auths directory and was reloaded
  3. Check that the auth_index string is passed verbatim (not trimmed of meaningful characters or empty)
Defensive patterns

Strategy: validation

Validate before calling

// refresh the index before use:
valid := false
for _, a := range host.CurrentAuthManager().List() {
    a.EnsureIndex()
    if a.Index == wantIndex { valid = true; break }
}
if !valid { /* re-list or re-acquire index */ }

Try / catch

if err != nil && strings.Contains(err.Error(), "auth not found for auth_index") {
    // re-enumerate auths and retry once with a fresh index
}

Prevention

When it happens

Trigger: Passing an auth_index that was never issued; using an index from a previous process run after auth files were deleted or reloaded with different index assignments; a stale index cached by a plugin while the auth directory changed underneath it.

Common situations: Auth file under auths/ was removed manually or via management API after the plugin captured the index; index is derived per-session and the process restarted; typo or truncated index string in the plugin request.

Related errors


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