mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 00:53:33 +00:00
feat: 实现OpenAI账户管理和统一调度系统
- 新增 OpenAI 账户管理服务,支持多账户轮询和负载均衡 - 实现统一的 OpenAI API 调度器,智能选择最优账户 - 优化成本计算器,支持更精确的 token 计算 - 更新模型定价数据,包含最新的 OpenAI 模型价格 - 增强 API Key 管理,支持更灵活的配额控制 - 改进管理界面,添加教程视图和账户分组管理 - 优化限流配置组件,提供更直观的用户体验 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -81,11 +81,29 @@ class CostCalculator {
|
||||
|
||||
if (pricingData) {
|
||||
// 转换动态价格格式为内部格式
|
||||
const inputPrice = (pricingData.input_cost_per_token || 0) * 1000000 // 转换为per 1M tokens
|
||||
const outputPrice = (pricingData.output_cost_per_token || 0) * 1000000
|
||||
const cacheReadPrice = (pricingData.cache_read_input_token_cost || 0) * 1000000
|
||||
|
||||
// OpenAI 模型的特殊处理:
|
||||
// - 如果没有 cache_creation_input_token_cost,缓存创建按普通 input 价格计费
|
||||
// - Claude 模型有专门的 cache_creation_input_token_cost
|
||||
let cacheWritePrice = (pricingData.cache_creation_input_token_cost || 0) * 1000000
|
||||
|
||||
// 检测是否为 OpenAI 模型(通过模型名或 litellm_provider)
|
||||
const isOpenAIModel =
|
||||
model.includes('gpt') || model.includes('o1') || pricingData.litellm_provider === 'openai'
|
||||
|
||||
if (isOpenAIModel && !pricingData.cache_creation_input_token_cost && cacheCreateTokens > 0) {
|
||||
// OpenAI 模型:缓存创建按普通 input 价格计费
|
||||
cacheWritePrice = inputPrice
|
||||
}
|
||||
|
||||
pricing = {
|
||||
input: (pricingData.input_cost_per_token || 0) * 1000000, // 转换为per 1M tokens
|
||||
output: (pricingData.output_cost_per_token || 0) * 1000000,
|
||||
cacheWrite: (pricingData.cache_creation_input_token_cost || 0) * 1000000,
|
||||
cacheRead: (pricingData.cache_read_input_token_cost || 0) * 1000000
|
||||
input: inputPrice,
|
||||
output: outputPrice,
|
||||
cacheWrite: cacheWritePrice,
|
||||
cacheRead: cacheReadPrice
|
||||
}
|
||||
usingDynamicPricing = true
|
||||
} else {
|
||||
@@ -126,6 +144,13 @@ class CostCalculator {
|
||||
cacheWrite: this.formatCost(cacheWriteCost),
|
||||
cacheRead: this.formatCost(cacheReadCost),
|
||||
total: this.formatCost(totalCost)
|
||||
},
|
||||
// 添加调试信息
|
||||
debug: {
|
||||
isOpenAIModel: model.includes('gpt') || model.includes('o1'),
|
||||
hasCacheCreatePrice: !!pricingData?.cache_creation_input_token_cost,
|
||||
cacheCreateTokens,
|
||||
cacheWritePriceUsed: pricing.cacheWrite
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user