feat(grok):add grok 4.7 support

This commit is contained in:
nagi330
2026-09-22 10:30:01 +08:00
parent 1c0a69c0ce
commit 935db68517
12 changed files with 67 additions and 6 deletions
@@ -855,6 +855,19 @@ func (s *BillingService) initFallbackPricing() {
LongContextOutputMultiplier: 2,
}
// xAI Grok 4.7: $2 input / $0.50 cached input / $6 output below 200k;
// long-context rates are $4 / $1 / $12 (>=200k prompt tokens).
s.fallbackPrices["grok-4.7"] = &ModelPricing{
InputPricePerToken: 2e-6,
OutputPricePerToken: 6e-6,
CacheReadPricePerToken: 0.5e-6,
SupportsCacheBreakdown: false,
LongContextInputThreshold: 200000,
LongContextThresholdInclusive: true,
LongContextInputMultiplier: 2,
LongContextOutputMultiplier: 2,
}
// xAI Grok 4.3: $1.25 input / $0.20 cached / $2.50 output below 200k;
// long-context rates are $2.50 / $0.40 / $5.
s.fallbackPrices["grok-4.3"] = &ModelPricing{
@@ -1128,6 +1141,8 @@ func (s *BillingService) getFallbackPricing(model string) *ModelPricing {
switch modelLower {
case "grok", "grok-latest", "grok-4.6", "grok-4.6-latest":
return s.fallbackPrices["grok-4.6"]
case "grok-4.7", "grok-4.7-latest":
return s.fallbackPrices["grok-4.7"]
case "grok-4.5", "grok-4.5-latest":
return s.fallbackPrices["grok-4.5"]
case "grok-3-mini":
@@ -1169,6 +1169,25 @@ func TestGetModelPricing_Grok46OfficialFallback(t *testing.T) {
}
}
func TestGetModelPricing_Grok47OfficialFallback(t *testing.T) {
svc := newTestBillingService()
for _, model := range []string{"grok-4.7", "grok-4.7-latest"} {
model := model
t.Run(model, func(t *testing.T) {
pricing, err := svc.GetModelPricing(model)
require.NoError(t, err)
require.InDelta(t, 2e-6, pricing.InputPricePerToken, 1e-12)
require.InDelta(t, 6e-6, pricing.OutputPricePerToken, 1e-12)
require.InDelta(t, 0.5e-6, pricing.CacheReadPricePerToken, 1e-12)
require.Equal(t, 200000, pricing.LongContextInputThreshold)
require.InDelta(t, 2.0, pricing.LongContextInputMultiplier, 1e-12)
require.InDelta(t, 2.0, pricing.LongContextOutputMultiplier, 1e-12)
require.False(t, pricing.SupportsCacheBreakdown)
})
}
}
func TestGetModelPricing_GrokOfficialFamilyCards(t *testing.T) {
svc := newTestBillingService()
for _, tc := range []struct {
@@ -1267,6 +1267,7 @@ func isGrokCodexImageInputModel(model string) bool {
case "grok-4.3",
"grok-4.5",
"grok-4.6",
"grok-4.7",
"grok-build-0.1",
"grok-4.20-0309-reasoning",
"grok-4.20-0309-non-reasoning",
@@ -744,16 +744,18 @@ func normalizeGrokReasoningEffortValue(raw, model string) (string, bool) {
}
// GrokSupportsXHighReasoningEffort reports whether the model advertises and
// forwards the xhigh reasoning effort (Grok 4.6 and its undated alias).
// forwards the xhigh reasoning effort (Grok 4.6/4.7 and their aliases).
func GrokSupportsXHighReasoningEffort(model string) bool {
model = strings.ToLower(xai.StripGrokProviderPrefix(strings.TrimSpace(model)))
return model == "grok-4.6" || model == "grok-4.6-latest"
return model == "grok-4.7" || model == "grok-4.7-latest" ||
model == "grok-4.6" || model == "grok-4.6-latest"
}
func grokSupportsReasoningEffort(model string) bool {
model = strings.ToLower(xai.StripGrokProviderPrefix(strings.TrimSpace(model)))
switch model {
case "grok-4.5", "grok-4.5-latest", "grok-4.6", "grok-4.6-latest",
"grok-4.7", "grok-4.7-latest",
"grok-4.3", "grok-4.3-latest",
"grok-3-mini", "grok-3-mini-fast", "grok-4.20-0309-reasoning",
"grok-4.20-reasoning", "grok-4.20-multi-agent-0309":
@@ -498,7 +498,7 @@ func grokChatResponsesCacheIntentBody(body []byte) ([]byte, error) {
func grokChatResponsesBridgeModel(model string) bool {
switch strings.ToLower(xai.StripGrokProviderPrefix(strings.TrimSpace(model))) {
case "grok-4.5", "grok-4.6", "grok-4.6-latest":
case "grok-4.5", "grok-4.6", "grok-4.6-latest", "grok-4.7", "grok-4.7-latest":
return true
default:
return false
+1
View File
@@ -27,6 +27,7 @@ const (
// 供 /v1/models 在尚未同步上游列表时回退,以及账号白名单预填。
func DefaultOpenCodeGoModelIDs() []string {
return []string{
"grok-4.7",
"grok-4.6",
"gpt-5.6-luna",
"glm-5.3-flash",
@@ -299,6 +299,8 @@ func canonicalGrokBuildRuntimeModel(model string) string {
return "grok-4.5-build"
case "grok-4.6", "grok-4.6-latest", "grok-4.6-build":
return "grok-4.6-build"
case "grok-4.7", "grok-4.7-latest", "grok-4.7-build":
return "grok-4.7-build"
default:
return ""
}