{"record":{"id":"13dbc55819de5d98","repo":"NousResearch/hermes-agent","slug":"gemini-native-client-requires-an-api-key-but-none","errorCode":null,"errorMessage":"Gemini native client requires an API key, but none was provided. Set GOOGLE_API_KEY or GEMINI_API_KEY in your environment / ~/.hermes/.env (get one at https://aistudio.google.com/app/apikey), or run `hermes setup` to configure the Google provider.","messagePattern":"Gemini native client requires an API key, but none was provided\\. Set GOOGLE_API_KEY or GEMINI_API_KEY in your environment / ~/\\.hermes/\\.env \\(get one at https://aistudio\\.google\\.com/app/apikey\\), or run `hermes setup` to configure the Google provider\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"agent/gemini_native_adapter.py","lineNumber":970,"sourceCode":"    def __init__(self, client: \"AsyncGeminiNativeClient\"):\n        self.completions = _AsyncGeminiChatCompletions(client)\n\n\nclass GeminiNativeClient:\n    \"\"\"Minimal OpenAI-SDK-compatible facade over Gemini's native REST API.\"\"\"\n\n    def __init__(\n        self,\n        *,\n        api_key: str,\n        base_url: Optional[str] = None,\n        default_headers: Optional[Dict[str, str]] = None,\n        timeout: Any = None,\n        http_client: Optional[httpx.Client] = None,\n        **_: Any,\n    ) -> None:\n        if not (api_key or \"\").strip():\n            raise RuntimeError(\n                \"Gemini native client requires an API key, but none was provided. \"\n                \"Set GOOGLE_API_KEY or GEMINI_API_KEY in your environment / ~/.hermes/.env \"\n                \"(get one at https://aistudio.google.com/app/apikey), or run `hermes setup` \"\n                \"to configure the Google provider.\"\n            )\n        self.api_key = api_key\n        normalized_base = (base_url or DEFAULT_GEMINI_BASE_URL).rstrip(\"/\")\n        if normalized_base.endswith(\"/openai\"):\n            normalized_base = normalized_base[: -len(\"/openai\")]\n        self.base_url = normalized_base\n        self._default_headers = dict(default_headers or {})\n        self.chat = _GeminiChatNamespace(self)\n        self.is_closed = False\n        self._http = http_client or httpx.Client(\n            timeout=timeout or httpx.Timeout(connect=15.0, read=600.0, write=30.0, pool=30.0)\n        )\n\n    def close(self) -> None:","sourceCodeStart":952,"sourceCodeEnd":988,"githubUrl":"https://github.com/NousResearch/hermes-agent/blob/c896c09c42910c584c4c7d2325b58c14713ea42c/agent/gemini_native_adapter.py#L952-L988","documentation":"The native Gemini client (GeminiNativeClient in agent/gemini_native_adapter.py) was constructed with an empty or whitespace-only api_key. The client talks to Google's Generative Language API directly, which requires a key on every request, so construction fails fast with instructions on where to get one and how to configure it.","triggerScenarios":"Instantiating the native Gemini adapter with api_key='' or None — i.e. neither GOOGLE_API_KEY nor GEMINI_API_KEY is set in the environment or ~/.hermes/.env when the Google provider resolves to native mode.","commonSituations":"Fresh install without running hermes setup; key present under the wrong variable name; .env not loaded because HERMES_HOME points at a profile that lacks it; key accidentally deleted during config edits.","solutions":["Add GOOGLE_API_KEY (or GEMINI_API_KEY) to ~/.hermes/.env — keys are secrets and belong there, not in config.yaml.","Or run `hermes setup` and configure the Google provider interactively.","Get a key at https://aistudio.google.com/app/apikey if you don't have one.","If using profiles, verify the key exists in the active profile's .env (HERMES_HOME scoped)."],"exampleFix":"# before — no key configured\n# after\necho 'GOOGLE_API_KEY=AIza...' >> ~/.hermes/.env\n# or: hermes setup  → choose Google provider","handlingStrategy":"validation","validationCode":"import os\n\ndef gemini_key_present() -> bool:\n    return bool((os.getenv('GOOGLE_API_KEY') or os.getenv('GEMINI_API_KEY') or '').strip())","typeGuard":null,"tryCatchPattern":"try:\n    client = GeminiNativeClient(api_key=os.getenv('GOOGLE_API_KEY', ''))\nexcept RuntimeError as e:\n    if 'requires an API key' in str(e):\n        # add key to ~/.hermes/.env or run hermes setup; then retry\n        ...","preventionTips":["Store GOOGLE_API_KEY in ~/.hermes/.env (never config.yaml)","Run hermes setup after install to configure providers","With profiles, ensure the active profile's .env has the key"],"tags":["gemini","api-key","config","authentication"],"backgroundTag":null,"analyzedSha":"c896c09c42910c584c4c7d2325b58c14713ea42c","analyzedAt":"2026-08-14T17:18:01.089Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}