Skip to main content

lmux-google

Google (Gemini) provider for lmux. Talks to the Google Gemini REST API directly over httpx, using google-auth to resolve Vertex AI credentials. Serves Google's models through either backend:

  • Vertex AI (default) — authenticated with Google Cloud credentials
  • Gemini Developer API (AI Studio) — authenticated with an API key (vertexai=False)

Supports chat completions, streaming, and embeddings for Google-published models: Gemini and the Gemini/text embedding models.

Part of the lmux ecosystem: standardized interface, cost tracking on every response, and registry-based routing across providers.

Auth

Three authentication methods:

Application Default Credentials (default)

Uses google.auth.default(), which works with GOOGLE_APPLICATION_CREDENTIALS, gcloud CLI, or instance metadata.

from lmux_google import GoogleProvider

provider = GoogleProvider(project="my-project", location="us-central1")

Service Account

from lmux_google import GoogleServiceAccountAuthProvider

provider = GoogleProvider(
    project="my-project",
    location="us-central1",
    auth=GoogleServiceAccountAuthProvider(service_account_file="/path/to/key.json"),
)

API Key

Set GOOGLE_API_KEY in your environment:

from lmux_google import GoogleAPIKeyAuthProvider

provider = GoogleProvider(auth=GoogleAPIKeyAuthProvider(), vertexai=False)

Usage

Chat

from lmux import UserMessage

response = provider.chat("gemini-2.5-pro", [UserMessage(content="Hello")])
print(response.content)
print(response.cost)

Streaming

for chunk in provider.chat_stream("gemini-2.5-pro", [UserMessage(content="Hello")]):
    if chunk.delta:
        print(chunk.delta, end="")

Tool continuations

Gemini 3 models require their thought signatures on follow-up tool calls. lmux-google captures the native assistant parts in response.continuation; use to_assistant_message() to preserve them:

response = provider.chat(model, messages, tools=tools)
messages.append(response.to_assistant_message())
messages.append(ToolMessage(content=tool_result, tool_call_id=response.tool_calls[0].id))

The provider replays a matching Google continuation exactly. If no matching continuation is present, it builds the assistant turn from normalized content and tool calls as before.

Embeddings

response = provider.embed("text-embedding-005", "Hello")
print(response.embeddings)

Async

All methods have async variants: achat, achat_stream, aembed.

Registry

Use with the lmux registry to route across multiple providers:

from lmux import Registry

registry = Registry()
registry.register("google", provider)
response = registry.chat("google/gemini-2.5-pro", messages)

Provider Params

from lmux_google import GoogleParams

response = provider.chat(
    "gemini-2.5-pro",
    messages,
    provider_params=GoogleParams(thinking_config={"thinking_budget": 1024}),
)
Parameter Type Description
safety_settings list[SafetySetting] Content safety thresholds
presence_penalty float Presence penalty
frequency_penalty float Frequency penalty
seed int Deterministic sampling seed
labels dict[str, str] Request labels
thinking_config dict Thinking/reasoning configuration
pricing_as_of datetime.date Override the date used for dated pricing (e.g. a model's introductory-rate window); defaults to the current date

Constructor Options

GoogleProvider(
    auth=...,       # AuthProvider, default: GoogleADCAuthProvider()
    project=...,    # GCP project ID
    location=...,   # GCP region
    vertexai=...,   # Use Vertex AI (default: True) vs. AI Studio
    timeout=...,    # request timeout in seconds
    max_retries=..., # retry count for transient failures
    default_headers=...,  # Optional headers included with every request
    transport=...,        # Optional httpx.BaseTransport for the sync client (proxies, testing)
    async_transport=...,  # Optional httpx.AsyncBaseTransport for the async client
)

default_headers is useful for gateway authentication, tracing, and routing. Google-managed authentication, quota-project, and content-type headers take precedence over caller values, case-insensitively.

Pricing

Rates are Vertex global-endpoint list prices. Setting location to anything other than global puts the request on a non-global Vertex endpoint, which bills a 10% premium on the models Vertex publishes a non-global rate for; the provider applies that automatically via VERTEX_NON_GLOBAL_MULTIPLIER. Every other model bills list price on both endpoints, and the Gemini Developer API (vertexai=False) has no endpoint premium at all.

Models with time-boxed introductory rates carry dated schedules, so cost reflects the rate in effect on the request date. Pass GoogleParams(pricing_as_of=...) to price against a different date. The endpoint premium is dated too — it starts at VERTEX_NON_GLOBAL_PREMIUM_START (2026-07-01), so costs replayed against an earlier date take no multiplier.

Download files

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

Source Distribution

lmux_google-0.12.0.tar.gz (22.4 kB view details)

Uploaded Source

Built Distribution

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

lmux_google-0.12.0-py3-none-any.whl (26.4 kB view details)

Uploaded Python 3

File details

Details for the file lmux_google-0.12.0.tar.gz.

File metadata

  • Download URL: lmux_google-0.12.0.tar.gz
  • Upload date:
  • Size: 22.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for lmux_google-0.12.0.tar.gz
Algorithm Hash digest
SHA256 db0c53c4e1bc564f87148658548805024a15579eb8193b64d211b313815441cd
MD5 abe740a11a0a89b1774dddc38d9debc3
BLAKE2b-256 aaf0af562e08e8e3a2615732cdbcdbd4998575edd0f2e32d2705a2a6b19d7161

See more details on using hashes here.

Provenance

The following attestation bundles were made for lmux_google-0.12.0.tar.gz:

Publisher: publish.yml on cluebbehusen/lmux

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

File details

Details for the file lmux_google-0.12.0-py3-none-any.whl.

File metadata

  • Download URL: lmux_google-0.12.0-py3-none-any.whl
  • Upload date:
  • Size: 26.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for lmux_google-0.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 21fd0bed62e43b05f3f9d1e8ded757843eff760efad327495aa3cf232719f870
MD5 7b7ba308749f1781c73e759f72ec1b02
BLAKE2b-256 a89f2da5989b6a61805a7032cf092dfa94abbb2c89d46ec5988c03badd93151c

See more details on using hashes here.

Provenance

The following attestation bundles were made for lmux_google-0.12.0-py3-none-any.whl:

Publisher: publish.yml on cluebbehusen/lmux

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 Sentry Error logging StatusPage Status page