Skip to content

Google Gemini

Connect to Gemini with a Google AI Studio API key, choose a Gemini model, and use it with the standard nimgent APIs.

import std/os
import nimgent
import nimgent/providers/google
let model = google(getEnv("GEMINI_API_KEY")).model("gemini-3.5-flash-lite")
echo generateText(model, prompt = "Say hello in one sentence.").text

Set GEMINI_API_KEY before you run the program.

google(...) connects to the Gemini API from Google AI Studio. Vertex AI uses different credentials and endpoints, and is not supported by this constructor.

Use GoogleOptions to set the embedding taskType for Gemini embeddings.

import std/options
let settings = ProviderOptions(google: GoogleOptions(
taskType: some("RETRIEVAL_DOCUMENT")
))

Pass settings to embed or embedMany as providerOptions. Use a task type supported by the selected Gemini embedding model.

For a Google-native setting without a typed option, use ProviderOptions.extra with the google namespace.

See Settings for portable controls, or Tools and agents for provider-hosted tools such as web search.