metronome-sdk
An unofficial Rust client for the Metronome billing API, generated from Metronome's published OpenAPI spec with progenitor.
Metronome doesn't ship a Rust SDK (only TypeScript and Go). This crate generates a typed, async client (
reqwest+serde) from their OpenAPI spec.src/lib.rsis generated — do not hand-edit it. Re-run./scripts/generate.shinstead.
Usage
Metronome uses bearer-token auth. progenitor doesn't inject the token itself, so
attach it as a default header on the reqwest::Client and hand that to the
generated client:
use FromStr;
use Client;
use IngestV1BodyItem;
async
Every Metronome endpoint is available as an async method on Client (119 in
total) — e.g. ingest_v1, search_events_v1, create_billable_metric_v1.
Request/response types live under metronome_sdk::types. Constrained string
fields are generated as validated newtypes; construct them with
FromStr/TryFrom (both return a ConversionError if validation fails).
Regenerating
Why the spec needs patching
Metronome's published OpenAPI spec has constructs that progenitor/typify can't
consume directly (the official Go/TS SDKs use a private Stainless overlay we
don't have). scripts/patch_spec.py applies three mechanical, deterministic
fixes before generation:
- Case-insensitive enums →
string(618 of them). The spec enumerates every casing of each value (count/Count/COUNT), which can't map to unique Rust variants. Downgrading tostringround-trips losslessly regardless of the casing the API returns. - Mis-typed string enums →
type: string(7). Some enums declaretype: objectdespite having string values (e.g.billable_status). - Stray scalar
formaton array/object nodes stripped (2). e.g. atype: arraycarryingformat: uuid.
If a future spec revision introduces a new unsupported construct, generation
will fail loudly; extend patch_spec.py with a new rule.