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.0 — first release. Pin exact versions while in 0.x. Source: Keel monorepo.

License

MIT — see LICENSE.

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.0.tar.gz (10.1 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.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: keel_llm_adapter_google-0.1.0.tar.gz
  • Upload date:
  • Size: 10.1 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.0.tar.gz
Algorithm Hash digest
SHA256 504c09ca3b79975537481bb60bd11906281bdb315c25b498395198c81d2fee52
MD5 cd8ad129904d6697ec31401d1ccf5dc2
BLAKE2b-256 cdea9140f772ae53b9357eaab42c7a0787d40f0858fada72c6e8ad0ddd397044

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for keel_llm_adapter_google-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 973518429969cebc6cee9476d32961dac6b25730859e93e20d4a14f65efe0db1
MD5 c3b4af402f7f19af4e43dd13729b3403
BLAKE2b-256 7da9aceb04c99930571bb8efc31dca10bdffe320da4775d9e79cd8da015d8062

See more details on using hashes here.

Provenance

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