Asynchronous Tasks
- smarter.apps.account.tasks.create_charge(*args, **kwargs)
Create a charge record for a user or account.
- Parameters:
user_profile_id – Integer, optional. The ID of the user_profile for whom the charge is created.
session_key – String, optional. The session key associated with the charge.
provider – String, optional. The provider for the charge.
charge_type – String, optional. The type of charge (e.g., usage, subscription).
prompt_tokens – Integer, optional. Number of prompt tokens used.
completion_tokens – Integer, optional. Number of completion tokens used.
total_tokens – Integer, optional. Total number of tokens used.
model – String, optional. The model used for the charge.
reference – String, optional. Reference information for the charge.
Note
This task is automatically retried on failure, with backoff and maximum retries configured via Celery settings.
Example usage:
# Create a charge for a user profile create_charge.delay(user_profile_id=123, charge_type="usage", prompt_tokens=100, completion_tokens=50)
- smarter.apps.account.tasks.aggregate_charges()
Top-level Celery task for aggregating charge records.
This task triggers the aggregation of daily billing records by calling
aggregate_daily_billing_records(). It is typically scheduled via Celery Beat.Example usage:
# Trigger aggregation from code aggregate_charges.delay() # Schedule with Celery Beat for daily aggregation # (see your Celery Beat configuration)
- smarter.apps.account.tasks.aggregate_daily_billing_records()
Aggregate daily billing records and delete individual Charge records.
This Celery task is typically scheduled via Celery Beat and is designed to be idempotent, meaning it can be safely run multiple times without causing duplicate records.
Note
This task aggregates all charges for each user/account/date/charge_type combination,
updates or creates a corresponding DailyBillingRecord, and deletes the original Charge records.
Example usage:
# Trigger aggregation from code aggregate_daily_billing_records.delay() # Schedule with Celery Beat for daily aggregation # (see your Celery Beat configuration)