UsageClient

Struct UsageClient 

Source
pub struct UsageClient<'a, T = ()> { /* private fields */ }
Expand description

Client for usage API.

Implementations§

Source§

impl<T: Default + Send + Sync> UsageClient<'_, T>

Source

pub async fn audio_speeches( &self, builder: UsageBuilder, ) -> Result<UsageResponse>

Get usage data for audio speeches.

§Example
use openai_ergonomic::Client;
use openai_ergonomic::builders::usage::UsageBuilder;

let client = Client::from_env()?;
let builder = UsageBuilder::new(1704067200, None);
let usage = client.usage().audio_speeches(builder).await?;
println!("Usage: {:?}", usage);
Examples found in repository?
examples/usage.rs (line 145)
141async fn audio_usage(client: &Client, start_time: i32, end_time: i32) -> Result<()> {
142    let builder = UsageBuilder::new(start_time, Some(end_time)).limit(10);
143
144    // Audio speeches (text-to-speech)
145    let speeches = client.usage().audio_speeches(builder.clone()).await?;
146    println!("Audio speeches usage: {} data points", speeches.data.len());
147
148    // Audio transcriptions
149    let transcriptions = client.usage().audio_transcriptions(builder).await?;
150    println!(
151        "Audio transcriptions usage: {} data points",
152        transcriptions.data.len()
153    );
154
155    Ok(())
156}
Source

pub async fn audio_transcriptions( &self, builder: UsageBuilder, ) -> Result<UsageResponse>

Get usage data for audio transcriptions.

Examples found in repository?
examples/usage.rs (line 149)
141async fn audio_usage(client: &Client, start_time: i32, end_time: i32) -> Result<()> {
142    let builder = UsageBuilder::new(start_time, Some(end_time)).limit(10);
143
144    // Audio speeches (text-to-speech)
145    let speeches = client.usage().audio_speeches(builder.clone()).await?;
146    println!("Audio speeches usage: {} data points", speeches.data.len());
147
148    // Audio transcriptions
149    let transcriptions = client.usage().audio_transcriptions(builder).await?;
150    println!(
151        "Audio transcriptions usage: {} data points",
152        transcriptions.data.len()
153    );
154
155    Ok(())
156}
Source

pub async fn code_interpreter_sessions( &self, builder: UsageBuilder, ) -> Result<UsageResponse>

Get usage data for code interpreter sessions.

Source

pub async fn completions(&self, builder: UsageBuilder) -> Result<UsageResponse>

Get usage data for completions.

Examples found in repository?
examples/usage.rs (line 75)
72async fn basic_usage_query(client: &Client, start_time: i32, end_time: i32) -> Result<()> {
73    let builder = UsageBuilder::new(start_time, Some(end_time));
74
75    let usage = client.usage().completions(builder).await?;
76
77    println!("Completions usage:");
78    println!("  Data points: {}", usage.data.len());
79
80    if usage.has_more {
81        println!("  Has more: yes");
82    }
83
84    Ok(())
85}
86
87async fn usage_with_aggregation(client: &Client, start_time: i32, end_time: i32) -> Result<()> {
88    let builder = UsageBuilder::new(start_time, Some(end_time))
89        .bucket_width(BucketWidth::Day)
90        .limit(10);
91
92    let usage = client.usage().completions(builder).await?;
93
94    println!("Daily aggregated completions usage:");
95    println!("  Bucket width: 1 day");
96    println!("  Data points: {}", usage.data.len());
97
98    Ok(())
99}
100
101async fn usage_by_model(client: &Client, start_time: i32, end_time: i32) -> Result<()> {
102    let builder = UsageBuilder::new(start_time, Some(end_time))
103        .model("gpt-4")
104        .limit(100);
105
106    let usage = client.usage().completions(builder).await?;
107
108    println!("Completions usage for gpt-4:");
109    println!("  Data points: {}", usage.data.len());
110
111    Ok(())
112}
113
114async fn usage_grouped_by_project(client: &Client, start_time: i32, end_time: i32) -> Result<()> {
115    let builder = UsageBuilder::new(start_time, Some(end_time))
116        .group_by(GroupBy::ProjectId)
117        .group_by(GroupBy::Model)
118        .limit(50);
119
120    let usage = client.usage().completions(builder).await?;
121
122    println!("Completions usage grouped by project and model:");
123    println!("  Data points: {}", usage.data.len());
124
125    Ok(())
126}
Source

pub async fn embeddings(&self, builder: UsageBuilder) -> Result<UsageResponse>

Get usage data for embeddings.

Examples found in repository?
examples/usage.rs (line 176)
171async fn embeddings_usage(client: &Client, start_time: i32, end_time: i32) -> Result<()> {
172    let builder = UsageBuilder::new(start_time, Some(end_time))
173        .model("text-embedding-3-small")
174        .limit(100);
175
176    let usage = client.usage().embeddings(builder).await?;
177
178    println!("Embeddings usage for text-embedding-3-small:");
179    println!("  Data points: {}", usage.data.len());
180
181    Ok(())
182}
Source

pub async fn images(&self, builder: UsageBuilder) -> Result<UsageResponse>

Get usage data for images.

Examples found in repository?
examples/usage.rs (line 163)
158async fn image_usage(client: &Client, start_time: i32, end_time: i32) -> Result<()> {
159    let builder = UsageBuilder::new(start_time, Some(end_time))
160        .bucket_width(BucketWidth::Day)
161        .limit(10);
162
163    let usage = client.usage().images(builder).await?;
164
165    println!("Image generation usage:");
166    println!("  Data points: {}", usage.data.len());
167
168    Ok(())
169}
Source

pub async fn moderations(&self, builder: UsageBuilder) -> Result<UsageResponse>

Get usage data for moderations.

Source

pub async fn vector_stores( &self, builder: UsageBuilder, ) -> Result<UsageResponse>

Get usage data for vector stores.

Source

pub async fn costs(&self, builder: UsageBuilder) -> Result<UsageResponse>

Get cost data.

Examples found in repository?
examples/usage.rs (line 133)
128async fn cost_data(client: &Client, start_time: i32, end_time: i32) -> Result<()> {
129    let builder = UsageBuilder::new(start_time, Some(end_time))
130        .bucket_width(BucketWidth::Day)
131        .limit(10);
132
133    let costs = client.usage().costs(builder).await?;
134
135    println!("Cost data:");
136    println!("  Data points: {}", costs.data.len());
137
138    Ok(())
139}

Trait Implementations§

Source§

impl<'a, T: Clone> Clone for UsageClient<'a, T>

Source§

fn clone(&self) -> UsageClient<'a, T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, T: Debug> Debug for UsageClient<'a, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, T: Copy> Copy for UsageClient<'a, T>

Auto Trait Implementations§

§

impl<'a, T> Freeze for UsageClient<'a, T>

§

impl<'a, T = ()> !RefUnwindSafe for UsageClient<'a, T>

§

impl<'a, T> Send for UsageClient<'a, T>

§

impl<'a, T> Sync for UsageClient<'a, T>

§

impl<'a, T> Unpin for UsageClient<'a, T>

§

impl<'a, T = ()> !UnwindSafe for UsageClient<'a, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,