# Wakapi : wakatime API client
Read-only API client for the [Wakatime API](https://wakatime.com/developers), supporting all GET endpoints as blocking or async depending on the `blocking` feature flag.
The following endpoints are implemented:
- [All Time Since Today](https://wakatime.com/developers#all-time-since-today) : [AllTimeSinceToday], [AllTimeSinceTodayParams], [AllTimeSinceToday::fetch]
- [Commit](https://wakatime.com/developers#commit) : [Commit], [CommitParams], [Commit::fetch]
- [Commits](https://wakatime.com/developers#commits) : [Commits], [CommitsParams], [Commits::fetch]
- [Durations](https://wakatime.com/developers#durations) : [Durations], [DurationsParams], [Durations::fetch]
- [Heartbeats](https://wakatime.com/developers#heartbeats) : [Heartbeats], [HeartbeatsParams], [Heartbeats::fetch]
- [Projects](https://wakatime.com/developers#projects) : [Projects], [ProjectsParams], [Projects::fetch]
- [Stats](https://wakatime.com/developers#stats) : [Stats], [StatsParams], [Stats::fetch]
- [Summaries](https://wakatime.com/developers#summaries) : [Summaries], [SummariesParams], [Summaries::fetch]
The structures are based on the [official documentation](https://wakatime.com/developers) last checked **2026-09-19**.
## Known inconsistencies with the official documentation
- **`projects`** — `repository` and `badge` fields are documented as strings but the API returns objects (`RepositoryDetails` and `ProjectBadge` respectively). The struct types match the actual API response.
- **`projects`** — The response includes pagination fields (`page`, `total`, `total_pages`, `prev_page`, `next_page`) not shown in the documentation.
- **`commits`** — The response includes a `page` field not shown in the documentation.
- **`stats`** — The response includes an `is_up_to_date_pending_future` boolean field not present in the documentation.
- **`heartbeats`** — `dependencies` is documented as a comma separated string but the API returns a list; both are accepted and exposed as `Option<Vec<String>>`.
- **`heartbeats`** — `id`, `user_id`, `user_agent_id` and `created_at` are present in the response but not documented.
- **`stats`** / **`all_time_since_today`** — While stats are being calculated (202 response code), the body is partial and includes a top-level `message`. Stats totals, averages, dates and lists are therefore optional (or empty).
- **`summaries`** — When `project` is set, the response includes top-level `available_branches`, `branches` and `color` fields not shown in the documentation.
- **`durations`** — The response includes `ai_model_line_changes` and `color` fields not shown in the documentation.
- **AI stats** — Most AI-related objects include an undocumented `ai_cached_input_tokens` field; `editors` stats also include `ai_additions`, `ai_deletions`, `human_additions` and `human_deletions`.
## Authentication
Wakatime API keys are now **write-only**, so they can't be used with the read endpoints of this client. Use an OAuth 2.0 access token with [WakapiClient::with_token] instead:
- For your own account, [get your OAuth token](https://wakatime.com/oauth); you don't need to publish an OAuth app.
- For other users, [create an app](https://wakatime.com/apps) and follow the [OAuth 2.0 flow](https://wakatime.com/developers#authentication). This client takes an access token and doesn't implement the flow itself.
The token needs the `read_stats`, `read_summaries` and `read_heartbeats` scopes to cover all endpoints of this client:
| `read_stats` | All Time Since Today, Stats |
| `read_stats.projects` | Projects |
| `read_summaries` | Summaries |
| `read_heartbeats` | Commit, Commits, Durations, Heartbeats |
[WakapiClient::new] still sends HTTP Basic credentials, for Wakatime-compatible servers that accept API keys on these endpoints.
## Usage
### Async mode
```rust
use wakapi::WakapiClient;
let client = WakapiClient::with_token(
"https://wakatime.com",
"YOUR_WAKATIME_OAUTH_TOKEN",
);
let res = wakapi::Summaries::fetch(
&client,
wakapi::SummariesParams::from_interval("2026-01-01", "2026-01-05"),
).await.unwrap();
println!("{:?}", res);
```
### Blocking mode
```rust
use wakapi::WakapiClient;
let client = WakapiClient::with_token(
"https://wakatime.com",
"YOUR_WAKATIME_OAUTH_TOKEN",
);
let res = wakapi::Summaries::fetch(
&client,
wakapi::SummariesParams::from_interval("2026-01-01", "2026-01-05"),
).unwrap();
println!("{:?}", res);
```
## Integration tests
Integration tests hit the real Wakatime API and require `WAKAPI_URL` and one of `WAKAPI_TOKEN` or `WAKAPI_KEY`:
| `WAKAPI_URL` | Base URL of the server, e.g. `https://wakatime.com` |
| `WAKAPI_TOKEN` | OAuth 2.0 access token (required for wakatime.com) |
| `WAKAPI_KEY` | HTTP Basic credentials, for Wakatime-compatible servers (ignored if `WAKAPI_TOKEN` is set) |
```sh
# Async (default)
WAKAPI_URL=https://wakatime.com WAKAPI_TOKEN=<token> cargo test --test integration
# Blocking
WAKAPI_URL=https://wakatime.com WAKAPI_TOKEN=<token> cargo test --features blocking --test integration
```
If the environment variables are not set, all tests are silently skipped.
## License
This project is licensed under the MIT License.