mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 09:38:02 +00:00
feat: 适配gpt-5-codex模型
This commit is contained in:
@@ -139,7 +139,7 @@ const handleResponses = async (req, res) => {
|
|||||||
let requestedModel = req.body?.model || null
|
let requestedModel = req.body?.model || null
|
||||||
|
|
||||||
// 如果模型是 gpt-5 开头且后面还有内容(如 gpt-5-2025-08-07),则覆盖为 gpt-5
|
// 如果模型是 gpt-5 开头且后面还有内容(如 gpt-5-2025-08-07),则覆盖为 gpt-5
|
||||||
if (requestedModel && requestedModel.startsWith('gpt-5-') && requestedModel !== 'gpt-5') {
|
if (requestedModel && requestedModel.startsWith('gpt-5-') && requestedModel !== 'gpt-5-codex') {
|
||||||
logger.info(`📝 Model ${requestedModel} detected, normalizing to gpt-5 for Codex API`)
|
logger.info(`📝 Model ${requestedModel} detected, normalizing to gpt-5 for Codex API`)
|
||||||
requestedModel = 'gpt-5'
|
requestedModel = 'gpt-5'
|
||||||
req.body.model = 'gpt-5' // 同时更新请求体中的模型
|
req.body.model = 'gpt-5' // 同时更新请求体中的模型
|
||||||
|
|||||||
@@ -265,6 +265,15 @@ class PricingService {
|
|||||||
return this.pricingData[modelName]
|
return this.pricingData[modelName]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 特殊处理:gpt-5-codex 回退到 gpt-5
|
||||||
|
if (modelName === 'gpt-5-codex' && !this.pricingData['gpt-5-codex']) {
|
||||||
|
const fallbackPricing = this.pricingData['gpt-5']
|
||||||
|
if (fallbackPricing) {
|
||||||
|
logger.info(`💰 Using gpt-5 pricing as fallback for ${modelName}`)
|
||||||
|
return fallbackPricing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 对于Bedrock区域前缀模型(如 us.anthropic.claude-sonnet-4-20250514-v1:0),
|
// 对于Bedrock区域前缀模型(如 us.anthropic.claude-sonnet-4-20250514-v1:0),
|
||||||
// 尝试去掉区域前缀进行匹配
|
// 尝试去掉区域前缀进行匹配
|
||||||
if (modelName.includes('.anthropic.') || modelName.includes('.claude')) {
|
if (modelName.includes('.anthropic.') || modelName.includes('.claude')) {
|
||||||
|
|||||||
@@ -242,6 +242,14 @@ class CostCalculator {
|
|||||||
* @returns {Object} 定价信息
|
* @returns {Object} 定价信息
|
||||||
*/
|
*/
|
||||||
static getModelPricing(model = 'unknown') {
|
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']
|
return MODEL_PRICING[model] || MODEL_PRICING['unknown']
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,7 +293,7 @@ class CostCalculator {
|
|||||||
* @returns {Object} 节省信息
|
* @returns {Object} 节省信息
|
||||||
*/
|
*/
|
||||||
static calculateCacheSavings(usage, model = 'unknown') {
|
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
|
const cacheReadTokens = usage.cache_read_input_tokens || 0
|
||||||
|
|
||||||
// 如果这些token不使用缓存,需要按正常input价格计费
|
// 如果这些token不使用缓存,需要按正常input价格计费
|
||||||
|
|||||||
Reference in New Issue
Block a user