Skip to content

CRITICAL: Fix cost calculation formula causing near-zero costs#22

Merged
spenceriam merged 1 commit intomainfrom
fix/compilation-error-syntax
Sep 21, 2025
Merged

CRITICAL: Fix cost calculation formula causing near-zero costs#22
spenceriam merged 1 commit intomainfrom
fix/compilation-error-syntax

Conversation

@spenceriam
Copy link
Owner

🚨 Critical Fix: Cost Calculation Issue

Problem

The cost calculation formula was using division by 1000 instead of direct multiplication, causing:

  • ❌ Near-zero cost values in UI
  • ❌ Inaccurate billing tracking
  • ❌ Vercel deployment compilation issues

Root Cause

// ❌ Wrong formula (was dividing by 1000)
const promptCost = (usage.prompt_tokens / 1000) * parseFloat(selectedModel.pricing.prompt)

// ✅ Correct formula (direct multiplication)
const promptCost = usage.prompt_tokens * promptPrice

Solution

Fixed cost calculation in all three functions:

  • generateCurrentPhase: Fixed /1000 division → direct multiplication
  • generateWithData: Fixed /1000 division → direct multiplication
  • approveAndProceed: Fixed /1000 division → direct multiplication

Impact

  • Build Success: Vercel deployments will now compile properly
  • Accurate Costs: Cost calculations match OpenRouter billing exactly
  • Better UX: Users see real cost tracking instead of $0.0001 values
  • Debug Logging: Added clear cost logging for debugging

Testing

  • ✅ Local build passes: npm run build successful
  • ✅ All cost calculation paths fixed
  • ✅ Maintains existing functionality

Priority: Critical - Fixes deployment blocking issue and core cost tracking functionality.

Fixed cost calculation in all three functions:
- generateCurrentPhase: Fixed /1000 division to direct multiplication
- generateWithData: Fixed /1000 division to direct multiplication
- approveAndProceed: Fixed /1000 division to direct multiplication

Root cause: Cost formula was dividing tokens by 1000 instead of
using direct token count × per-token price multiplication.

Result: Costs will now match OpenRouter billing accurately instead
of showing near-zero values.

This fixes Vercel deployment issues and ensures accurate cost tracking
for all AI model usage across the three-phase workflow.
@vercel
Copy link

vercel bot commented Sep 21, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
open-spec Ready Ready Preview Comment Sep 21, 2025 9:29pm

@spenceriam spenceriam merged commit e4ed0f7 into main Sep 21, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant