openrouter_client.py 654 B

12345678910111213141516171819
  1. """OpenRouter API key probe shared by Hermes tools."""
  2. import os
  3. def check_api_key() -> bool:
  4. """Return True if OPENROUTER_API_KEY is present.
  5. Scope-aware: an installed profile secret scope is authoritative under
  6. multiplex; unscoped CLI probes fall back to the plain env read. Any other
  7. scope failure propagates -- a failed scoped read must never silently
  8. borrow another profile's key from ``os.environ``.
  9. """
  10. from agent.secret_scope import UnscopedSecretError, get_secret
  11. try:
  12. return bool(get_secret("OPENROUTER_API_KEY"))
  13. except UnscopedSecretError:
  14. return bool(os.getenv("OPENROUTER_API_KEY"))