"use client"; import { useState, useEffect } from "react"; import { useRouter } from "next/navigation"; import Card from "@/shared/components/Card"; import PricingModal from "@/shared/components/PricingModal"; export default function PricingSettingsPage() { const router = useRouter(); const [showModal, setShowModal] = useState(false); const [currentPricing, setCurrentPricing] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { loadPricing(); }, []); const loadPricing = async () => { setLoading(true); try { const response = await fetch("/api/pricing"); if (response.ok) { const data = await response.json(); setCurrentPricing(data); } } catch (error) { console.error("Failed to load pricing:", error); } finally { setLoading(false); } }; const handlePricingUpdated = () => { loadPricing(); }; // Count total models with pricing const getModelCount = () => { if (!currentPricing) return 0; let count = 0; for (const provider in currentPricing) { count += Object.keys(currentPricing[provider]).length; } return count; }; // Get providers list const getProviders = () => { if (!currentPricing) return []; return Object.keys(currentPricing).sort(); }; return (
{/* Header */}

Pricing Settings

Configure pricing rates for cost tracking and calculations

{/* Quick Stats */}
Total Models
{loading ? "..." : getModelCount()}
Providers
{loading ? "..." : getProviders().length}
Status
{loading ? "..." : "Active"}
{/* Info Section */}

How Pricing Works

Cost Calculation: Costs are calculated based on token usage and pricing rates. Each request's cost is determined by: (input_tokens × input_rate) + (output_tokens × output_rate) + (cached_tokens × cached_rate)

Pricing Format: All rates are in dollars per million tokens ($/1M tokens). Example: An input rate of 2.50 means $2.50 per 1,000,000 input tokens.

Token Types:

  • Input: Standard prompt tokens
  • Output: Completion/response tokens
  • Cached: Cached input tokens (typically 50% of input rate)
  • Reasoning: Special reasoning/thinking tokens (fallback to output rate)
  • Cache Creation: Tokens used to create cache entries (fallback to input rate)

Custom Pricing: You can override default pricing for specific models. Reset to defaults anytime to restore standard rates.

{/* Current Pricing Preview */}

Current Pricing Overview

{loading ? (
Loading pricing data...
) : currentPricing ? (
{Object.keys(currentPricing).slice(0, 5).map(provider => (
{provider.toUpperCase()}:{" "} {Object.keys(currentPricing[provider]).length} models
))} {Object.keys(currentPricing).length > 5 && (
+ {Object.keys(currentPricing).length - 5} more providers
)}
) : (
No pricing data available
)}
{/* Pricing Modal */} {showModal && ( setShowModal(false)} onSave={handlePricingUpdated} /> )}
); }