pub struct BudgetManager { /* private fields */ }Expand description
Budget manager for AI usage
Implementations§
Source§impl BudgetManager
impl BudgetManager
Sourcepub fn new(config: BudgetConfig) -> BudgetManager
pub fn new(config: BudgetConfig) -> BudgetManager
Create a new budget manager
Sourcepub fn with_org_controls(
config: BudgetConfig,
org_controls: Arc<OrgControls>,
) -> BudgetManager
pub fn with_org_controls( config: BudgetConfig, org_controls: Arc<OrgControls>, ) -> BudgetManager
Create a new budget manager with org controls
Sourcepub async fn get_usage(&self, workspace_id: &str) -> Result<UsageStats, Error>
pub async fn get_usage(&self, workspace_id: &str) -> Result<UsageStats, Error>
Get usage statistics for a workspace
Sourcepub async fn check_budget(
&self,
org_id: Option<&str>,
workspace_id: &str,
estimated_tokens: u64,
) -> Result<bool, Error>
pub async fn check_budget( &self, org_id: Option<&str>, workspace_id: &str, estimated_tokens: u64, ) -> Result<bool, Error>
Check if request is within budget
Checks org-level limits first (if available), then workspace-level limits. Org-level limits take precedence.
Sourcepub async fn check_rate_limit(
&self,
org_id: Option<&str>,
workspace_id: &str,
) -> Result<bool, Error>
pub async fn check_rate_limit( &self, org_id: Option<&str>, workspace_id: &str, ) -> Result<bool, Error>
Check rate limit (org-level first, then workspace-level)
Sourcepub async fn is_feature_enabled(
&self,
org_id: Option<&str>,
workspace_id: &str,
feature: &str,
) -> Result<bool, Error>
pub async fn is_feature_enabled( &self, org_id: Option<&str>, workspace_id: &str, feature: &str, ) -> Result<bool, Error>
Check if a feature is enabled (org-level first, then defaults to true)
Sourcepub async fn record_usage(
&self,
org_id: Option<&str>,
workspace_id: &str,
user_id: Option<&str>,
tokens: u64,
cost_usd: f64,
) -> Result<(), Error>
pub async fn record_usage( &self, org_id: Option<&str>, workspace_id: &str, user_id: Option<&str>, tokens: u64, cost_usd: f64, ) -> Result<(), Error>
Record token usage and cost
Sourcepub async fn record_usage_with_feature(
&self,
org_id: Option<&str>,
workspace_id: &str,
user_id: Option<&str>,
tokens: u64,
cost_usd: f64,
feature: Option<AiFeature>,
) -> Result<(), Error>
pub async fn record_usage_with_feature( &self, org_id: Option<&str>, workspace_id: &str, user_id: Option<&str>, tokens: u64, cost_usd: f64, feature: Option<AiFeature>, ) -> Result<(), Error>
Record token usage and cost with feature tracking
Records usage both in-memory (workspace-level) and in org controls (if available).
Auto Trait Implementations§
impl Freeze for BudgetManager
impl !RefUnwindSafe for BudgetManager
impl Send for BudgetManager
impl Sync for BudgetManager
impl Unpin for BudgetManager
impl UnsafeUnpin for BudgetManager
impl !UnwindSafe for BudgetManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more