The primary text prompt.
Optionaloptions: {OptionalapiKey?: stringAPI key; defaults to AI_KEY env var.
Optionalcache?: booleanCache the model response before user processing, not the callback output. Defaults to true.
Optionalfiles?: { path: string; type: "image" | "video" | "audio" | "pdf" | "text" }[]Files to send alongside the prompt, in order. Each entry has a path (local path or gs:// URL) and a type ("image", "video", "audio", "pdf", or "text"). All files are appended as separate content parts after the prompt.
OptionalgeminiParameters?: Partial<GenerateContentParameters>Extra params merged into generateContent.
Optionallocation?: stringGCP location; defaults to AI_LOCATION env var.
Optionalmodel?: stringModel name; defaults to AI_MODEL env var.
OptionalprocessResponse?: (response: unknown) => TResponse | Promise<TResponse>Transform or validate the model response on every call, including cache hits. The callback output is never cached; rejected cached responses are removed.
Optionalproject?: stringGCP project ID; defaults to AI_PROJECT env var.
OptionalsafetyEnabled?: booleanOverride safety filter defaults; this library requires true with API-key authentication.
OptionalschemaJson?: unknownZod JSON schema for structured output.
OptionalsystemPrompt?: stringOptional system prompt.
Optionaltemperature?: numberSampling temperature sent to Gemini.
OptionalthinkingBudget?: numberReasoning token budget. Use 0 to disable thinking, -1 for a dynamic budget, or a positive number for a fixed budget. Ignored when thinkingLevel is provided.
OptionalthinkingLevel?: "minimal" | "low" | "medium" | "high"Thinking level: "minimal" | "low" | "medium" | "high".
Optionalvertex?: booleanUse Vertex AI authentication.
OptionalwebSearch?: booleanEnable web search grounding (extra cost).
const result = await askGemini("What is the capital of France?");
console.log(result.response); // "Paris"
// Pass credentials directly.
const response = await askGemini("What is the capital of France?", {
apiKey: "your_api_key",
model: "gemini-3.5-flash",
});
// Vertex AI.
const vertexResponse = await askGemini("What is the capital of France?", {
vertex: true,
project: "your_project_id",
location: "us-central1",
});
// Web search grounding.
const factCheck = await askGemini(
`Verify: "Renewable energy now accounts for over 30% of global electricity generation."`,
{ webSearch: true },
);
// Structured JSON output with a Zod schema.
import * as z from "zod";
const schema = z.toJSONSchema(z.array(z.object({ name: z.string(), age: z.number() })));
await askGemini("Give me 10 random people.", { schemaJson: schema });
// Analyse a local image.
const info = await askGemini("Describe this image.", {
files: [{ path: "./photo.jpg", type: "image" }],
});
Interacts with Google's Gemini models to perform a wide range of tasks, from answering questions to analyzing multimedia content.
Authentication: set
AI_KEY(API key) orAI_PROJECT+AI_LOCATION(Vertex AI) environment variables, or pass credentials directly via options.Caching: model calls can be slow and costly, so original responses are cached in
.journalism-cacheby default.processResponsereruns on every call, including cache hits, and its output is never cached. Keep it lightweight and optimize heavier processing, especially for large workloads. Setcache: falseto disable caching.File handling: pass files via
files: [{ path, type }]. Local paths andgs://GCS URLs are both supported for images, audio, video, PDF, and text.Web Search Grounding: set
webSearch: trueto let the model search the web in real time (extra API cost).Safety filters are on by default (
true) but off when using Vertex AI (false); override withsafetyEnabled.