ccproxy.plugins.pricing.loader¶
ccproxy.plugins.pricing.loader
¶
Pricing data loader and format converter for LiteLLM pricing data.
PricingLoader
¶
Loads and converts pricing data from LiteLLM format to internal format.
extract_claude_models
staticmethod
¶
Extract Claude model entries from LiteLLM data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
litellm_data
|
dict[str, Any]
|
Raw LiteLLM pricing data |
required |
verbose
|
bool
|
Whether to log individual model discoveries |
True
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with only Claude models |
Source code in ccproxy/plugins/pricing/loader.py
extract_openai_models
staticmethod
¶
Extract OpenAI model entries from LiteLLM data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
litellm_data
|
dict[str, Any]
|
Raw LiteLLM pricing data |
required |
verbose
|
bool
|
Whether to log individual model discoveries |
True
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with only OpenAI models |
Source code in ccproxy/plugins/pricing/loader.py
extract_anthropic_models
staticmethod
¶
Extract all Anthropic model entries from LiteLLM data.
This includes Claude models and any other Anthropic models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
litellm_data
|
dict[str, Any]
|
Raw LiteLLM pricing data |
required |
verbose
|
bool
|
Whether to log individual model discoveries |
True
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with all Anthropic models |
Source code in ccproxy/plugins/pricing/loader.py
extract_models_by_provider
staticmethod
¶
Extract models by provider from LiteLLM data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
litellm_data
|
dict[str, Any]
|
Raw LiteLLM pricing data |
required |
provider
|
Literal['anthropic', 'openai', 'all', 'claude']
|
Provider to extract models for ("anthropic", "openai", "claude", or "all") |
'all'
|
verbose
|
bool
|
Whether to log individual model discoveries |
True
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with models from specified provider(s) |
Source code in ccproxy/plugins/pricing/loader.py
convert_to_internal_format
staticmethod
¶
Convert LiteLLM pricing format to internal format.
LiteLLM format uses cost per token, we use cost per 1M tokens as Decimal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
models
|
dict[str, Any]
|
Models in LiteLLM format |
required |
map_to_claude
|
bool
|
Whether to map model names to Claude equivalents |
True
|
verbose
|
bool
|
Whether to log individual model conversions |
True
|
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Decimal]]
|
Dictionary in internal pricing format |
Source code in ccproxy/plugins/pricing/loader.py
load_pricing_from_data
staticmethod
¶
Load and convert pricing data from LiteLLM format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
litellm_data
|
dict[str, Any]
|
Raw LiteLLM pricing data |
required |
provider
|
Literal['anthropic', 'openai', 'all', 'claude']
|
Provider to load pricing for ("anthropic", "openai", "all", or "claude") "claude" is kept for backward compatibility and extracts only Claude models |
'claude'
|
map_to_claude
|
bool
|
Whether to map model names to Claude equivalents |
True
|
verbose
|
bool
|
Whether to enable verbose logging |
True
|
Returns:
| Type | Description |
|---|---|
PricingData | None
|
Validated pricing data as PricingData model, or None if invalid |
Source code in ccproxy/plugins/pricing/loader.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | |
validate_pricing_data
staticmethod
¶
Validate pricing data using Pydantic models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pricing_data
|
Any
|
Pricing data to validate (dict or PricingData) |
required |
verbose
|
bool
|
Whether to enable verbose logging |
True
|
Returns:
| Type | Description |
|---|---|
PricingData | None
|
Valid PricingData model or None if validation fails |