Skip to content

GLM-4.5 Model Support and Pricing Configuration #656

@cobra91

Description

@cobra91

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

  1. GLM-4.5 Missing from LiteLLM Database

  2. Limited Provider Prefix Support

    • GLM-4.5 models exist in LiteLLM under different provider names:
      • deepinfra/zai-org/GLM-4.5
      • vercel_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/
  3. 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

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:

  1. Use GLM-4.5 models in their Claude Code sessions
  2. Rely on accurate cost tracking and reporting
  3. 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 prefixes
  • apps/ccusage/src/_macro.ts - Add GLM-4.5 pricing configuration
  • apps/codex/src/_macro.ts - Add GLM-4.5 pricing configuration (if needed)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions