Skip to main content

Reference keel-llm-protocol adapter for Google's native Gemini generateContent API.

Project description

keel-llm-adapter-google

A reference keel-llm-protocol adapter for Google's native Gemini generateContent API.

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_EXHAUSTEDRateLimitError 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 assistantmodel
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.20.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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

keel_llm_adapter_google-0.1.2.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

keel_llm_adapter_google-0.1.2-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

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

Hashes for keel_llm_adapter_google-0.1.2.tar.gz
Algorithm Hash digest
SHA256 e088f08a75380048653c47a24723b1d2387388feb239a9575ad737659c654048
MD5 1e07e16c1fe9f46cefcfe89d37bbbac0
BLAKE2b-256 8d772b7e6867c18db4bb668691e61d422ea294ba20545448d7cecb585f897989

See more details on using hashes here.

Provenance

The following attestation bundles were made for keel_llm_adapter_google-0.1.2.tar.gz:

Publisher: publish-py.yml on keelplatform/keel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file keel_llm_adapter_google-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for keel_llm_adapter_google-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c400ea7b4dc239dccf9ed6964758ada3175189b1d8512ca084bcb65ddbb5c734
MD5 05c48a6cfad44475e1bd7246ede75cc7
BLAKE2b-256 a843676e193924184204767c9ad7b1d21e8520a11d6ef69ef4f7f27dd2cde77a

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page