dataflow.auth.credits¶

Attributes¶

Classes¶

CreditsManager

Manager for user credits and usage tracking.

UsageRecord

Record of agent usage.

Module Contents¶

class dataflow.auth.credits.CreditsManager¶

Manager for user credits and usage tracking.

async check_credits(user_id: str, required_credits: float = 1.0) bool¶

Check if user has sufficient credits.

Parameters:
  • user_id (str) – User ID

  • required_credits (float) – Required credits for the operation

Returns:

True if user has sufficient credits, False otherwise

Return type:

bool

async deduct_credits(user_id: str, amount: float) bool¶

Deduct credits from user account.

Parameters:
  • user_id (str) – User ID

  • amount (float) – Amount to deduct

Returns:

True if deduction was successful, False otherwise

Return type:

bool

async log_usage(usage: UsageRecord) bool¶

Log agent usage for billing and analytics.

Parameters:

usage (UsageRecord) – Usage record

Returns:

True if logging was successful, False otherwise

Return type:

bool

property client¶

Lazy-loaded Supabase admin client.

config¶
class dataflow.auth.credits.UsageRecord(/, **data: Any)¶

Bases: pydantic.BaseModel

Record of agent usage.

Parameters:

data (Any)

agent_id: str¶
conversation_id: str | None = None¶
cost: decimal.Decimal¶
created_at: datetime.datetime | None = None¶
token_count: int¶
user_id: str¶
dataflow.auth.credits.logger¶