fleetwire
An unofficial, read-only Rust client for the Tesla Fleet API that knows which calls cost money.
Not affiliated with, endorsed by, or sponsored by Tesla, Inc. Tesla names and trademarks belong to their respective owners.
- Read-only. GET requests only. There is no vehicle-command or signing code, and the endpoint trait is sealed, so a caller cannot add a write.
- Cost-aware. Every request type says whether Tesla bills it (
Pricing). Billed calls are never retried or re-sent by the recovery paths, andClient::send_guardedchecks for free whether the car is online before spending anything. - Synchronous. Built on
ureqwith rustls. No async runtime needed. - Careful with tokens.
TokenManagerkeeps tokens in an owner-only directory at0600, persists a rotated refresh token before returning, and collapses concurrent refreshes within and across processes.
Quick start
Before you start you need two things from Tesla, and this crate does not obtain them for you:
- a Tesla developer app — its client id;
- a refresh token for your account, issued to that app with the scopes
openid,offline_accessandvehicle_device_data.
Tesla's Fleet API docs cover app registration and the authorization-code flow that yields the refresh token. fleetwire takes over from there: it refreshes access tokens, but it does not run the authorization-code exchange. Expect this part to take longer than everything below.
The crate builds on Linux and macOS (CI runs on Linux).
-
Get the code. The example lives in the repository, so clone it; the commands below work from anywhere inside the clone.
-
Put the refresh token where only you can read it:
&& ( && )expires_atis a Unix time in seconds;0means "already expired", so the first call refreshes the access token and fills inaccess_token.- Do this once. fleetwire rewrites this file every time Tesla rotates the refresh token, and the newest refresh token exists only there. Running the command again over a working directory overwrites it with the old token you pasted.
- The directory must not be accessible to other users, or the client refuses to read it.
- A
tokens.lockfile appears next to it. It is the cross-process lock; leave it.
-
List your vehicles. This call is free and does not wake the car:
TESLA_CLIENT_ID=your-client-id FLEETWIRE_TOKEN_DIR=/.fleetwire \1 vehicle(s) - vin LRW**********1234 · state asleepThe example masks the VIN; add
-- --show-vinto print it in full.TESLA_CLIENT_IDandFLEETWIRE_TOKEN_DIRare read by the example only — the library takes both as arguments.
If it fails
| You see | Usual cause |
|---|---|
set TESLA_CLIENT_ID … / set FLEETWIRE_TOKEN_DIR … |
The environment variable is missing. |
token refresh failed: HTTP 400 … client_not_found |
The client id is wrong, or belongs to another app. |
Any other token refresh failed: HTTP 4xx … |
The refresh token is mistyped, expired, already rotated, or was issued to a different client id. Tesla's own message follows the status. |
token directory permissions are too permissive |
The directory or tokens.json is readable by others: chmod 700 ~/.fleetwire && chmod 600 ~/.fleetwire/tokens.json. |
token file not found |
FLEETWIRE_TOKEN_DIR points at a directory without tokens.json (step 2). |
| A scope error before any request is sent | The token lacks vehicle_device_data; re-authorize the app with that scope. |
-
Use it from your code. Add the dependency (
cargo add fleetwire, once published — until then, apathorgitdependency on this repository), then:use Arc; use ListVehicles; use ; #
Calls that cost money
Of the sixteen endpoints this crate models, two are billed: GetVehicleData and
GetNearbyChargingSites (measured: $0.002 per request, and a 408 from a sleeping vehicle is billed too).
The other fourteen are not.
| Entry point | What it does |
|---|---|
Client::send |
The typed response. |
Client::send_guarded |
Checks the car's state with a free call first and only makes the billed call when it is online; otherwise reports Guarded::Skipped and spends nothing. |
Client::send_metered |
The typed response plus the ratelimit-* quota the billed endpoints report. |
Client::send_raw |
The response body verbatim and unscrubbed (VIN, coordinates, odometer) as one serde_json::Value, for observing schema drift. Treat it as personal data. |
max_attempts defaults to 1, and the 401/412 recovery paths never re-send a request to a billed
endpoint. send_guarded narrows the window but cannot close it: the car can fall asleep between the free
check and the billed call.
Status
Early release. The API may change before 1.0.
The sixteen modelled GET endpoints (12 vehicle, 4 user) were verified against live responses. Not implemented: vehicle commands and anything that writes — this crate has no POST or signing code and is not a route to one — and the charging, energy and partner endpoints, which are left out until a live response can verify their shape.
A custom TokenRefresher must bound its own request time: TokenManager holds a cross-process file lock
while a refresh runs.
Minimum Supported Rust Version (MSRV)
Rust 1.89.0 (edition 2024 floor). The MSRV may rise only in a documented minor release.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions.