keel-llm-adapter-google
A reference
keel-llm-protocoladapter for Google's native GeminigenerateContentAPI.
The third and most divergent grounding for the protocol standard. Gemini's native wire format differs from both OpenAI and Anthropic — contents/parts, the "model" role, systemInstruction, generationConfig, functionCall parts, finishReason + promptFeedback.blockReason, and the Google error envelope. Every divergence is absorbed in the adapter; the protocol's types are unchanged.
Notably, Gemini supports native structured output, so this adapter's capabilities include json_object and json_schema — the contrast with keel-llm-adapter-anthropic (which declares neither) shows the capability-introspection design doing real work.
Is this for you?
Adopt when — you're consuming via keel-llm-protocol / keel-llm-reliability and want Gemini calls mapped to the typed taxonomy. Especially valuable for Gemini's free-tier ceiling (15 RPM) where RESOURCE_EXHAUSTED → RateLimitError is the high-leverage mapping.
Skip when — you're calling Gemini directly in a simple app — the official google-generativeai SDK has a wider surface; this adapter covers chat / streaming / tools.
Install
pip install keel-llm-adapter-google # pulls in keel-llm-protocol + httpx
Use
from keel_llm_adapter_google import GoogleAdapter
from keel_llm_protocol import user
from keel_llm_protocol.errors import RateLimitError
adapter = GoogleAdapter(model="gemini-2.0-flash", api_key="...", provider="google")
try:
resp = await adapter.generate([user("Explain rate limiting briefly.")])
print(resp.text, resp.usage.total_tokens, resp.finish_reason)
except RateLimitError as e:
# Gemini free tier is 15 RPM — a 429 here means healthy-but-throttled.
# The typed error lets a circuit breaker defer to a rate limiter instead of
# tripping the model's circuit.
await asyncio.sleep(e.retry_after or 5.0)
Same keel-llm-protocol types as every other adapter — code written against the protocol runs unchanged whether it's pointed at Gemini, an OpenAI-compatible endpoint, or Anthropic. Implements ModelAdapter, StreamingModelAdapter, ToolCallingModelAdapter.
How Gemini diverges — and where it's handled
| Gemini divergence | Absorbed by |
|---|---|
contents/parts request shape |
adapter builds parts from Messages |
Assistant role is "model" |
adapter maps assistant → model |
System prompt is systemInstruction |
adapter lifts Message(role="system") |
Params under generationConfig |
adapter wraps temperature/maxOutputTokens/stopSequences |
functionCall.args is a parsed dict |
normalized to ToolCall.arguments (JSON string) |
functionDeclarations + functionCallingConfig {AUTO|ANY|NONE} |
mapped from ToolSpec / tool_choice |
finishReason (STOP/MAX_TOKENS/SAFETY/…) + promptFeedback.blockReason |
mapped to FinishReason; safety/blocks → content_filter; unmapped → unknown |
Google error envelope; RESOURCE_EXHAUSTED/UNAVAILABLE/… |
mapped to the standard error taxonomy |
Native structured output (responseMimeType + responseSchema) |
declared in capabilities; honored flag set |
Status
0.1.2 — 0.x while the API stabilizes through year one (breaking changes possible at minor bumps, documented in the CHANGELOG; pin exact versions).
The Keel toolkit
Composable, vendor-neutral LLM reliability libraries on PyPI:
keel-llm-reliability · keel-llm-protocol · keel-llm-adapter-openai · keel-llm-adapter-anthropic · keel-llm-adapter-google · keel-circuit-breaker
MIT licensed.
Metadata
Release files for keel-llm-adapter-google 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| keel_llm_adapter_google-0.1.2.tar.gz | 10.6 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| keel_llm_adapter_google-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.4 kB
Release files / keel_llm_adapter_google-0.1.2.tar.gz
| Download URL | keel_llm_adapter_google-0.1.2.tar.gz |
|---|---|
| Size | 10.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e088f08a75380048653c47a24723b1d2387388feb239a9575ad737659c654048
|
|
BLAKE2b-256 checksum How to use checksums |
8d772b7e6867c18db4bb668691e61d422ea294ba20545448d7cecb585f897989
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 23, 2026.
Transparency logRelease files / keel_llm_adapter_google-0.1.2-py3-none-any.whl
| Download URL | keel_llm_adapter_google-0.1.2-py3-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c400ea7b4dc239dccf9ed6964758ada3175189b1d8512ca084bcb65ddbb5c734
|
|
BLAKE2b-256 checksum How to use checksums |
a843676e193924184204767c9ad7b1d21e8520a11d6ef69ef4f7f27dd2cde77a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 23, 2026.
Transparency logSecurity for keel-llm-adapter-google 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for keel_llm_adapter_google-0.1.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 23, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.