openrouter_client.py
1 """Shared OpenRouter API client for Hermes tools. 2 3 Provides a single lazy-initialized AsyncOpenAI client that all tool modules 4 can share. Routes through the centralized provider router in 5 agent/auxiliary_client.py so auth, headers, and API format are handled 6 consistently. 7 """ 8 9 import os 10 11 _client = None 12 13 14 def get_async_client(): 15 """Return a shared async OpenAI-compatible client for OpenRouter. 16 17 The client is created lazily on first call and reused thereafter. 18 Uses the centralized provider router for auth and client construction. 19 Raises ValueError if OPENROUTER_API_KEY is not set. 20 """ 21 global _client 22 if _client is None: 23 from agent.auxiliary_client import resolve_provider_client 24 client, _model = resolve_provider_client("openrouter", async_mode=True) 25 if client is None: 26 raise ValueError("OPENROUTER_API_KEY environment variable not set") 27 _client = client 28 return _client 29 30 31 def check_api_key() -> bool: 32 """Check whether the OpenRouter API key is present.""" 33 return bool(os.getenv("OPENROUTER_API_KEY"))