feat:AI 토큰 단가 설정 기능 추가 (DB 기반)
- ai_pricing_configs 테이블 마이그레이션 생성 (기본 시드 데이터 포함) - AiPricingConfig 모델 추가 (캐시 적용 단가/환율 조회) - AiReportService 하드코딩 단가를 DB 조회로 변경 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Tenants\AiPricingConfig;
|
||||
use App\Models\Tenants\AiReport;
|
||||
use App\Models\Tenants\AiTokenUsage;
|
||||
use App\Models\Tenants\Card;
|
||||
@@ -398,12 +399,13 @@ private function saveTokenUsage(array $apiResult, string $model, string $menuNam
|
||||
$completionTokens = $usage['candidatesTokenCount'] ?? 0;
|
||||
$totalTokens = $usage['totalTokenCount'] ?? 0;
|
||||
|
||||
// Gemini 2.0 Flash 기준 단가 (USD per token)
|
||||
$inputPricePerToken = 0.10 / 1_000_000; // $0.10 / 1M tokens
|
||||
$outputPricePerToken = 0.40 / 1_000_000; // $0.40 / 1M tokens
|
||||
// DB 단가 조회 (fallback: 하드코딩 기본값)
|
||||
$pricing = AiPricingConfig::getActivePricing('gemini');
|
||||
$inputPricePerToken = $pricing ? (float) $pricing->input_price_per_million / 1_000_000 : 0.10 / 1_000_000;
|
||||
$outputPricePerToken = $pricing ? (float) $pricing->output_price_per_million / 1_000_000 : 0.40 / 1_000_000;
|
||||
|
||||
$costUsd = ($promptTokens * $inputPricePerToken) + ($completionTokens * $outputPricePerToken);
|
||||
$exchangeRate = (float) config('services.gemini.exchange_rate', 1400);
|
||||
$exchangeRate = AiPricingConfig::getExchangeRate();
|
||||
$costKrw = $costUsd * $exchangeRate;
|
||||
|
||||
AiTokenUsage::create([
|
||||
|
||||
Reference in New Issue
Block a user