transport.py 1.5 KB

1234567891011121314151617181920212223242526272829303132
  1. """Solstice inference transport: the native Gemini wire on the per-user-quota methods, with the user's
  2. OAuth access token as a Bearer instead of an API key.
  3. Everything else (request building, tool-call ids, thinking config, streaming, error mapping) is the
  4. native adapter's, so a fix there reaches this provider too.
  5. """
  6. from __future__ import annotations
  7. from typing import Any, Dict
  8. from agent.gemini_native_adapter import GeminiAPIError, GeminiNativeClient, gemini_http_error
  9. from . import INFERENCE_BASE_URL
  10. class SolsticeClient(GeminiNativeClient):
  11. """``GeminiNativeClient`` on ``:generateContentPerUserQuota`` / ``:streamGenerateContentPerUserQuota``."""
  12. GENERATE_METHOD, STREAM_METHOD = "generateContentPerUserQuota", "streamGenerateContentPerUserQuota"
  13. MISSING_KEY_ERROR = "Solstice needs a signed-in account. Run `hermes auth add solstice`."
  14. def __init__(self, *, base_url: Any = None, **kwargs: Any) -> None:
  15. # No base means this endpoint, never the generic Gemini default (a different API surface).
  16. super().__init__(base_url=base_url or INFERENCE_BASE_URL, **kwargs)
  17. def _auth_headers(self) -> dict[str, str]:
  18. return {"Authorization": f"Bearer {self.api_key}"}
  19. def _http_error(self, response: Any, body_text: Any = None) -> GeminiAPIError:
  20. # The API-key remedies (free tier, Standard key, wrong key surface) do not apply to a bearer.
  21. return gemini_http_error(response, body_text=body_text, base_url=self.base_url, key_guidance=False)