gemini-cli-sdk
Strongly-typed, async-first Rust SDK for building agents on the Google Gemini CLI (gemini --experimental-acp).
Features
- One-shot queries -
query()/query_with_content()return collected messages - Streaming -
query_stream()/query_stream_with_content()yield messages as they arrive - Multi-turn sessions -
Clientwithsend()/send_content()for persistent threads - Multimodal input - text + image URLs or base64 blobs via
UserContent - Permission callbacks -
CanUseToolCallbackfor per-tool approval/denial - Lifecycle hooks -
HookMatcherforPreToolUse,PostToolUse,Stop, etc. - MCP server config - attach Model Context Protocol servers at session start
- Message callbacks - observe or log messages without interrupting the stream
- Testing framework -
MockTransport+ScenarioBuilder(featuretesting) - Cross-platform - macOS, Linux, and Windows
Quick Start
[]
= "0.1"
= { = "1", = ["macros", "rt-multi-thread"] }
use query;
async
Examples
All examples require a working Gemini CLI installation and authentication.
| Example | Feature | Run |
|---|---|---|
simple_query |
One-shot query | cargo run --example simple_query |
streaming |
Streaming responses | cargo run --example streaming |
multi_turn |
Multi-turn session | cargo run --example multi_turn |
with_permissions |
Tool approvals | cargo run --example with_permissions |
with_hooks |
Lifecycle hooks | cargo run --example with_hooks |
Testing
Enable mock testing support:
= { = "0.1", = ["testing"] }
Run the test suites:
Disclaimer
This is an unofficial, community-developed SDK and is not affiliated with, endorsed by, or sponsored by Google. "Gemini" is a trademark of Google. This crate interacts with the Gemini CLI but does not contain any Google proprietary code.
License
Licensed under either of Apache License, Version 2.0 or MIT License at your option.
Maintained by the POM team.