eb38c65ac5ee838c9febd0b2d21e37b818535df2
- Remove unused AUTH_SCOPE constant from client.rs - Remove unused ErrorType, ErrorInfoMetadata, FieldViolation, and Link types from types/error.rs - Fix "EventSourrce" typo in error.rs Display impl
google-genai
A Rust client library for the Google Generative AI API.
Building
To build the library, run the following command:
cargo build --release
Running Examples
The project includes several examples in the examples directory. To run an example, you'll first need to set up your environment with your Gemini API key.
-
Create a
.envfile in the root of the project:GEMINI_API_KEY=your_api_key_here -
Run an example using
cargo run:cargo run --example generate-content
Usage
To use this library in your own Rust application, add it as a dependency in your Cargo.toml file:
[dependencies]
google-genai = "0.1.0" # Or the latest version
Here is a basic example of how to use the GeminiClient to generate content:
use std::env;
use google_genai::prelude::{Content, GeminiClient, GenerateContentRequest, Role};
async fn run() -> Result<(), Box<dyn std::error::Error>> {
// Get the API key from the environment.
let api_key = env::var("GEMINI_API_KEY")?;
// Create a new GeminiClient.
let gemini_client = GeminiClient::new(api_key);
// Build a prompt with a single user message.
let prompt = vec![
Content::builder()
.role(Role::User)
.add_text_part("What is the airspeed of an unladen swallow?")
.build(),
];
// Create the content generation request.
let request = GenerateContentRequest::builder().contents(prompt).build();
// Call the API to generate content.
let response = gemini_client
.generate_content(&request, "gemini-3-pro-preview")
.await?;
// Print the response.
println!("Response: {:?}", response.candidates[0].get_text().unwrap());
Ok(())
}
Description
Languages
Rust
100%