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

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: TimestampedModel

DailyBillingRecord 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

ForeignKey to Account

Account (related name: daily_billing_records)

Type:

Type

account_id

Internal field, use account instead.

charge_type

CharField

Charge type

Choices:

  • completion

  • plugin

  • tool

Type:

Type

completion_tokens

IntegerField

Completion tokens

Type:

Type

created_at

DateTimeField

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

date

DateField

Date

Type:

Type

get_charge_type_display(*, field=<django.db.models.CharField: charge_type>)

Shows the label of the charge_type. See get_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. See get_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. See get_previous_by_FOO() for more information.

get_provider_display(*, field=<django.db.models.CharField: provider>)

Shows the label of the provider. See get_FOO_display() for more information.

id

BigAutoField

Primary key: ID

Type:

Type

objects = <django.db.models.Manager object>
prompt_tokens

IntegerField

Prompt tokens

Type:

Type

provider

CharField

Provider

Choices:

  • openai

  • metaai

  • googleai

Type:

Type

total_tokens

IntegerField

Total tokens

Type:

Type

updated_at

DateTimeField

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

ForeignKey to User

User (related name: daily_billing_records)

Type:

Type

user_id

Internal field, use user instead.