@@ -460,29 +460,27 @@ async fn check_usage_limit(
)
.await?;
- if state.config.is_llm_billing_enabled() {
- if usage.spending_this_month >= FREE_TIER_MONTHLY_SPENDING_LIMIT {
- if !claims.has_llm_subscription {
- return Err(Error::http(
- StatusCode::PAYMENT_REQUIRED,
- "Maximum spending limit reached for this month.".to_string(),
- ));
- }
+ if usage.spending_this_month >= FREE_TIER_MONTHLY_SPENDING_LIMIT {
+ if !claims.has_llm_subscription {
+ return Err(Error::http(
+ StatusCode::PAYMENT_REQUIRED,
+ "Maximum spending limit reached for this month.".to_string(),
+ ));
+ }
- if (usage.spending_this_month - FREE_TIER_MONTHLY_SPENDING_LIMIT)
- >= Cents(claims.max_monthly_spend_in_cents)
- {
- return Err(Error::Http(
- StatusCode::FORBIDDEN,
- "Maximum spending limit reached for this month.".to_string(),
- [(
- HeaderName::from_static(MAX_LLM_MONTHLY_SPEND_REACHED_HEADER_NAME),
- HeaderValue::from_static("true"),
- )]
- .into_iter()
- .collect(),
- ));
- }
+ if (usage.spending_this_month - FREE_TIER_MONTHLY_SPENDING_LIMIT)
+ >= Cents(claims.max_monthly_spend_in_cents)
+ {
+ return Err(Error::Http(
+ StatusCode::FORBIDDEN,
+ "Maximum spending limit reached for this month.".to_string(),
+ [(
+ HeaderName::from_static(MAX_LLM_MONTHLY_SPEND_REACHED_HEADER_NAME),
+ HeaderValue::from_static("true"),
+ )]
+ .into_iter()
+ .collect(),
+ ));
}
}
@@ -627,7 +625,6 @@ where
impl<S> Drop for TokenCountingStream<S> {
fn drop(&mut self) {
let state = self.state.clone();
- let is_llm_billing_enabled = state.config.is_llm_billing_enabled();
let claims = self.claims.clone();
let provider = self.provider;
let model = std::mem::take(&mut self.model);
@@ -641,14 +638,7 @@ impl<S> Drop for TokenCountingStream<S> {
provider,
&model,
tokens,
- // We're passing `false` here if LLM billing is not enabled
- // so that we don't write any records to the
- // `billing_events` table until we're ready to bill users.
- if is_llm_billing_enabled {
- claims.has_llm_subscription
- } else {
- false
- },
+ claims.has_llm_subscription,
Cents(claims.max_monthly_spend_in_cents),
Utc::now(),
)