← All @molecule/* packages · App templates
@molecule/api-ai-googleProvider bond · ai · API (Node) · v1.2.1 · Apache-2.0
Google ai-google provider for molecule.dev.
npm install @molecule/api-ai-googlenpm · Source on GitHub · Implements @molecule/api-ai
@molecule/api-ai-google is a provider bond on the API (Node) side: it implements the ai core interface (@molecule/api-ai) with a concrete vendor or library behind it.
Your code calls the core; you wire this provider once at startup. Swapping vendors later is one line in that wiring, not a rewrite.
Works with: @molecule/api-bond, @molecule/api-i18n, @molecule/api-secrets
Secrets: GOOGLE_AI_API_KEY
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
Google Gemini AI provider for molecule.dev.
provider
npm install @molecule/api-ai-google @molecule/api-ai @molecule/api-bond @molecule/api-i18n @molecule/api-secrets
GoogleConfigConfiguration for the Google Gemini AI provider.
interface GoogleConfig {
/** Called on each rate-limited/overloaded upstream response, before any retry sleep. */
onRateLimit?: AiRateLimitCallback
/** API key. Defaults to the `GOOGLE_AI_API_KEY` env var. */
apiKey?: string
/**
* Base URL override (for proxies / gateways). Defaults to the
* `GOOGLE_AI_BASE_URL` env var, then Google's public Generative Language
* endpoint (`https://generativelanguage.googleapis.com/v1beta`).
*/
baseUrl?: string
/**
* Default model id when not overridden per-request. Defaults to the
* `GOOGLE_AI_MODEL` env var, then `gemini-3.8-flash`.
*/
model?: string
}
ProcessEnvProcess env vars read by the Google Gemini AI bond.
interface ProcessEnv {
/** Google AI (Gemini) API key. */
GOOGLE_AI_API_KEY: string
/** Base URL override (for credential brokers / gateways). */
GOOGLE_AI_BASE_URL?: string
/** Default model id override. */
GOOGLE_AI_MODEL?: string
}
createProvider(config)Creates a Google Gemini AI provider instance.
function createProvider(config?: GoogleConfig): AIProvider
config — Google-specific configuration (API key, base URL, model).Returns: An AIProvider backed by the Google Generative Language REST API.
aiGoogleSecretDefinitionsSecret definitions required by the Google AI bond.
const aiGoogleSecretDefinitions: SecretDefinition[]
providerThe provider implementation.
const provider: AIProvider
Implements @molecule/api-ai interface.
Setup function to register this provider with the bond system:
import { bond } from '@molecule/api-bond'
import { provider } from '@molecule/api-ai-google'
export function setupAiGoogle(): void {
bond('ai', 'google', provider)
}
Peer dependencies:
@molecule/api-ai ^1.0.1@molecule/api-bond ^1.0.1@molecule/api-i18n ^1.0.1@molecule/api-secrets ^1.0.1GOOGLE_AI_API_KEY (required) — Google AI (Gemini) API key
AIza...@molecule/api-ai@molecule/api-bond@molecule/api-i18n@molecule/api-secretsConfig: GOOGLE_AI_API_KEY (SERVER-side only) plus an optional default model id/base URL.
Missing GOOGLE_AI_API_KEY fails fast (throws naming the exact env var on first use — the
exported provider is a lazy proxy, so this fires on the first chat() call).
Error message disambiguation: a plain 400 that ISN'T a context-length error (bad param, malformed tool schema) gets its own non-retryable message distinct from the generic "AI service error. Please try again." used for retryable failures.
Integration checklist — drive the real UI (live preview, no mocks), adapt each item to this app's actual chat/AI screens, and check every box off one by one. A box you can't check is an integration bug to fix — not a skip. The sandbox HAS an AI provider bonded, so the flow runs live end-to-end; AI output is NON-DETERMINISTIC, so assert on STRUCTURE/behavior, not exact text:
chat() yields text chunks then a final done; a single late
blob means the reply was awaited whole and streaming is broken.)messages history is sent, not just the last
line.