A V language SDK for interacting with Google's Gemini AI API. This module provides a simple and efficient way to integrate Gemini's generative AI capabilities into your V applications.
- Support for multiple free Gemini models (2.5 Flash variants, 3.0 Flash and gemma 3 variant) - PRs welcome for paid models
- Simple prompt-based text generation
- Advanced request configuration with system instructions
- Comprehensive response handling
- Type-safe API with structured data models
- Built-in error handling
v install Ddiidev.sdkgeminiOR
v install https://github.com/Ddiidev/sdk_gemini// import Ddiidev.sdk_gemini //for install from vpm
// for install github repo
import log // built-in V module
import sdk_gemini
fn main() {
//log level 'debug' provides full model response when errors occur
log.set_level(.debug)
// Read API key from environment
api_key := sdk_gemini.get_api_key('GEMINI_API_KEY') or {
log.error(err.msg())
return
}
// Initialize the SDK with your API key
mut sdk := sdk_gemini.new(api_key)
// Send a simple prompt
response := sdk.send_prompt(
.gemini_3_0_flash_preview,
'Tell me about João Pessoa, Paraíba',
'You are a tour guide from Brazil, specifically from the Northeast region, João Pessoa and Paraíba state'
) or {
log.error(err.msg())
return
}
content := response.str()
println(content)
}Use the GeminiResponse iterator to safely iterate through all parts.
for part in response {
println(part)
}To get all concatenated content in a single string, use str():
text := response.str()
if text != '' {
println(text)
}You can also directly get the last part with last():
last := response.last() or { '' }
if last != '' {
println(last)
}The main SDK struct for interacting with the Gemini API.
pub struct GeminiSDK {
pub:
api_key string
}Sends a complete request to the Gemini API with full control over the request structure.
Parameters:
model: The Gemini model to use (see Models enum)req_payload: Complete request configuration
Returns: GeminiResponse or error
Simplified method for sending text prompts with optional system instructions.
Parameters:
model: The Gemini model to useprompt: The user prompt/questionsystem_instruction: Optional system instruction (can be empty string)
Returns: GeminiResponse or error
The SDK supports the following Gemini models:
gemma_3_1b_it- Gemma 3.1b Itgemma_3_4b_it- Gemma 3.4b Itgemma_3_12b_it- Gemma 3.12b Itgemma_3_27b_it- Gemma 3.27b Itgemini_2_5_flash_lite_preview_09_2025- Gemini 2.5 Flash Lite Preview 09 2025gemini_2_5_flash_lite- Gemini 2.5 Flash Litegemini_2_5_flash- Gemini 2.5 Flashgemini_3_0_flash_preview- Gemini 3.0 Flash Preview
MIT License
Contributions are welcome! Please feel free to submit issues and pull requests.