Gemini API Module for Duso

Access Google’s Gemini API directly from Duso scripts using the OpenAI-compatible interface.

Setup

  1. Get a free API key from Google AI Studio
  2. Set your API key as an environment variable:
export GEMINI_API_KEY=your_api_key_here
duso script.du

Or pass it explicitly in code:

gemini = require("gemini")
response = gemini.prompt("Hello", {key = "your_api_key_here"})

Quick Start

gemini = require("gemini")

// One-shot query
response = gemini.prompt("What is Gemini?")
print(response)

// Multi-turn conversation
chat = gemini.session({
  system = "You are a helpful assistant",
  model = "gemini-2.5-pro"
})

response1 = chat.prompt("What is Google Gemini known for?")
response2 = chat.prompt("What are its advantages?")
print(chat.usage)

Endpoint

Default: https://generativelanguage.googleapis.com/v1beta/openai/

Cloud-hosted API (no local setup required, unlike Ollama).

Available Models

See Gemini API documentation for the latest model list.

API Key Required

Gemini is a cloud API. You need a valid Google API key from AI Studio.

Configuration Options

Same as OpenAI module - see openai.md for full reference.

Key differences:

See Also