Skip to content

feat: implement mixed provider pricing strategy for free/paid/sometimes-free tiers #2

@sadnow

Description

@sadnow

Context

We've added OpenAI and Google Gemini keys to opencode-zen. Both providers offer complex pricing:

  • OpenAI: Free tier with daily token allowance under data-sharing agreement, then paid
  • Google Gemini: Similar free tier deal with limits
  • OpenCode: Always free
  • Claude Max / Copilot: Subscription-based with monthly limits

Problem

Current budget orchestrator treats providers as either subscription or paid-per-token. Need hybrid support:

  • Free tier until daily/monthly limit reached
  • Automatic fallback when free tier exhausted
  • Preference for free providers when available

Requirements

1. New Provider Types

  • hybrid-free-then-paid: Free tier until limit, then paid
  • hybrid-free-daily: Daily free reset

2. Free Tier Tracking

  • Detect when limits reached (parse 429 errors, user config, heuristics)
  • Track usage against free tier limits
  • Reset counters at appropriate intervals
  • Fallback logic when exhausted

3. Provider Selection Priority

  1. Free tier available (opencode, openai/google within limits)
  2. Subscription with headroom (Claude Max, Copilot)
  3. Paid-per-token (when budget allows)

4. Parallel Agent Optimization

Distribute across free tiers for more parallel agents without cost.

5. Files to Modify

  • src/features/budget-orchestrator/
  • src/features/usage-tracker/
  • src/config/schema.ts

Success Criteria

  • System uses free tiers before paid
  • Automatic fallback when exhausted
  • Cost savings measurable
  • More parallel agents possible
  • All tests pass

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