Skip to content

Commit 0176b0e

Browse files
edwin-truthsearch-iocte
authored andcommitted
update xai models and pricing (#4315)
* update xai models and pricing * cache accounting for xAI * change log
1 parent cb7bafb commit 0176b0e

File tree

4 files changed

+46
-121
lines changed

4 files changed

+46
-121
lines changed

.changeset/cruel-roses-stick.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@roo-code/types": patch
3+
---
4+
5+
Update x.ai supported models and metadata. Ensure accurate cost accounting.

packages/types/src/providers/xai.ts

Lines changed: 26 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -6,152 +6,68 @@ export type XAIModelId = keyof typeof xaiModels
66
export const xaiDefaultModelId: XAIModelId = "grok-3"
77

88
export const xaiModels = {
9-
"grok-3-beta": {
10-
maxTokens: 8192,
11-
contextWindow: 131072,
12-
supportsImages: false,
13-
supportsPromptCache: false,
14-
inputPrice: 3.0,
15-
outputPrice: 15.0,
16-
description: "xAI's Grok-3 beta model with 131K context window",
17-
},
18-
"grok-3-fast-beta": {
19-
maxTokens: 8192,
20-
contextWindow: 131072,
21-
supportsImages: false,
22-
supportsPromptCache: false,
23-
inputPrice: 5.0,
24-
outputPrice: 25.0,
25-
description: "xAI's Grok-3 fast beta model with 131K context window",
26-
},
27-
"grok-3-mini-beta": {
9+
"grok-2-1212": {
2810
maxTokens: 8192,
2911
contextWindow: 131072,
3012
supportsImages: false,
3113
supportsPromptCache: false,
32-
inputPrice: 0.3,
33-
outputPrice: 0.5,
34-
description: "xAI's Grok-3 mini beta model with 131K context window",
35-
supportsReasoningEffort: true,
14+
inputPrice: 2.0,
15+
outputPrice: 10.0,
16+
description: "xAI's Grok-2 model (version 1212) with 128K context window",
3617
},
37-
"grok-3-mini-fast-beta": {
18+
"grok-2-vision-1212": {
3819
maxTokens: 8192,
39-
contextWindow: 131072,
40-
supportsImages: false,
20+
contextWindow: 32768,
21+
supportsImages: true,
4122
supportsPromptCache: false,
42-
inputPrice: 0.6,
43-
outputPrice: 4.0,
44-
description: "xAI's Grok-3 mini fast beta model with 131K context window",
45-
supportsReasoningEffort: true,
23+
inputPrice: 2.0,
24+
outputPrice: 10.0,
25+
description: "xAI's Grok-2 Vision model (version 1212) with image support and 32K context window",
4626
},
4727
"grok-3": {
4828
maxTokens: 8192,
4929
contextWindow: 131072,
5030
supportsImages: false,
51-
supportsPromptCache: false,
31+
supportsPromptCache: true,
5232
inputPrice: 3.0,
5333
outputPrice: 15.0,
54-
description: "xAI's Grok-3 model with 131K context window",
34+
cacheWritesPrice: 0.75,
35+
cacheReadsPrice: 0.75,
36+
description: "xAI's Grok-3 model with 128K context window",
5537
},
5638
"grok-3-fast": {
5739
maxTokens: 8192,
5840
contextWindow: 131072,
5941
supportsImages: false,
60-
supportsPromptCache: false,
42+
supportsPromptCache: true,
6143
inputPrice: 5.0,
6244
outputPrice: 25.0,
63-
description: "xAI's Grok-3 fast model with 131K context window",
45+
cacheWritesPrice: 1.25,
46+
cacheReadsPrice: 1.25,
47+
description: "xAI's Grok-3 fast model with 128K context window",
6448
},
6549
"grok-3-mini": {
6650
maxTokens: 8192,
6751
contextWindow: 131072,
6852
supportsImages: false,
69-
supportsPromptCache: false,
53+
supportsPromptCache: true,
7054
inputPrice: 0.3,
7155
outputPrice: 0.5,
72-
description: "xAI's Grok-3 mini model with 131K context window",
56+
cacheWritesPrice: 0.07,
57+
cacheReadsPrice: 0.07,
58+
description: "xAI's Grok-3 mini model with 128K context window",
7359
supportsReasoningEffort: true,
7460
},
7561
"grok-3-mini-fast": {
7662
maxTokens: 8192,
7763
contextWindow: 131072,
7864
supportsImages: false,
79-
supportsPromptCache: false,
65+
supportsPromptCache: true,
8066
inputPrice: 0.6,
8167
outputPrice: 4.0,
82-
description: "xAI's Grok-3 mini fast model with 131K context window",
68+
cacheWritesPrice: 0.15,
69+
cacheReadsPrice: 0.15,
70+
description: "xAI's Grok-3 mini fast model with 128K context window",
8371
supportsReasoningEffort: true,
8472
},
85-
"grok-2-latest": {
86-
maxTokens: 8192,
87-
contextWindow: 131072,
88-
supportsImages: false,
89-
supportsPromptCache: false,
90-
inputPrice: 2.0,
91-
outputPrice: 10.0,
92-
description: "xAI's Grok-2 model - latest version with 131K context window",
93-
},
94-
"grok-2": {
95-
maxTokens: 8192,
96-
contextWindow: 131072,
97-
supportsImages: false,
98-
supportsPromptCache: false,
99-
inputPrice: 2.0,
100-
outputPrice: 10.0,
101-
description: "xAI's Grok-2 model with 131K context window",
102-
},
103-
"grok-2-1212": {
104-
maxTokens: 8192,
105-
contextWindow: 131072,
106-
supportsImages: false,
107-
supportsPromptCache: false,
108-
inputPrice: 2.0,
109-
outputPrice: 10.0,
110-
description: "xAI's Grok-2 model (version 1212) with 131K context window",
111-
},
112-
"grok-2-vision-latest": {
113-
maxTokens: 8192,
114-
contextWindow: 32768,
115-
supportsImages: true,
116-
supportsPromptCache: false,
117-
inputPrice: 2.0,
118-
outputPrice: 10.0,
119-
description: "xAI's Grok-2 Vision model - latest version with image support and 32K context window",
120-
},
121-
"grok-2-vision": {
122-
maxTokens: 8192,
123-
contextWindow: 32768,
124-
supportsImages: true,
125-
supportsPromptCache: false,
126-
inputPrice: 2.0,
127-
outputPrice: 10.0,
128-
description: "xAI's Grok-2 Vision model with image support and 32K context window",
129-
},
130-
"grok-2-vision-1212": {
131-
maxTokens: 8192,
132-
contextWindow: 32768,
133-
supportsImages: true,
134-
supportsPromptCache: false,
135-
inputPrice: 2.0,
136-
outputPrice: 10.0,
137-
description: "xAI's Grok-2 Vision model (version 1212) with image support and 32K context window",
138-
},
139-
"grok-vision-beta": {
140-
maxTokens: 8192,
141-
contextWindow: 8192,
142-
supportsImages: true,
143-
supportsPromptCache: false,
144-
inputPrice: 5.0,
145-
outputPrice: 15.0,
146-
description: "xAI's Grok Vision Beta model with image support and 8K context window",
147-
},
148-
"grok-beta": {
149-
maxTokens: 8192,
150-
contextWindow: 131072,
151-
supportsImages: false,
152-
supportsPromptCache: false,
153-
inputPrice: 5.0,
154-
outputPrice: 15.0,
155-
description: "xAI's Grok Beta model (legacy) with 131K context window",
156-
},
15773
} as const satisfies Record<string, ModelInfo>

src/api/providers/__tests__/xai.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe("XAIHandler", () => {
6262
})
6363

6464
test("should return specified model when valid model is provided", () => {
65-
const testModelId = "grok-2-latest"
65+
const testModelId = "grok-3"
6666
const handlerWithModel = new XAIHandler({ apiModelId: testModelId })
6767
const model = handlerWithModel.getModel()
6868

@@ -72,7 +72,7 @@ describe("XAIHandler", () => {
7272

7373
test("should include reasoning_effort parameter for mini models", async () => {
7474
const miniModelHandler = new XAIHandler({
75-
apiModelId: "grok-3-mini-beta",
75+
apiModelId: "grok-3-mini",
7676
reasoningEffort: "high",
7777
})
7878

@@ -101,7 +101,7 @@ describe("XAIHandler", () => {
101101

102102
test("should not include reasoning_effort parameter for non-mini models", async () => {
103103
const regularModelHandler = new XAIHandler({
104-
apiModelId: "grok-2-latest",
104+
apiModelId: "grok-3",
105105
reasoningEffort: "high",
106106
})
107107

@@ -255,7 +255,7 @@ describe("XAIHandler", () => {
255255

256256
test("createMessage should pass correct parameters to OpenAI client", async () => {
257257
// Setup a handler with specific model
258-
const modelId = "grok-2-latest"
258+
const modelId = "grok-3"
259259
const modelInfo = xaiModels[modelId]
260260
const handlerWithModel = new XAIHandler({ apiModelId: modelId })
261261

src/api/providers/xai.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,21 @@ export class XAIHandler extends BaseProvider implements SingleCompletionHandler
7676
}
7777

7878
if (chunk.usage) {
79+
// Extract detailed token information if available
80+
// First check for prompt_tokens_details structure (real API response)
81+
const promptDetails = "prompt_tokens_details" in chunk.usage ? chunk.usage.prompt_tokens_details : null;
82+
const cachedTokens = promptDetails && "cached_tokens" in promptDetails ? promptDetails.cached_tokens : 0;
83+
84+
// Fall back to direct fields in usage (used in test mocks)
85+
const readTokens = cachedTokens || ("cache_read_input_tokens" in chunk.usage ? (chunk.usage as any).cache_read_input_tokens : 0);
86+
const writeTokens = "cache_creation_input_tokens" in chunk.usage ? (chunk.usage as any).cache_creation_input_tokens : 0;
87+
7988
yield {
8089
type: "usage",
8190
inputTokens: chunk.usage.prompt_tokens || 0,
8291
outputTokens: chunk.usage.completion_tokens || 0,
83-
// X.AI might include these fields in the future, handle them if present.
84-
cacheReadTokens:
85-
"cache_read_input_tokens" in chunk.usage ? (chunk.usage as any).cache_read_input_tokens : 0,
86-
cacheWriteTokens:
87-
"cache_creation_input_tokens" in chunk.usage
88-
? (chunk.usage as any).cache_creation_input_tokens
89-
: 0,
92+
cacheReadTokens: readTokens,
93+
cacheWriteTokens: writeTokens,
9094
}
9195
}
9296
}

0 commit comments

Comments
 (0)