pydanticai_cost
Class info¶
Classes¶
| Name | Children | Inherits |
|---|---|---|
| Usage tokonomics.pydanticai_cost Protocol matching pydantic-ai's Usage object structure. |
🛈 DocStrings¶
Integration with pydantic-ai cost calculations.
Usage
¶
Bases: Protocol
Protocol matching pydantic-ai's Usage object structure.
Source code in src/tokonomics/pydanticai_cost.py
calculate_pydantic_cost
async
¶
calculate_pydantic_cost(
model: str, usage: Usage, *, cache_timeout: int = 86400
) -> TokenCosts | None
calculate_pydantic_cost(
model: str, usage: Usage | None, *, cache_timeout: int = 86400
) -> TokenCosts | None
Calculate costs from a pydantic-ai Usage object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Name of the model used (e.g. "gpt-4", "openai:gpt-3.5-turbo") |
required |
usage
|
Usage | None
|
Token usage information from pydantic-ai |
required |
cache_timeout
|
int
|
Number of seconds to keep prices in cache (default: 24 hours) |
86400
|
Returns:
| Type | Description |
|---|---|
TokenCosts | None
|
TokenCosts | None: Detailed cost breakdown if pricing data available |