Reference keel-llm-protocol adapter for Google's native Gemini generateContent API.
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file keel_llm_adapter_google-0.1.2.tar.gz.
File metadata
- Download URL: keel_llm_adapter_google-0.1.2.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e088f08a75380048653c47a24723b1d2387388feb239a9575ad737659c654048
|
|
| MD5 |
1e07e16c1fe9f46cefcfe89d37bbbac0
|
|
| BLAKE2b-256 |
8d772b7e6867c18db4bb668691e61d422ea294ba20545448d7cecb585f897989
|
Provenance
The following attestation bundles were made for keel_llm_adapter_google-0.1.2.tar.gz:
Publisher:
publish-py.yml on keelplatform/keel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
keel_llm_adapter_google-0.1.2.tar.gz -
Subject digest:
e088f08a75380048653c47a24723b1d2387388feb239a9575ad737659c654048 - Sigstore transparency entry: 1610078465
- Sigstore integration time:
-
Permalink:
keelplatform/keel@2d54c903ad991fb68652520570a6571c69c477fb -
Branch / Tag:
refs/tags/py-llm-adapter-google-v0.1.2 - Owner: https://github.com/keelplatform
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-py.yml@2d54c903ad991fb68652520570a6571c69c477fb -
Trigger Event:
push
-
Statement type:
File details
Details for the file keel_llm_adapter_google-0.1.2-py3-none-any.whl.
File metadata
- Download URL: keel_llm_adapter_google-0.1.2-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c400ea7b4dc239dccf9ed6964758ada3175189b1d8512ca084bcb65ddbb5c734
|
|
| MD5 |
05c48a6cfad44475e1bd7246ede75cc7
|
|
| BLAKE2b-256 |
a843676e193924184204767c9ad7b1d21e8520a11d6ef69ef4f7f27dd2cde77a
|
Provenance
The following attestation bundles were made for keel_llm_adapter_google-0.1.2-py3-none-any.whl:
Publisher:
publish-py.yml on keelplatform/keel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
keel_llm_adapter_google-0.1.2-py3-none-any.whl -
Subject digest:
c400ea7b4dc239dccf9ed6964758ada3175189b1d8512ca084bcb65ddbb5c734 - Sigstore transparency entry: 1610078647
- Sigstore integration time:
-
Permalink:
keelplatform/keel@2d54c903ad991fb68652520570a6571c69c477fb -
Branch / Tag:
refs/tags/py-llm-adapter-google-v0.1.2 - Owner: https://github.com/keelplatform
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-py.yml@2d54c903ad991fb68652520570a6571c69c477fb -
Trigger Event:
push
-
Statement type: