1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
use crate::client::RainyClient;
use crate::error::Result;
use crate::models::{CreditInfo, UsageStats};
impl RainyClient {
/// Get credit statistics
///
/// This endpoint returns information about the user's credit usage.
///
/// # Arguments
///
/// * `days` - Optional number of days to look back (default: 30)
///
/// # Returns
///
/// Returns credit information including balance, usage, and allocation.
///
/// # Example
///
/// ```rust,no_run
/// # use rainy_sdk::RainyClient;
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let client = RainyClient::with_api_key("user-api-key")?;
///
/// let credits = client.get_credit_stats(Some(7)).await?;
/// println!("Current credits: {}", credits.current_credits);
/// println!("Estimated cost: {}", credits.estimated_cost);
/// # Ok(())
/// # }
/// ```
#[deprecated(
note = "Legacy v2-style usage helper. Rainy API v3 usage endpoints require JWT/session auth and return different shapes."
)]
pub async fn get_credit_stats(&self, days: Option<u32>) -> Result<CreditInfo> {
let endpoint = if let Some(days) = days {
format!("/usage/credits?days={days}")
} else {
"/usage/credits".to_string()
};
#[derive(serde::Deserialize)]
struct CreditStatsResponse {
credits: CreditInfo,
}
let response: CreditStatsResponse = self
.make_request(reqwest::Method::GET, &endpoint, None)
.await?;
Ok(response.credits)
}
/// Get usage statistics
///
/// This endpoint returns detailed usage statistics.
///
/// # Arguments
///
/// * `days` - Optional number of days to look back (default: 30)
///
/// # Returns
///
/// Returns comprehensive usage statistics including daily usage and recent transactions.
///
/// # Example
///
/// ```rust,no_run
/// # use rainy_sdk::RainyClient;
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let client = RainyClient::with_api_key("user-api-key")?;
///
/// let usage = client.get_usage_stats(Some(30)).await?;
/// println!("Total requests: {}", usage.total_requests);
/// println!("Total tokens: {}", usage.total_tokens);
///
/// for daily in &usage.daily_usage {
/// println!("{}: {} credits used", daily.date, daily.credits_used);
/// }
/// # Ok(())
/// # }
/// ```
#[deprecated(
note = "Legacy v2-style usage helper. Rainy API v3 usage endpoints require JWT/session auth and return different shapes."
)]
pub async fn get_usage_stats(&self, days: Option<u32>) -> Result<UsageStats> {
let endpoint = if let Some(days) = days {
format!("/usage/stats?days={days}")
} else {
"/usage/stats".to_string()
};
self.make_request(reqwest::Method::GET, &endpoint, None)
.await
}
}