Credits API (Python)

Methods, examples, and parameters for client.credits.

Module Overview

Inspect balances, transaction history, and package purchases for billing workflows.

Available Methods

  • client.credits.getBalance() - Read current remaining credit balance.
  • client.credits.listTransactions() - List historical credit movements.
  • client.credits.purchase() - Create a payment intent for a package.

Examples

Python
from therouter import TheRouter.ai

client = TheRouter.ai(
    api_key=os.getenv("THEROUTER_API_KEY"),
    base_url="https://api.therouter.ai/v1",
)

balance = client.credits.get_balance()
transactions = client.credits.list_transactions(limit=10)

print(balance.total_credits, len(transactions.data))
credits-response.json
{
  "id": "req_01HXYZ123",
  "module": "credits",
  "status": "ok"
}

Parameter Types

NameTypeRequiredDescription
tenant_id
stringTarget tenant if using admin credentials.
limit
integerNumber of transaction rows to return.
status
stringFilter by pending, completed, or failed.
SDK parity
Method signatures are aligned across SDKs so migration between TypeScript and Python stays predictable.