Google Gemini
Run batches on the Gemini Developer API — inline :batchGenerateContent with results keyed by request.
Google’s Gemini Developer API runs batches inline: requests are submitted to :batchGenerateContent, which returns a long-running operation you poll, then reads the responses back inline — each correlated by a key you set per request. Batchwork wraps that in the standard batch() call.
| Property | Value |
|---|---|
| Shape | Inline :batchGenerateContent |
| Results | Inline operation responses |
| Webhooks | Poll-only (managed by the server) |
| Env var | GOOGLE_GENERATIVE_AI_API_KEY (or GEMINI_API_KEY) |
| Package | @ai-sdk/google |
| Base URL | https://generativelanguage.googleapis.com/v1beta |
Example
import { batch } from "batchwork";
import { google } from "@ai-sdk/google";
const job = await batch({
model: google("gemini-2.5-flash"),
requests: [
{ customId: "fr", prompt: "Capital of France? One word." },
{ customId: "jp", prompt: "Capital of Japan? One word." },
],
});
A "google/…" or "gemini/…" model string works too — see Models.
How it works
- Build — each request becomes
{ metadata: { key: customId }, request }, whererequestis the captured body. - Submit —
POST /v1beta/models/{model}:batchGenerateContent. The model is set in the URL. - Poll — the returned long-running operation is polled; its
JOB_STATE_*value maps onto the normalized status. - Read — the inline responses are read back, each correlated by its
metadata.key.
Batchwork validates Gemini operation ids before using them in API paths.
Notes
This is the Gemini Developer API, not Vertex AI — Vertex’s batch API requires GCS staging and cloud IAM auth, which aren’t supported yet. Gemini has no native batch webhook, so it is poll-only; use the server layer for unified completion events.
Embeddings
Gemini embedding models (e.g. gemini-embedding-001) run through the async :asyncBatchEmbedContent batch method rather than :batchGenerateContent. Submit with batch.embeddings():
import { batch } from "batchwork";
import { google } from "@ai-sdk/google";
const job = await batch.embeddings({
model: google.embeddingModel("gemini-embedding-001"),
requests: [{ customId: "a", value: "The quick brown fox." }],
});
The vector lands on result.embedding. Tune providerOptions.google.outputDimensionality / taskType per request — see Embeddings.
Images
Gemini image models (e.g. gemini-2.5-flash-image) run through the same :batchGenerateContent flow — submit with batch.images():
import { batch } from "batchwork";
import { google } from "@ai-sdk/google";
const job = await batch.images({
model: google.image("gemini-2.5-flash-image"),
requests: [
{ customId: "a", prompt: "A sunlit forest path.", aspectRatio: "16:9" },
],
});
Images are read back inline from each response’s candidates[].content.parts[].inlineData and land as base64 on result.images[].data (with mediaType). Google’s Imagen models (:predict) aren’t batch-supported. See Images.
Credentials
Set GOOGLE_GENERATIVE_AI_API_KEY (or GEMINI_API_KEY), or pass apiKey / baseURL / headers to batch(). Install the peer dependency:
bun add @ai-sdk/google