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.

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.10.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.1.tar.gz (10.3 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.1-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file keel_llm_adapter_google-0.1.1.tar.gz.

File metadata

  • Download URL: keel_llm_adapter_google-0.1.1.tar.gz
  • Upload date:
  • Size: 10.3 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.1.tar.gz
Algorithm Hash digest
SHA256 85000cb697e99c282030d7e5fc93192b0a92f75bced56332fa6ab0c8dd884cfc
MD5 11dcc4215dd39ca795f4de97d5583733
BLAKE2b-256 0a3487ee0cf4b517c364035f960c1dd3fd35abaa45e6d8339c5d86b9c0673d84

See more details on using hashes here.

Provenance

The following attestation bundles were made for keel_llm_adapter_google-0.1.1.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.1-py3-none-any.whl.

File metadata

File hashes

Hashes for keel_llm_adapter_google-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 35985cd1124008cd95fc545e8c5345d61fc5d76f95f9093938d11b7813b9883f
MD5 1751e0e0878f8c49557628fe71479606
BLAKE2b-256 f2b9ff94e94f5eb3090068ccdd6633a609ab73bc600e43e571b7406c6910dcd5

See more details on using hashes here.

Provenance

The following attestation bundles were made for keel_llm_adapter_google-0.1.1-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