Skip to content

Create a pricing registry for major models and compute estimated cost per request based on token usage #464

Closed

Description

@psschwei

Description:
Create a pricing registry for major models and compute estimated cost per request based on token usage.

Detailed Requirements:

  1. Create mellea/telemetry/pricing.py module with:
    • PricingRegistry class with model pricing data
    • Pricing format: {model_id: {input_per_1k: float, output_per_1k: float}}
    • Default pricing for major models (OpenAI GPT-4, GPT-3.5, Claude, etc.)
    • Support for custom pricing overrides via config
  2. Create cost counter:
    • mellea.llm.cost.usd - Estimated cost in USD (counter)
  3. Create helper function:
    • compute_cost(model, input_tokens, output_tokens) -> float
    • record_cost(cost_usd, model, backend)
  4. Integrate with token usage recording in backends
  5. Handle unknown models gracefully (log warning, skip cost recording)

Files to Create:

  • mellea/telemetry/pricing.py

Files to Modify:

  • mellea/telemetry/metrics.py - Add cost counter
  • mellea/telemetry/backend_instrumentation.py - Add cost recording

Default Pricing (example - to be verified):

Model Input $/1K tokens Output $/1K tokens
gpt-4-turbo 0.01 0.03
gpt-4 0.03 0.06
gpt-3.5-turbo 0.0005 0.0015
claude-3-opus 0.015 0.075
claude-3-sonnet 0.003 0.015

Environment Variables:

Variable Default Description
MELLEA_PRICING_FILE - Path to custom pricing JSON

Acceptance Criteria:

  • Pricing registry with default model prices
  • Cost computed and recorded per request
  • Custom pricing overrides supported
  • Unknown models handled gracefully

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions