@ai-sdk/deepseek 3.0.81 → 3.0.84

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -534,6 +534,97 @@ extension is used as a fallback when the media type is generic (for example,
534
534
  `application/octet-stream`). Recognizable non-image content is rejected even
535
535
  when its declared media type or filename indicates a supported image format.
536
536
 
537
+ ## Responses API
538
+
539
+ You can use DeepSeek's [Responses API](https://api-docs.deepseek.com/guides/responses_api) with the `.responses()` factory method. It supports `deepseek-flash` and `deepseek-v4-pro`, JSON schema structured outputs, `toolChoice` modes, and DeepSeek's server-side web search.
540
+
541
+ ```ts
542
+ import { deepSeek } from '@ai-sdk/deepseek';
543
+ import { generateText } from 'ai';
544
+
545
+ const { text } = await generateText({
546
+ model: deepSeek.responses('deepseek-v4-pro'),
547
+ prompt: 'Write a vegetarian lasagna recipe for 4 people.',
548
+ });
549
+ ```
550
+
551
+ The Responses API is stateless. The provider sends the full conversation history, including reasoning and previous web search calls, on every request.
552
+
553
+ The following optional provider options are available for Responses models:
554
+
555
+ - `thinking` _object_
556
+
557
+ Optional. Set `type` to `'disabled'` to turn off thinking mode (sent as `reasoning.effort: 'none'`).
558
+
559
+ - `reasoningEffort` _'low' | 'high' | 'max'_
560
+
561
+ Optional. Controls thinking strength when thinking is enabled. The top-level `reasoning` setting is also mapped to these values.
562
+
563
+ - `topLogprobs` _number_
564
+
565
+ Optional. Returns the specified number of most likely tokens at each token position in `providerMetadata.deepseek.logprobs`. Accepts values from `0` through `20`.
566
+
567
+ - `userId` _string_
568
+
569
+ Optional. An opaque end-user identifier, sent as `user`. The value must match `^[a-zA-Z0-9_-]+$` and contain at most 512 characters.
570
+
571
+ ```ts
572
+ import {
573
+ deepSeek,
574
+ type DeepSeekLanguageModelResponsesOptions,
575
+ } from '@ai-sdk/deepseek';
576
+ import { generateText } from 'ai';
577
+
578
+ const { text } = await generateText({
579
+ model: deepSeek.responses('deepseek-v4-pro'),
580
+ prompt: 'How many "r"s are in the word "strawberry"?',
581
+ providerOptions: {
582
+ deepseek: {
583
+ reasoningEffort: 'high',
584
+ } satisfies DeepSeekLanguageModelResponsesOptions,
585
+ },
586
+ });
587
+ ```
588
+
589
+ The Responses API does not support `stopSequences`, `frequencyPenalty`, `presencePenalty`, `topK`, `seed`, or strict function tools. The provider omits them and returns an unsupported warning.
590
+
591
+ DeepSeek rejects `toolChoice: 'required'` and forced tool choices while thinking is enabled, which is the default. Set `thinking.type` to `'disabled'` to use them. `'auto'` and `'none'` work in both modes.
592
+
593
+ ### Web Search
594
+
595
+ DeepSeek can search the web and read pages on the server while it generates a response. Add the `webSearch` tool to a `deepseek-v4-pro` Responses model. DeepSeek ignores the tool on `deepseek-flash`.
596
+
597
+ ```ts
598
+ import { deepSeek } from '@ai-sdk/deepseek';
599
+ import { generateText } from 'ai';
600
+
601
+ const result = await generateText({
602
+ model: deepSeek.responses('deepseek-v4-pro'),
603
+ prompt: 'What is the official Python website?',
604
+ tools: {
605
+ web_search: deepSeek.tools.webSearch(),
606
+ },
607
+ });
608
+
609
+ console.log(result.text);
610
+ console.log(result.providerMetadata?.deepseek?.serverToolUse);
611
+ // { toolSearch: 1, toolFetch: 0 }
612
+ ```
613
+
614
+ Each server-side search is returned as a provider-executed `web_search` tool call and tool result. The raw DeepSeek `web_search_call` item is kept in the tool call's provider metadata, so it is sent back in later turns and DeepSeek can restore its search results.
615
+
616
+ DeepSeek bills successful searches and page reads per operation. The counts are returned in `providerMetadata.deepseek.serverToolUse` (`toolSearch` and `toolFetch`) and in `usage.raw.server_tool_use`. See [DeepSeek pricing](https://api-docs.deepseek.com/quick_start/pricing) for rates.
617
+
618
+ ### Responses Provider Metadata
619
+
620
+ Responses models return the following fields in `providerMetadata.deepseek`:
621
+
622
+ - `responseId`: The DeepSeek response ID
623
+ - `serverToolUse`: Successful server-side web searches (`toolSearch`) and page reads (`toolFetch`), when any ran
624
+ - `logprobs`: Token log probabilities, when `topLogprobs` is set
625
+
626
+ Reasoning parts include the DeepSeek reasoning item ID in `providerMetadata.deepseek.itemId`.
627
+
537
628
  ## Model Capabilities
538
629
 
539
630
  {/* model-capabilities:deepseek-language:start */}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/deepseek",
3
- "version": "3.0.81",
3
+ "version": "3.0.84",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@ai-sdk/provider": "4.0.37",
39
- "@ai-sdk/provider-utils": "5.0.76"
39
+ "@ai-sdk/provider-utils": "5.0.79"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@ai-sdk/test-server": "2.0.4",
@@ -45,7 +45,7 @@
45
45
  "@vercel/ai-tsdown-config": "0.0.0",
46
46
  "tsdown": "^0.23.0",
47
47
  "typescript": "6.0.3",
48
- "zod": "3.25.76"
48
+ "zod": "4.6.7"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "zod": "^3.25.76 || ^4.1.8"
@@ -15,6 +15,9 @@ import {
15
15
  import type { DeepSeekChatModelId } from './chat/deepseek-chat-language-model-options';
16
16
  import { DeepSeekChatLanguageModel } from './chat/deepseek-chat-language-model';
17
17
  import { DeepSeekFiles } from './files/deepseek-files';
18
+ import { DeepSeekResponsesLanguageModel } from './responses/deepseek-responses-language-model';
19
+ import type { DeepSeekResponsesModelId } from './responses/deepseek-responses-language-model-options';
20
+ import { deepseekTools } from './tool';
18
21
  import { VERSION } from './version';
19
22
 
20
23
  export interface DeepSeekProviderSettings {
@@ -57,6 +60,17 @@ export interface DeepSeekProvider extends ProviderV4 {
57
60
  */
58
61
  chat(modelId: DeepSeekChatModelId): LanguageModelV4;
59
62
 
63
+ /**
64
+ * Creates a DeepSeek model that uses the Responses API. Supports
65
+ * server-side tools such as `deepseek.tools.webSearch()`.
66
+ */
67
+ responses(modelId: DeepSeekResponsesModelId): LanguageModelV4;
68
+
69
+ /**
70
+ * DeepSeek server-side tools for use with the Responses API.
71
+ */
72
+ tools: typeof deepseekTools;
73
+
60
74
  /**
61
75
  * Creates a DeepSeek files interface for uploading images.
62
76
  */
@@ -101,6 +115,14 @@ export function createDeepSeek(
101
115
  });
102
116
  };
103
117
 
118
+ const createResponsesModel = (modelId: DeepSeekResponsesModelId) =>
119
+ new DeepSeekResponsesLanguageModel(modelId, {
120
+ provider: 'deepseek.responses',
121
+ url: ({ path }) => `${baseURL}${path}`,
122
+ headers: getHeaders,
123
+ fetch: options.fetch,
124
+ });
125
+
104
126
  const createFiles = () =>
105
127
  new DeepSeekFiles({
106
128
  provider: 'deepseek.files',
@@ -115,6 +137,8 @@ export function createDeepSeek(
115
137
  provider.specificationVersion = 'v4' as const;
116
138
  provider.languageModel = createLanguageModel;
117
139
  provider.chat = createLanguageModel;
140
+ provider.responses = createResponsesModel;
141
+ provider.tools = deepseekTools;
118
142
  provider.files = createFiles;
119
143
 
120
144
  provider.embeddingModel = (modelId: string) => {
package/src/index.ts CHANGED
@@ -18,6 +18,7 @@ export type {
18
18
  /** @deprecated Use `DeepSeekLanguageModelChatOptions` instead. */
19
19
  DeepSeekLanguageModelChatOptions as DeepSeekChatOptions,
20
20
  } from './chat/deepseek-chat-language-model-options';
21
+ export type { DeepSeekLanguageModelResponsesOptions } from './responses/deepseek-responses-language-model-options';
21
22
  export type { DeepSeekErrorData } from './chat/deepseek-chat-api-types';
22
23
  export type { DeepSeekFilePartProviderOptions } from './chat/deepseek-file-part-options';
23
24
  export type { DeepSeekFilesOptions } from './files/deepseek-files-options';
@@ -0,0 +1,44 @@
1
+ import type { LanguageModelV4Usage } from '@ai-sdk/provider';
2
+ import { createNullLanguageModelUsage } from '@ai-sdk/provider-utils';
3
+ import type { DeepSeekResponsesUsage } from './deepseek-responses-api';
4
+
5
+ export function convertDeepSeekResponsesUsage(
6
+ usage: DeepSeekResponsesUsage | null | undefined,
7
+ ): LanguageModelV4Usage {
8
+ if (usage == null) {
9
+ return createNullLanguageModelUsage();
10
+ }
11
+
12
+ const inputTokens = usage.input_tokens ?? 0;
13
+ const outputTokens = usage.output_tokens ?? 0;
14
+ const cacheReadTokens = usage.input_tokens_details?.cached_tokens ?? 0;
15
+ const reasoningTokens = usage.output_tokens_details?.reasoning_tokens ?? 0;
16
+
17
+ return {
18
+ inputTokens: {
19
+ total: inputTokens,
20
+ noCache: inputTokens - cacheReadTokens,
21
+ cacheRead: cacheReadTokens,
22
+ cacheWrite: undefined,
23
+ },
24
+ outputTokens: {
25
+ total: outputTokens,
26
+ text: Math.max(0, outputTokens - reasoningTokens),
27
+ reasoning: reasoningTokens,
28
+ },
29
+ raw: usage,
30
+ };
31
+ }
32
+
33
+ export function getDeepSeekServerToolUse(
34
+ usage: DeepSeekResponsesUsage | null | undefined,
35
+ ): { toolSearch: number; toolFetch: number } | undefined {
36
+ const serverToolUse = usage?.server_tool_use;
37
+ if (serverToolUse == null) {
38
+ return undefined;
39
+ }
40
+ return {
41
+ toolSearch: serverToolUse.tool_search ?? 0,
42
+ toolFetch: serverToolUse.tool_fetch ?? 0,
43
+ };
44
+ }
@@ -0,0 +1,279 @@
1
+ import {
2
+ InvalidPromptError,
3
+ UnsupportedFunctionalityError,
4
+ type LanguageModelV4FilePart,
5
+ type LanguageModelV4Prompt,
6
+ type SharedV4Warning,
7
+ } from '@ai-sdk/provider';
8
+ import {
9
+ convertToBase64,
10
+ getTopLevelMediaType,
11
+ parseProviderOptions,
12
+ resolveFullMediaType,
13
+ resolveProviderReference,
14
+ } from '@ai-sdk/provider-utils';
15
+ import { deepseekFilePartProviderOptions } from '../chat/deepseek-file-part-options';
16
+ import type {
17
+ DeepSeekResponsesInput,
18
+ DeepSeekResponsesInputContentPart,
19
+ } from './deepseek-responses-api';
20
+
21
+ export async function convertToDeepSeekResponsesInput({
22
+ prompt,
23
+ providerOptionsName,
24
+ }: {
25
+ prompt: LanguageModelV4Prompt;
26
+ providerOptionsName: string;
27
+ }): Promise<{
28
+ input: DeepSeekResponsesInput;
29
+ inputWarnings: SharedV4Warning[];
30
+ }> {
31
+ const input: DeepSeekResponsesInput = [];
32
+ const inputWarnings: SharedV4Warning[] = [];
33
+
34
+ for (const message of prompt) {
35
+ switch (message.role) {
36
+ case 'system': {
37
+ input.push({ role: 'system', content: message.content });
38
+ break;
39
+ }
40
+
41
+ case 'user': {
42
+ const content: Array<DeepSeekResponsesInputContentPart> = [];
43
+
44
+ for (const part of message.content) {
45
+ if (part.type === 'text') {
46
+ content.push({ type: 'input_text', text: part.text });
47
+ } else if (
48
+ part.type === 'file' &&
49
+ getTopLevelMediaType(part.mediaType) === 'image' &&
50
+ part.data.type !== 'text'
51
+ ) {
52
+ content.push(
53
+ await convertImagePart({ part, prompt, providerOptionsName }),
54
+ );
55
+ } else {
56
+ inputWarnings.push({
57
+ type: 'unsupported',
58
+ feature: `user message part type: ${part.type}`,
59
+ });
60
+ }
61
+ }
62
+
63
+ input.push({ role: 'user', content });
64
+ break;
65
+ }
66
+
67
+ case 'assistant': {
68
+ for (const part of message.content) {
69
+ switch (part.type) {
70
+ case 'text': {
71
+ if (part.text.length > 0) {
72
+ input.push({ role: 'assistant', content: part.text });
73
+ }
74
+ break;
75
+ }
76
+
77
+ case 'reasoning': {
78
+ const itemId = getStringOption(
79
+ part.providerOptions?.[providerOptionsName]?.itemId,
80
+ );
81
+ input.push({
82
+ type: 'reasoning',
83
+ ...(itemId != null && { id: itemId }),
84
+ content: [{ type: 'reasoning_text', text: part.text }],
85
+ });
86
+ break;
87
+ }
88
+
89
+ case 'tool-call': {
90
+ if (part.providerExecuted) {
91
+ const webSearchCall =
92
+ part.providerOptions?.[providerOptionsName]?.webSearchCall;
93
+ if (isWebSearchCallItem(webSearchCall)) {
94
+ input.push(webSearchCall);
95
+ }
96
+ break;
97
+ }
98
+
99
+ input.push({
100
+ type: 'function_call',
101
+ call_id: part.toolCallId,
102
+ name: part.toolName,
103
+ arguments:
104
+ typeof part.input === 'string'
105
+ ? part.input
106
+ : JSON.stringify(part.input),
107
+ });
108
+ break;
109
+ }
110
+
111
+ case 'tool-result': {
112
+ break;
113
+ }
114
+
115
+ default: {
116
+ inputWarnings.push({
117
+ type: 'unsupported',
118
+ feature: `assistant message part type: ${part.type}`,
119
+ });
120
+ }
121
+ }
122
+ }
123
+ break;
124
+ }
125
+
126
+ case 'tool': {
127
+ for (const part of message.content) {
128
+ if (part.type === 'tool-approval-response') {
129
+ continue;
130
+ }
131
+
132
+ const output = part.output;
133
+ let value: string | Array<DeepSeekResponsesInputContentPart>;
134
+
135
+ switch (output.type) {
136
+ case 'text':
137
+ case 'error-text':
138
+ value = output.value;
139
+ break;
140
+ case 'execution-denied':
141
+ value = output.reason ?? 'Tool call execution denied.';
142
+ break;
143
+ case 'json':
144
+ case 'error-json':
145
+ value = JSON.stringify(output.value);
146
+ break;
147
+ case 'content': {
148
+ value = [];
149
+ for (const item of output.value) {
150
+ if (item.type === 'text') {
151
+ value.push({ type: 'input_text', text: item.text });
152
+ } else if (
153
+ item.type === 'file' &&
154
+ getTopLevelMediaType(item.mediaType) === 'image' &&
155
+ item.data.type !== 'text'
156
+ ) {
157
+ value.push(
158
+ await convertImagePart({
159
+ part: item,
160
+ prompt,
161
+ providerOptionsName,
162
+ }),
163
+ );
164
+ } else {
165
+ inputWarnings.push({
166
+ type: 'unsupported',
167
+ feature: `tool result content part type: ${item.type}`,
168
+ });
169
+ }
170
+ }
171
+ break;
172
+ }
173
+ }
174
+
175
+ input.push({
176
+ type: 'function_call_output',
177
+ call_id: part.toolCallId,
178
+ output: value,
179
+ });
180
+ }
181
+ break;
182
+ }
183
+ }
184
+ }
185
+
186
+ return { input, inputWarnings };
187
+ }
188
+
189
+ const supportedImageMediaTypes = new Set([
190
+ 'image/gif',
191
+ 'image/jpeg',
192
+ 'image/jpg',
193
+ 'image/png',
194
+ 'image/webp',
195
+ ]);
196
+
197
+ async function convertImagePart({
198
+ part,
199
+ prompt,
200
+ providerOptionsName,
201
+ }: {
202
+ part: LanguageModelV4FilePart;
203
+ prompt: LanguageModelV4Prompt;
204
+ providerOptionsName: string;
205
+ }): Promise<DeepSeekResponsesInputContentPart> {
206
+ if (part.data.type === 'reference') {
207
+ return {
208
+ type: 'input_image',
209
+ file_id: resolveProviderReference({
210
+ reference: part.data.reference,
211
+ provider: 'deepseek',
212
+ }),
213
+ };
214
+ }
215
+
216
+ const filePartOptions = await parseProviderOptions({
217
+ provider: providerOptionsName,
218
+ providerOptions: part.providerOptions,
219
+ schema: deepseekFilePartProviderOptions,
220
+ });
221
+
222
+ if (filePartOptions?.fileData === true) {
223
+ throw new UnsupportedFunctionalityError({
224
+ functionality: 'DeepSeek `fileData` image parts with the Responses API',
225
+ });
226
+ }
227
+
228
+ const detail = filePartOptions?.imageDetail;
229
+
230
+ if (part.data.type === 'url') {
231
+ const url = part.data.url.toString();
232
+ if (url.length > 8192) {
233
+ throw new InvalidPromptError({
234
+ prompt,
235
+ message: 'DeepSeek image URLs must not exceed 8192 characters.',
236
+ });
237
+ }
238
+ return {
239
+ type: 'input_image',
240
+ image_url: url,
241
+ ...(detail != null && { detail }),
242
+ };
243
+ }
244
+
245
+ if (part.data.type !== 'data') {
246
+ throw new UnsupportedFunctionalityError({
247
+ functionality: `DeepSeek image data type ${part.data.type}`,
248
+ });
249
+ }
250
+
251
+ const mediaType = resolveFullMediaType({ part });
252
+ if (!supportedImageMediaTypes.has(mediaType)) {
253
+ throw new UnsupportedFunctionalityError({
254
+ functionality: `DeepSeek image media type ${mediaType}`,
255
+ message: 'DeepSeek supports JPEG, PNG, GIF, and WebP image inputs.',
256
+ });
257
+ }
258
+
259
+ return {
260
+ type: 'input_image',
261
+ image_url: `data:${mediaType === 'image/jpg' ? 'image/jpeg' : mediaType};base64,${convertToBase64(part.data.data)}`,
262
+ ...(detail != null && { detail }),
263
+ };
264
+ }
265
+
266
+ function getStringOption(value: unknown): string | undefined {
267
+ return typeof value === 'string' ? value : undefined;
268
+ }
269
+
270
+ function isWebSearchCallItem(
271
+ value: unknown,
272
+ ): value is { type: 'web_search_call' } & Record<string, unknown> {
273
+ return (
274
+ typeof value === 'object' &&
275
+ value != null &&
276
+ !Array.isArray(value) &&
277
+ (value as { type?: unknown }).type === 'web_search_call'
278
+ );
279
+ }