kagi-sdk
Typed Rust SDK for Kagi with explicit official-api and session-web surfaces.
Features at a glance
| Feature | What you get |
|---|---|
| Explicit protocol boundaries | Separate official_api() and session_web() clients |
| Typed request models | Constructor-level validation for common invalid input |
| Fail-fast auth/surface checks | Invalid credential/surface combinations fail before request execution |
| Endpoint scope clarity | v1 support tracked in ../docs/endpoint-auth-version-matrix.md |
Install
Choose one installation mode:
crates.io (recommended)
[]
= "0.1.3"
= { = "1", = ["macros", "rt-multi-thread"] }
Path dependency (same workspace or local checkout)
[]
= { = "../sdk" }
= { = "1", = ["macros", "rt-multi-thread"] }
Git dependency (unreleased revisions)
[]
= { = "https://github.com/kdcokenny/kagi-rs", = "kagi-sdk" }
= { = "1", = ["macros", "rt-multi-thread"] }
Choose your surface
| Use case | SDK surface | Credential |
|---|---|---|
| Kagi official API routes | client.official_api()? |
BotToken (commonly from KAGI_API_KEY) |
| Kagi session-web routes | client.session_web()? |
SessionToken (commonly from KAGI_SESSION_TOKEN) |
Quickstart (canonical: official API)
use SearchRequest;
use ;
async
Session quickstart (alternate surface)
use ;
use ;
async
Supported endpoints
Official API (Authorization: Bot <token>)
| Method | Route | SDK method |
|---|---|---|
| GET | /api/v0/search |
official_api.search(...) |
| GET | /api/v0/enrich/web |
official_api.enrich_web(...) |
| GET | /api/v0/enrich/news |
official_api.enrich_news(...) |
| GET | /api/v0/summarize |
official_api.summarize_get(...) |
| POST | /api/v0/summarize |
official_api.summarize_post(...) |
| POST | /api/v0/fastgpt |
official_api.fastgpt(...) |
| GET | /api/v1/smallweb/feed |
official_api.smallweb_feed(...) |
Session web (Cookie: kagi_session=<token>)
| Method | Route | SDK method |
|---|---|---|
| GET | /html/search |
session_web.search(...) |
| GET or POST | /mother/summary_labs or /mother/summary_labs/ |
session_web.summarize(...) |
| GET or POST | /mother/summary_labs or /mother/summary_labs/ |
session_web.summarize_stream(...) (advanced) |
Error handling
Most methods return Result<_, kagi_sdk::KagiError>.
Common categories:
- invalid credential/input/configuration
- unsupported auth/surface combination
- unauthorized bot token or invalid session
- transport failures
- parse failures
- API envelope failures
Advanced configuration
use Duration;
use ;
Development and live-test notes
From workspace root:
Live integration tests are manual-only in v1 via live-integration.yml:
sdk/tests/live_official.rsexpectsKAGI_API_KEY(optionalKAGI_BASE_URL)sdk/tests/live_session.rsexpectsKAGI_SESSION_TOKEN(optionalKAGI_BASE_URL)
For release/workflow policy, see ../docs/releasing.md.