Asynchronous Tasks
- smarter.apps.account.tasks.create_charge(*args, **kwargs)
Create a charge record for a user or account.
This task is automatically retried on failure, with backoff and maximum retries configured via Celery settings.
- Parameters:
resource_locator – String. The TimestampedModel.resource_locator of the resource that this charge is associated with.
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.
Example usage:
# Create a charge for a user profile create_charge.delay(resource_locator="record_123", charge_type="usage", prompt_tokens=100, completion_tokens=50, total_tokens=150)
- smarter.apps.account.tasks.aggregate_records()
Top-level Celery task for aggregating charge records.
This task triggers the aggregation of daily billing records by calling
aggregate_charges(). It is typically scheduled via Celery Beat.Example usage:
# Trigger aggregation from code aggregate_records.delay() # Schedule with Celery Beat for daily aggregation # (see your Celery Beat configuration)