DailyBillingRecord Model
Account DailyBillingRecord Model
This module defines the DailyBillingRecord model for aggregating and tracking daily billing data
for accounts and users. It enables efficient reporting and analytics by recording daily usage and billing
information per account, user, provider, and charge type.
Classes & Constants
DailyBillingRecord: Aggregates daily usage and billing data for each account and user.
Key Features
Tracks provider, charge type, and token usage for each billing day.
Enforces uniqueness for each (account, user, provider, date) combination.
Integrates with Smarter logging and account models.
Example
from smarter.apps.account.models import DailyBillingRecord
record = DailyBillingRecord.objects.create(
account=account,
user=user,
provider="openai",
date=date.today(),
charge_type="completion",
prompt_tokens=100,
completion_tokens=200,
total_tokens=300
)
- class smarter.apps.account.models.daily_billing_record.DailyBillingRecord(*args, **kwargs)[source]
Bases:
TimestampedModelDailyBillingRecord model for aggregating daily account charges.
Tracks daily usage and billing data for each account, user, provider, and charge type, enabling efficient reporting and analytics.
- Parameters:
account – ForeignKey to
Account. The account being billed.user – ForeignKey to
django.contrib.auth.models.User. The user associated with the record.provider – String. The LLM provider (e.g., OpenAI).
date – Date. The billing date for the record.
charge_type – String. The type of charge (e.g., completion, plugin, tool).
prompt_tokens – Integer. Number of prompt tokens used.
completion_tokens – Integer. Number of completion tokens used.
total_tokens – Integer. Total tokens used.
Example usage:
record = DailyBillingRecord.objects.create( account=account, user=user, provider="openai", date=date.today(), charge_type="completion", prompt_tokens=100, completion_tokens=200, total_tokens=300 )
See also
Charge,Account- Parameters:
id (Unknown) – Primary key: ID
created_at (Unknown) – Created at
updated_at (Unknown) – Updated at
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- exception NotUpdated
Bases:
ObjectNotUpdated,DatabaseError
- account
-
Account (related name:
daily_billing_records)- Type:
Type
- completion_tokens
-
Completion tokens
- Type:
Type
- created_at
-
Created at
Timestamp indicating when the model instance was created.
This field is automatically set to the current date and time when the instance is first created. It is indexed in the database for efficient querying.
- Type:
Type
- get_charge_type_display(*, field=<django.db.models.CharField: charge_type>)
Shows the label of the
charge_type. Seeget_FOO_display()for more information.
- get_next_by_date(*, field=<django.db.models.DateField: date>, is_next=True, **kwargs)
Finds next instance based on
date. Seeget_next_by_FOO()for more information.
- get_previous_by_date(*, field=<django.db.models.DateField: date>, is_next=False, **kwargs)
Finds previous instance based on
date. Seeget_previous_by_FOO()for more information.
- get_provider_display(*, field=<django.db.models.CharField: provider>)
Shows the label of the
provider. Seeget_FOO_display()for more information.
- id
-
Primary key: ID
- Type:
Type
- objects = <django.db.models.Manager object>
- prompt_tokens
-
Prompt tokens
- Type:
Type
- total_tokens
-
Total tokens
- Type:
Type
- updated_at
-
Updated at
Timestamp indicating when the model instance was last updated.
This field is automatically updated to the current date and time whenever the instance is saved. It is indexed in the database for efficient querying.
- Type:
Type
- user
ForeignKeytoUserUser (related name:
daily_billing_records)- Type:
Type