diff --git a/src/app/dashboard/settings/pricing/page.js b/src/app/dashboard/settings/pricing/page.js new file mode 100644 index 0000000..ffcfe8d --- /dev/null +++ b/src/app/dashboard/settings/pricing/page.js @@ -0,0 +1,173 @@ +"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 ( +
+ Configure pricing rates for cost tracking and calculations +
++ 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: +
++ Custom Pricing: You can override default pricing for specific models. + Reset to defaults anytime to restore standard rates. +
+Pricing Rates Format
++ All rates are in dollars per million tokens ($/1M tokens). + Example: Input rate of 2.50 means $2.50 per 1,000,000 input tokens. +
+| Model | +Input | +Output | +Cached | +Reasoning | +Cache Creation | +
|---|---|---|---|---|---|
| {model} | + {pricingFields.map(field => ( ++ handlePricingChange(provider, model, field, e.target.value)} + className="w-20 px-2 py-1 text-right bg-bg-base border border-border rounded focus:outline-none focus:border-primary" + /> + | + ))} +