ModelPricing
Base classes¶
| Name | Children | Inherits |
|---|---|---|
| Schema schemez.schema Base class for configuration models. |
â‹” Inheritance diagram¶
graph TD
3326076699["chat_model.ModelPricing"]
330168112["schema.Schema"]
3879467795["main.BaseModel"]
2751680898["builtins.object"]
330168112 --> 3326076699
3879467795 --> 330168112
2751680898 --> 3879467795
🛈 DocStrings¶
Bases: Schema
Pricing information for chat models.
Source code in src/tokonomics/models/chat_model.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
cache_creation_input_token_cost
class-attribute
instance-attribute
¶
Cost per token for cache creation.
cache_read_input_token_cost
class-attribute
instance-attribute
¶
Cost per token for cache reads.
input_cost_above_128k
class-attribute
instance-attribute
¶
Input cost per token above 128k context.
input_cost_above_200k
class-attribute
instance-attribute
¶
Input cost per token above 200k context.
input_cost_flex
class-attribute
instance-attribute
¶
Input cost per token for flex requests.
input_cost_per_audio_second
class-attribute
instance-attribute
¶
Cost per second of audio input.
input_cost_per_image
class-attribute
instance-attribute
¶
Cost per image input.
input_cost_per_token
class-attribute
instance-attribute
¶
Standard input cost per token.
input_cost_per_video_second
class-attribute
instance-attribute
¶
Cost per second of video input.
input_cost_priority
class-attribute
instance-attribute
¶
Input cost per token for priority requests.
output_cost_above_128k
class-attribute
instance-attribute
¶
Output cost per token above 128k context.
output_cost_above_200k
class-attribute
instance-attribute
¶
Output cost per token above 200k context.
output_cost_flex
class-attribute
instance-attribute
¶
Output cost per token for flex requests.
output_cost_per_reasoning_token
class-attribute
instance-attribute
¶
Cost per reasoning output token for models like o1.
output_cost_per_token
class-attribute
instance-attribute
¶
Standard output cost per token.
output_cost_priority
class-attribute
instance-attribute
¶
Output cost per token for priority requests.
tiered_pricing
class-attribute
instance-attribute
¶
tiered_pricing: list[TieredPricingTier] | None = None
Volume-based tiered pricing if available.
calculate_cost
¶
calculate_cost(
*,
input_tokens: int = 0,
cache_write_tokens: int = 0,
cache_read_tokens: int = 0,
input_audio_tokens: int = 0,
cache_audio_read_tokens: int = 0,
output_tokens: int = 0,
) -> Decimal | None
Calculate cost based on usage mirroring pydantic-ai RunUsage.
Uses contextual pricing if token count exceeds thresholds, otherwise uses standard input/output cost per token.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_tokens
|
int
|
Total number of input/prompt tokens |
0
|
cache_write_tokens
|
int
|
Total number of tokens written to the cache |
0
|
cache_read_tokens
|
int
|
Total number of tokens read from the cache |
0
|
input_audio_tokens
|
int
|
Total number of audio input tokens |
0
|
cache_audio_read_tokens
|
int
|
Total number of audio tokens read from the cache |
0
|
output_tokens
|
int
|
Total number of output/completion tokens |
0
|
Returns:
| Type | Description |
|---|---|
Decimal | None
|
Total cost or None if pricing unavailable |
Source code in src/tokonomics/models/chat_model.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |