Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions hermes_cli/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,19 @@ def _resolve_api_key_provider_secret(
key = str(key).strip()
if has_usable_secret(key):
return key, f"credential_pool:{provider_id}"
# All entries exhausted — return first entry's key anyway so the
# upstream API returns a meaningful error (429/402) instead of a
# misleading 401 caused by sending an empty api_key.
for e in pool._entries:
_key = getattr(e, "access_token", "") or getattr(e, "runtime_api_key", "")
_key = str(_key).strip()
if has_usable_secret(_key):
logger.warning(
"credential pool: all %s entries exhausted; "
"using %s anyway for clearer upstream error",
provider_id, e.label or e.id[:8],
)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This raw loop also considers STATUS_DEAD entries. CredentialPool._available_entries() deliberately excludes DEAD credentials permanently (agent/credential_pool.py:1467-1496), so restrict this fallback to entries explicitly marked exhausted; otherwise a revoked/invalidated credential can be sent again.

return _key, f"credential_pool:{provider_id}"
except Exception:
pass

Expand Down
Loading