Skip to content

Routing page: adopt shared cost engine with cached token pricing #11

Description

@aditisaluja5

Problem

The routing economics page (lib/routing/calc.ts) uses a naive cost calculation for frontier API pricing:

cost = (tokensIn / 1M) × pricePerMInput + (tokensOut / 1M) × pricePerMOutput

This overstates frontier API cost because it ignores cached token discounts. Cloud APIs (OpenAI, Anthropic, Google) charge ~50% less for recently-seen input tokens. Without modeling this, the self-hosted savings shown on the routing page are inflated.

What needs to change

  1. Use the shared cost engine being built in Cost comparison: self-hosted on-prem vs cloud API cost per million tokens #10. That engine implements the blended cost model:

    • Input tokens (full price)
    • Cached input tokens (~50% discount, based on cache hit rate)
    • Output tokens
    • Breakeven utilization curve (self-hosted GPUs aren't always at 100%)
  2. Add pricePerMCached to FrontierModel interface — currently only has pricePerMInput and pricePerMOutput. Needs a third field for cached input token pricing.

  3. Add cache hit rate input per tier — the routing page lets you configure tokens in/out per tier, but has no cache hit rate slider. Different tiers will have different cache rates (e.g., RAG/doc processing = high cache, conversational = low).

  4. Add utilization modeling — current self-hosted calc assumes GPUs run 24/7 at full capacity. In reality, utilization varies. The standalone calculator models the breakeven utilization % where self-hosting becomes cheaper.

Context

Current routing calc location

  • lib/routing/calc.ts — computeFrontierCost() and computeSelfHostedCost()
  • lib/pricing/frontier-models.ts — model pricing catalog (needs pricePerMCached field)

Blocked by

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    cost-modelingCost estimation and comparison features

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions