Skip to content

Commit fada1a5

Browse files
authored
fix(provider): serialize Mistral prompt cache keys (#38448)
1 parent 542ba88 commit fada1a5

6 files changed

Lines changed: 128 additions & 6 deletions

File tree

‎bun.lock‎

Lines changed: 13 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
"@standard-community/standard-openapi@0.2.9": "patches/@standard-community%2Fstandard-openapi@0.2.9.patch",
150150
"solid-js@1.9.10": "patches/solid-js@1.9.10.patch",
151151
"@ai-sdk/xai@3.0.102": "patches/@ai-sdk%2Fxai@3.0.102.patch",
152+
"@ai-sdk/mistral@3.0.34": "patches/@ai-sdk%2Fmistral@3.0.34.patch",
152153
"gcp-metadata@8.1.2": "patches/gcp-metadata@8.1.2.patch",
153154
"pacote@21.5.0": "patches/pacote@21.5.0.patch",
154155
"@ai-sdk/google@3.0.73": "patches/@ai-sdk%2Fgoogle@3.0.73.patch",

‎packages/core/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"@ai-sdk/google": "3.0.73",
7373
"@ai-sdk/google-vertex": "4.0.128",
7474
"@ai-sdk/groq": "3.0.31",
75-
"@ai-sdk/mistral": "3.0.27",
75+
"@ai-sdk/mistral": "3.0.34",
7676
"@ai-sdk/openai": "3.0.84",
7777
"@ai-sdk/openai-compatible": "2.0.41",
7878
"@ai-sdk/perplexity": "3.0.26",
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { createMistral } from "@ai-sdk/mistral"
2+
import { expect, test } from "bun:test"
3+
4+
test("Mistral sends promptCacheKey as prompt_cache_key", async () => {
5+
let body: Record<string, unknown> | undefined
6+
const mockFetch = Object.assign(
7+
async (_input: Parameters<typeof fetch>[0], init?: RequestInit) => {
8+
body = JSON.parse(String(init?.body))
9+
return Response.json({
10+
id: "response-1",
11+
created: 0,
12+
model: "mistral-large-latest",
13+
object: "chat.completion",
14+
choices: [{ index: 0, message: { role: "assistant", content: "Hello" }, finish_reason: "stop" }],
15+
usage: { prompt_tokens: 1, completion_tokens: 1, total_tokens: 2 },
16+
})
17+
},
18+
{ preconnect: fetch.preconnect },
19+
)
20+
const model = createMistral({ apiKey: "test", fetch: mockFetch })("mistral-large-latest")
21+
22+
await model.doGenerate({
23+
prompt: [{ role: "user", content: [{ type: "text", text: "Hello" }] }],
24+
providerOptions: { mistral: { promptCacheKey: "session-123" } },
25+
})
26+
27+
expect(body?.prompt_cache_key).toBe("session-123")
28+
})

‎packages/opencode/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"@ai-sdk/google": "3.0.73",
6767
"@ai-sdk/google-vertex": "4.0.128",
6868
"@ai-sdk/groq": "3.0.31",
69-
"@ai-sdk/mistral": "3.0.27",
69+
"@ai-sdk/mistral": "3.0.34",
7070
"@ai-sdk/openai": "3.0.84",
7171
"@ai-sdk/openai-compatible": "2.0.41",
7272
"@ai-sdk/perplexity": "3.0.26",
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
diff --git a/dist/index.d.ts b/dist/index.d.ts
2+
index 1ca9113bed2728a616db773a8e08d8d6957447d7..15408ec429dc210b5fa43589d81b69c93bf27b2d 100644
3+
--- a/dist/index.d.ts
4+
+++ b/dist/index.d.ts
5+
@@ -14,6 +14,7 @@ declare const mistralLanguageModelOptions: z.ZodObject<{
6+
none: "none";
7+
high: "high";
8+
}>>;
9+
+ promptCacheKey: z.ZodOptional<z.ZodString>;
10+
}, z.core.$strip>;
11+
type MistralLanguageModelOptions = z.infer<typeof mistralLanguageModelOptions>;
12+
13+
diff --git a/dist/index.js b/dist/index.js
14+
index 45735e524aaff54ea058c99c729c5ffd3c507058..6aca5f6f13da0054ede31c1f1a692e4eaed37d34 100644
15+
--- a/dist/index.js
16+
+++ b/dist/index.js
17+
@@ -268,7 +268,8 @@ var mistralLanguageModelOptions = import_v4.z.object({
18+
* - `'high'`: Enable reasoning
19+
* - `'none'`: Disable reasoning
20+
*/
21+
- reasoningEffort: import_v4.z.enum(["high", "none"]).optional()
22+
+ reasoningEffort: import_v4.z.enum(["high", "none"]).optional(),
23+
+ promptCacheKey: import_v4.z.string().optional()
24+
});
25+
26+
// src/mistral-error.ts
27+
@@ -413,6 +414,7 @@ var MistralChatLanguageModel = class {
28+
top_p: topP,
29+
random_seed: seed,
30+
reasoning_effort: options.reasoningEffort,
31+
+ prompt_cache_key: options.promptCacheKey,
32+
// response format:
33+
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? structuredOutputs && (responseFormat == null ? void 0 : responseFormat.schema) != null ? {
34+
type: "json_schema",
35+
diff --git a/dist/index.mjs b/dist/index.mjs
36+
index 4c22df1cd78a1ba81309c8a86ceecefef4ba4aea..30cd3b1f503860109b7fa2107cd1eb17b70c96be 100644
37+
--- a/dist/index.mjs
38+
+++ b/dist/index.mjs
39+
@@ -256,7 +256,8 @@ var mistralLanguageModelOptions = z.object({
40+
* - `'high'`: Enable reasoning
41+
* - `'none'`: Disable reasoning
42+
*/
43+
- reasoningEffort: z.enum(["high", "none"]).optional()
44+
+ reasoningEffort: z.enum(["high", "none"]).optional(),
45+
+ promptCacheKey: z.string().optional()
46+
});
47+
48+
// src/mistral-error.ts
49+
@@ -403,6 +404,7 @@ var MistralChatLanguageModel = class {
50+
top_p: topP,
51+
random_seed: seed,
52+
reasoning_effort: options.reasoningEffort,
53+
+ prompt_cache_key: options.promptCacheKey,
54+
// response format:
55+
response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? structuredOutputs && (responseFormat == null ? void 0 : responseFormat.schema) != null ? {
56+
type: "json_schema",
57+
diff --git a/src/mistral-chat-language-model.ts b/src/mistral-chat-language-model.ts
58+
index 480c472d534bedbe8897979673453bd1c29a70b7..e46496da94f7d4af9822897202ca6baae67dae3a 100644
59+
--- a/src/mistral-chat-language-model.ts
60+
+++ b/src/mistral-chat-language-model.ts
61+
@@ -129,6 +129,7 @@ export class MistralChatLanguageModel implements LanguageModelV3 {
62+
top_p: topP,
63+
random_seed: seed,
64+
reasoning_effort: options.reasoningEffort,
65+
+ prompt_cache_key: options.promptCacheKey,
66+
67+
// response format:
68+
response_format:
69+
diff --git a/src/mistral-chat-options.ts b/src/mistral-chat-options.ts
70+
index 80fff45fba2c378fa06962f071946bcd2b882a0b..b4fdfa51f3bf11a4220e010c8aca92482cb0c3db 100644
71+
--- a/src/mistral-chat-options.ts
72+
+++ b/src/mistral-chat-options.ts
73+
@@ -62,6 +62,11 @@ export const mistralLanguageModelOptions = z.object({
74+
* - `'none'`: Disable reasoning
75+
*/
76+
reasoningEffort: z.enum(['high', 'none']).optional(),
77+
+
78+
+ /**
79+
+ * A stable identifier used to route requests with shared prompt prefixes.
80+
+ */
81+
+ promptCacheKey: z.string().optional(),
82+
});
83+
84+
export type MistralLanguageModelOptions = z.infer<

0 commit comments

Comments
 (0)