Expand description
A simple Rust library that demonstrates how to call the Meter endpoints of OpenMeter.
Add the following to your Cargo.toml
:
[dependencies]
reqwest = "0.11"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tokio = { version = "1", features = ["macros"] }
§Example
ⓘ
use openmeter::{MeterClient, CreateMeterRequest};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = MeterClient::new("https://openmeter.cloud".to_string(), "YOUR_SECRET_TOKEN".to_string());
// Create a meter
let create_req = CreateMeterRequest {
slug: "tokens_total".to_string(),
name: Some("Tokens Total".to_string()),
description: Some("AI Token Usage".to_string()),
aggregation: "SUM".to_string(),
event_type: "prompt".to_string(),
event_from: None,
value_property: Some("$.tokens".to_string()),
group_by: Some(serde_json::json!({
"model": "$.model",
"type": "$.type"
})),
metadata: None,
};
let meter = client.create_meter(&create_req).await?;
println!("Created meter: {:?}", meter);
Ok(())
}
Structs§
- Cloud
Event - Represents a single CloudEvent.
- Create
Entitlement Request - Request body to create an Entitlement (all entitlement types).
- Create
Feature Request - Request body to create a Feature.
- Create
Meter Request - Request body to create a meter.
- Entitlement
- Response model for an Entitlement.
- Feature
- Response model for a Feature.
- Grant
- Response model for a Grant.
- Grant
Request - Request body to create a Grant.
- Ingested
Event - Represents an event that was ingested, including timestamps.
- List
Events Params - Parameters for listing events.
- Meter
- Represents a Meter object returned from the API.
- Meter
Client - A convenient client to interact with the Meter esndpoints.
- Query
Data - Individual data point in the usage query response.
- Query
Params - Represents optional parameters for querying meter usage.
- Query
Response - Represents the response structure from Querying usage.
- Reset
Entitlement Request - Request body to reset an Entitlement.
- Update
Meter Request - Request body to update a meter.