73 lines
4.1 KiB
Go
73 lines
4.1 KiB
Go
package billing_setting
|
|
|
|
import "github.com/QuantumNous/new-api/constant"
|
|
|
|
// deepSeekPeak is the legacy built-in schedule used by the original DeepSeek
|
|
// model expressions. Provider-specific pricing below uses deepSeekPeakAllDays.
|
|
const deepSeekPeak = `weekday("Asia/Shanghai") >= 1 && weekday("Asia/Shanghai") <= 5 && ((hour("Asia/Shanghai") >= 9 && hour("Asia/Shanghai") < 12) || (hour("Asia/Shanghai") >= 14 && hour("Asia/Shanghai") < 18))`
|
|
|
|
// deepSeekPeakAllDays follows the actual upstream schedule configured for the
|
|
// official token group: the two peak windows apply every day of the week.
|
|
const deepSeekPeakAllDays = `((hour("Asia/Shanghai") >= 9 && hour("Asia/Shanghai") < 12) || (hour("Asia/Shanghai") >= 14 && hour("Asia/Shanghai") < 18))`
|
|
|
|
const deepSeekFlashExpr = deepSeekPeak + ` ? tier("peak", p * 0.3 + cr * 0.006 + c * 1.2) : tier("off_peak", p * 0.15 + cr * 0.003 + c * 0.6)`
|
|
|
|
const (
|
|
// DeepSeekOfficialGroup is the user-token group whose official pricing is
|
|
// selected for compatible/custom channels as well as native DeepSeek ones.
|
|
DeepSeekOfficialGroup = "Deepseek官Key"
|
|
DeepSeekOfficialGroupRatio = 0.45
|
|
)
|
|
|
|
// deepSeekFlashOfficialExpr uses the official Flash base prices. The cache
|
|
// prices are raised slightly so that the shared 0.45 group ratio still covers
|
|
// the upstream cache-read prices shown for the official key.
|
|
const deepSeekFlashOfficialExpr = deepSeekPeakAllDays + ` ? tier("peak", p * 2 + cr * 0.066667 + c * 8) : tier("off_peak", p * 1 + cr * 0.033334 + c * 4)`
|
|
|
|
// deepSeekV4ProOfficialExpr follows the official DeepSeek V4 Pro base prices.
|
|
const deepSeekV4ProOfficialExpr = deepSeekPeakAllDays + ` ? tier("peak", p * 9 + cr * 0.30 + c * 27) : tier("off_peak", p * 4.5 + cr * 0.15 + c * 13.5)`
|
|
|
|
// Built-in token prices use actual USD per million tokens. Keep new model
|
|
// defaults here instead of splitting them across the legacy ratio tables.
|
|
var builtinBillingExpr = map[string]string{
|
|
// https://developers.openai.com/api/docs/pricing (Standard, 2026-09-09).
|
|
// The Images API reports image output in output_tokens, normalized to c.
|
|
"gpt-image-2": `tier("standard", p * 5 + cr * 1.25 + img * 8 + img_cr * 2 + c * 30)`,
|
|
"gpt-image-2.5-sunburst": `tier("standard", p * 5 + cr * 1.25 + img * 8 + img_cr * 2 + c * 30)`,
|
|
"gpt-image-2.5-flare": `tier("standard", p * 5 + cr * 1.25 + img * 8 + img_cr * 2 + c * 30)`,
|
|
// https://developers.openai.com/api/docs/models/gpt-6-astra
|
|
// Standard pricing; the long-context rates apply to the whole request.
|
|
// Do not infer service-tier discounts from incoming request parameters:
|
|
// channels filter service_tier by default, so it may not reach the upstream.
|
|
"gpt-6-astra": `len <= 272000 ? tier("standard", p * 10 + c * 50 + cr * 1 + cc * 12.5) : tier("long_context", p * 20 + c * 75 + cr * 2 + cc * 25)`,
|
|
// https://api-docs.deepseek.com/quick_start/pricing (2026-10-17). Off-peak
|
|
// is half the peak price. deepseek-v4-flash and deepseek-v4-flash-vision-exp
|
|
// run on V4.1 Flash and bill at the Flash price. Images bill as input
|
|
// tokens, and there is no cache-write price.
|
|
"deepseek-flash": deepSeekFlashExpr,
|
|
"deepseek-v4-flash": deepSeekFlashExpr,
|
|
"deepseek-v4-flash-vision-exp": deepSeekFlashExpr,
|
|
"deepseek-v4-pro": deepSeekPeak + ` ? tier("peak", p * 1.32 + cr * 0.044 + c * 3.96) : tier("off_peak", p * 0.66 + cr * 0.022 + c * 1.98)`,
|
|
// The Search and Fetch API routing names: $0.75 per 1,000 successful
|
|
// requests each, the same pricing page. The calls carry no tokens.
|
|
constant.DeepSeekSearchModel: `tier("request", fixed(0.00075))`,
|
|
constant.DeepSeekFetchModel: `tier("request", fixed(0.00075))`,
|
|
}
|
|
|
|
// GetChannelBillingExpr returns provider-specific built-in pricing that must
|
|
// not replace the model's regular or group pricing for other channels.
|
|
func GetChannelBillingExpr(channelType int, model string) (string, bool) {
|
|
if channelType != constant.ChannelTypeDeepSeek {
|
|
return "", false
|
|
}
|
|
|
|
switch model {
|
|
case "deepseek-flash", "deepseek-v4.1-flash", "deepseek-v4-flash", "deepseek-v4-flash-vision-exp":
|
|
return deepSeekFlashOfficialExpr, true
|
|
case "deepseek-v4-pro":
|
|
return deepSeekV4ProOfficialExpr, true
|
|
default:
|
|
return "", false
|
|
}
|
|
}
|