-
-
Notifications
You must be signed in to change notification settings - Fork 317
Description
GLM-4.5 Model Support and Pricing Configuration
Problem Description
GLM-4.5 model pricing is not properly supported in ccusage, leading to incorrect cost calculations and discrepancies between expected and actual costs.
Current Behavior
When processing usage data for GLM-4.5 models, ccusage falls back to using pre-calculated costs from JSONL files instead of dynamically calculating costs based on GLM-4.5 pricing. This results in cost discrepancies such as:
- Expected cost: 6.72 (based on GLM-4.5 pricing)
- Actual displayed cost: 6.53 (based on fallback to pre-calculated costs)
- Discrepancy: 0.19 difference
Root Cause Analysis
-
GLM-4.5 Missing from LiteLLM Database
- GLM-4.5 model pricing is not available in the LiteLLM pricing database
- Current pricing lookup only supports models in: https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json
-
Limited Provider Prefix Support
- GLM-4.5 models exist in LiteLLM under different provider names:
deepinfra/zai-org/GLM-4.5vercel_ai_gateway/zai/glm-4.5
- Current DEFAULT_PROVIDER_PREFIXES only includes:
anthropic/,claude-*,openai/,azure/,openrouter/openai/ - Missing support for:
deepinfra/,vercel_ai_gateway/
- GLM-4.5 models exist in LiteLLM under different provider names:
-
Model Name Matching Issues
- When model name is "glm-4.5", the system can't find matching pricing because:
- No exact match for "glm-4.5"
- No provider prefix matches for deepinfra/vercel providers
- Falls back to fuzzy matching which may not find the correct pricing
- Ultimately uses pre-calculated costs from JSONL files
- When model name is "glm-4.5", the system can't find matching pricing because:
Expected GLM-4.5 Pricing
Based on available data:
- Input tokens: 0.60 per million tokens
- Output tokens: 2.2 per million tokens
- Cache read tokens: 0.11 per million tokens
Proposed Solutions
Option 1: Add Provider Prefix Support
Add GLM-4.5 provider prefixes to DEFAULT_PROVIDER_PREFIXES:
const DEFAULT_PROVIDER_PREFIXES = [
'anthropic/',
'claude-3-5-',
'claude-3-',
'claude-',
'openai/',
'azure/',
'openrouter/openai/',
'deepinfra/', // Add for GLM-4.5 support
'vercel_ai_gateway/', // Add for GLM-4.5 support
];Option 2: Add Hardcoded GLM-4.5 Pricing
Add GLM-4.5 pricing configuration in the prefetch functions similar to other model-specific configurations.
Option 3: Enhance Model Matching Logic
Improve the model matching algorithm to better handle variations in model names and provider prefixes.
Impact
This affects users who:
- Use GLM-4.5 models in their Claude Code sessions
- Rely on accurate cost tracking and reporting
- Need to budget and monitor API usage costs
Additional Context
The issue was discovered when users replaced Claude model references with GLM-4.5 in their usage data but noticed that cost calculations were inconsistent and incorrect. The system should properly support GLM-4.5 pricing to provide accurate cost analysis.
Files to Modify
packages/internal/src/pricing.ts- Add provider prefixesapps/ccusage/src/_macro.ts- Add GLM-4.5 pricing configurationapps/codex/src/_macro.ts- Add GLM-4.5 pricing configuration (if needed)