feat: 适配gpt-5-codex模型

This commit is contained in:
shaw
2025-09-16 09:01:41 +08:00
parent 646e62d6be
commit 51cb92d395
3 changed files with 19 additions and 2 deletions

View File

@@ -242,6 +242,14 @@ class CostCalculator {
* @returns {Object} 定价信息
*/
static getModelPricing(model = 'unknown') {
// 特殊处理gpt-5-codex 回退到 gpt-5如果没有专门定价
if (model === 'gpt-5-codex' && !MODEL_PRICING['gpt-5-codex']) {
const gpt5Pricing = MODEL_PRICING['gpt-5']
if (gpt5Pricing) {
console.log(`Using gpt-5 pricing as fallback for ${model}`)
return gpt5Pricing
}
}
return MODEL_PRICING[model] || MODEL_PRICING['unknown']
}
@@ -285,7 +293,7 @@ class CostCalculator {
* @returns {Object} 节省信息
*/
static calculateCacheSavings(usage, model = 'unknown') {
const pricing = this.getModelPricing(model)
const pricing = this.getModelPricing(model) // 已包含 gpt-5-codex 回退逻辑
const cacheReadTokens = usage.cache_read_input_tokens || 0
// 如果这些token不使用缓存需要按正常input价格计费