@ai-sdk/xai 3.0.84 → 3.0.86

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/xai",
3
- "version": "3.0.84",
3
+ "version": "3.0.86",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -29,16 +29,16 @@
29
29
  }
30
30
  },
31
31
  "dependencies": {
32
- "@ai-sdk/openai-compatible": "2.0.42",
33
- "@ai-sdk/provider": "3.0.9",
34
- "@ai-sdk/provider-utils": "4.0.24"
32
+ "@ai-sdk/openai-compatible": "2.0.44",
33
+ "@ai-sdk/provider": "3.0.10",
34
+ "@ai-sdk/provider-utils": "4.0.26"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/node": "20.17.24",
38
38
  "tsup": "^8",
39
39
  "typescript": "5.8.3",
40
40
  "zod": "3.25.76",
41
- "@ai-sdk/test-server": "1.0.4",
41
+ "@ai-sdk/test-server": "1.0.5",
42
42
  "@vercel/ai-tsconfig": "0.0.0"
43
43
  },
44
44
  "peerDependencies": {
@@ -1,10 +1,10 @@
1
1
  import {
2
- SharedV3Warning,
3
- LanguageModelV3Prompt,
4
2
  UnsupportedFunctionalityError,
3
+ type SharedV3Warning,
4
+ type LanguageModelV3Prompt,
5
5
  } from '@ai-sdk/provider';
6
6
  import { convertToBase64 } from '@ai-sdk/provider-utils';
7
- import { XaiChatPrompt } from './xai-chat-prompt';
7
+ import type { XaiChatPrompt } from './xai-chat-prompt';
8
8
 
9
9
  export function convertToXaiChatMessages(prompt: LanguageModelV3Prompt): {
10
10
  messages: XaiChatPrompt;
@@ -1,5 +1,5 @@
1
- import { LanguageModelV3Usage } from '@ai-sdk/provider';
2
- import { XaiChatUsage } from './xai-chat-language-model';
1
+ import type { LanguageModelV3Usage } from '@ai-sdk/provider';
2
+ import type { XaiChatUsage } from './xai-chat-language-model';
3
3
 
4
4
  export function convertXaiChatUsage(usage: XaiChatUsage): LanguageModelV3Usage {
5
5
  const cacheReadTokens = usage.prompt_tokens_details?.cached_tokens ?? 0;
@@ -1,4 +1,4 @@
1
- import { LanguageModelV3FinishReason } from '@ai-sdk/provider';
1
+ import type { LanguageModelV3FinishReason } from '@ai-sdk/provider';
2
2
 
3
3
  export function mapXaiFinishReason(
4
4
  finishReason: string | null | undefined,
@@ -1,10 +1,10 @@
1
1
  import {
2
- SharedV3Warning,
3
- LanguageModelV3Message,
4
2
  UnsupportedFunctionalityError,
3
+ type SharedV3Warning,
4
+ type LanguageModelV3Message,
5
5
  } from '@ai-sdk/provider';
6
6
  import { convertToBase64 } from '@ai-sdk/provider-utils';
7
- import {
7
+ import type {
8
8
  XaiResponsesInput,
9
9
  XaiResponsesUserMessageContentPart,
10
10
  } from './xai-responses-api';
@@ -54,9 +54,19 @@ export async function convertToXaiResponsesInput({
54
54
  : `data:${mediaType};base64,${convertToBase64(block.data)}`;
55
55
 
56
56
  contentParts.push({ type: 'input_image', image_url: imageUrl });
57
+ } else if (block.data instanceof URL) {
58
+ // xAI's Responses API accepts non-image documents (PDF, text, CSV, etc.)
59
+ // via `{ type: 'input_file', file_url }`. See
60
+ // https://docs.x.ai/docs/guides/chat-with-files. Inline bytes for
61
+ // non-image files are not supported by xAI; callers must upload via
62
+ // the Files API and pass a provider reference (file_id) instead.
63
+ contentParts.push({
64
+ type: 'input_file',
65
+ file_url: block.data.toString(),
66
+ });
57
67
  } else {
58
68
  throw new UnsupportedFunctionalityError({
59
- functionality: `file part media type ${block.mediaType}`,
69
+ functionality: `file part media type ${block.mediaType} as inline data (xAI Responses requires a URL or a Files API reference for non-image files)`,
60
70
  });
61
71
  }
62
72
  break;
@@ -1,5 +1,5 @@
1
- import { LanguageModelV3Usage } from '@ai-sdk/provider';
2
- import { XaiResponsesUsage } from './xai-responses-api';
1
+ import type { LanguageModelV3Usage } from '@ai-sdk/provider';
2
+ import type { XaiResponsesUsage } from './xai-responses-api';
3
3
 
4
4
  export function convertXaiResponsesUsage(
5
5
  usage: XaiResponsesUsage,
@@ -1,4 +1,4 @@
1
- import { LanguageModelV3FinishReason } from '@ai-sdk/provider';
1
+ import type { LanguageModelV3FinishReason } from '@ai-sdk/provider';
2
2
 
3
3
  export function mapXaiResponsesFinishReason(
4
4
  finishReason: string | null | undefined,
@@ -26,7 +26,8 @@ export type XaiResponsesSystemMessage = {
26
26
 
27
27
  export type XaiResponsesUserMessageContentPart =
28
28
  | { type: 'input_text'; text: string }
29
- | { type: 'input_image'; image_url: string };
29
+ | { type: 'input_image'; image_url: string }
30
+ | { type: 'input_file'; file_url: string };
30
31
 
31
32
  export type XaiResponsesUserMessage = {
32
33
  role: 'user';
@@ -1,4 +1,4 @@
1
- import {
1
+ import type {
2
2
  LanguageModelV3,
3
3
  LanguageModelV3CallOptions,
4
4
  LanguageModelV3Content,
@@ -13,25 +13,25 @@ import {
13
13
  combineHeaders,
14
14
  createEventSourceResponseHandler,
15
15
  createJsonResponseHandler,
16
- FetchFunction,
17
16
  parseProviderOptions,
18
- ParseResult,
19
17
  postJsonToApi,
18
+ type FetchFunction,
19
+ type ParseResult,
20
20
  } from '@ai-sdk/provider-utils';
21
- import { z } from 'zod/v4';
21
+ import type { z } from 'zod/v4';
22
22
  import { getResponseMetadata } from '../get-response-metadata';
23
23
  import { xaiFailedResponseHandler } from '../xai-error';
24
24
  import { convertToXaiResponsesInput } from './convert-to-xai-responses-input';
25
25
  import { convertXaiResponsesUsage } from './convert-xai-responses-usage';
26
26
  import { mapXaiResponsesFinishReason } from './map-xai-responses-finish-reason';
27
27
  import {
28
- XaiResponsesIncludeOptions,
29
28
  xaiResponsesChunkSchema,
30
29
  xaiResponsesResponseSchema,
30
+ type XaiResponsesIncludeOptions,
31
31
  } from './xai-responses-api';
32
32
  import {
33
- XaiResponsesModelId,
34
33
  xaiLanguageModelResponsesOptions,
34
+ type XaiResponsesModelId,
35
35
  } from './xai-responses-options';
36
36
  import { prepareResponsesTools } from './xai-responses-prepare-tools';
37
37
 
@@ -61,6 +61,11 @@ export class XaiResponsesLanguageModel implements LanguageModelV3 {
61
61
 
62
62
  readonly supportedUrls: Record<string, RegExp[]> = {
63
63
  'image/*': [/^https?:\/\/.*$/],
64
+ // xAI's Responses API accepts non-image documents (PDF, plain text, CSV, etc.) as
65
+ // `{ type: 'input_file', file_url }`. Keeping these URLs intact here lets them pass
66
+ // through to the converter instead of being downloaded to bytes by the SDK.
67
+ 'application/pdf': [/^https?:\/\/.*$/],
68
+ 'text/*': [/^https?:\/\/.*$/],
64
69
  };
65
70
 
66
71
  private async getArgs({
@@ -1,14 +1,14 @@
1
1
  import {
2
- LanguageModelV3CallOptions,
3
- SharedV3Warning,
4
2
  UnsupportedFunctionalityError,
3
+ type LanguageModelV3CallOptions,
4
+ type SharedV3Warning,
5
5
  } from '@ai-sdk/provider';
6
6
  import { validateTypes } from '@ai-sdk/provider-utils';
7
7
  import { fileSearchArgsSchema } from '../tool/file-search';
8
8
  import { mcpServerArgsSchema } from '../tool/mcp-server';
9
9
  import { webSearchArgsSchema } from '../tool/web-search';
10
10
  import { xSearchArgsSchema } from '../tool/x-search';
11
- import { XaiResponsesTool } from './xai-responses-api';
11
+ import type { XaiResponsesTool } from './xai-responses-api';
12
12
 
13
13
  type XaiResponsesToolChoice =
14
14
  | 'auto'
@@ -1,25 +1,25 @@
1
1
  import {
2
2
  APICallError,
3
- LanguageModelV3,
4
- LanguageModelV3CallOptions,
5
- LanguageModelV3Content,
6
- LanguageModelV3FinishReason,
7
- LanguageModelV3GenerateResult,
8
- LanguageModelV3StreamPart,
9
- LanguageModelV3StreamResult,
10
- LanguageModelV3Usage,
11
- SharedV3Warning,
3
+ type LanguageModelV3,
4
+ type LanguageModelV3CallOptions,
5
+ type LanguageModelV3Content,
6
+ type LanguageModelV3FinishReason,
7
+ type LanguageModelV3GenerateResult,
8
+ type LanguageModelV3StreamPart,
9
+ type LanguageModelV3StreamResult,
10
+ type LanguageModelV3Usage,
11
+ type SharedV3Warning,
12
12
  } from '@ai-sdk/provider';
13
13
  import {
14
14
  combineHeaders,
15
15
  createEventSourceResponseHandler,
16
16
  createJsonResponseHandler,
17
17
  extractResponseHeaders,
18
- FetchFunction,
19
18
  parseProviderOptions,
20
- ParseResult,
21
19
  postJsonToApi,
22
20
  safeParseJSON,
21
+ type FetchFunction,
22
+ type ParseResult,
23
23
  } from '@ai-sdk/provider-utils';
24
24
  import { z } from 'zod/v4';
25
25
  import { convertToXaiChatMessages } from './convert-to-xai-chat-messages';
@@ -27,8 +27,8 @@ import { convertXaiChatUsage } from './convert-xai-chat-usage';
27
27
  import { getResponseMetadata } from './get-response-metadata';
28
28
  import { mapXaiFinishReason } from './map-xai-finish-reason';
29
29
  import {
30
- XaiChatModelId,
31
30
  xaiLanguageModelChatOptions,
31
+ type XaiChatModelId,
32
32
  } from './xai-chat-options';
33
33
  import { xaiFailedResponseHandler } from './xai-error';
34
34
  import { prepareTools } from './xai-prepare-tools';
@@ -1,19 +1,19 @@
1
- import { ImageModelV3, SharedV3Warning } from '@ai-sdk/provider';
1
+ import type { ImageModelV3, SharedV3Warning } from '@ai-sdk/provider';
2
2
  import {
3
3
  combineHeaders,
4
4
  convertImageModelFileToDataUri,
5
5
  createBinaryResponseHandler,
6
6
  createJsonResponseHandler,
7
7
  createStatusCodeErrorResponseHandler,
8
- FetchFunction,
9
8
  getFromApi,
10
9
  parseProviderOptions,
11
10
  postJsonToApi,
11
+ type FetchFunction,
12
12
  } from '@ai-sdk/provider-utils';
13
13
  import { z } from 'zod/v4';
14
14
  import { xaiFailedResponseHandler } from './xai-error';
15
15
  import { xaiImageModelOptions } from './xai-image-options';
16
- import { XaiImageModelId } from './xai-image-settings';
16
+ import type { XaiImageModelId } from './xai-image-settings';
17
17
 
18
18
  interface XaiImageModelConfig {
19
19
  provider: string;
@@ -1,9 +1,9 @@
1
1
  import {
2
- LanguageModelV3CallOptions,
3
- SharedV3Warning,
4
2
  UnsupportedFunctionalityError,
3
+ type LanguageModelV3CallOptions,
4
+ type SharedV3Warning,
5
5
  } from '@ai-sdk/provider';
6
- import { XaiToolChoice } from './xai-chat-prompt';
6
+ import type { XaiToolChoice } from './xai-chat-prompt';
7
7
 
8
8
  export function prepareTools({
9
9
  tools,
@@ -1,27 +1,27 @@
1
1
  import {
2
- type Experimental_VideoModelV3,
3
- ImageModelV3,
4
- LanguageModelV3,
5
2
  NoSuchModelError,
6
- ProviderV3,
3
+ type ImageModelV3,
4
+ type LanguageModelV3,
5
+ type ProviderV3,
6
+ type Experimental_VideoModelV3,
7
7
  } from '@ai-sdk/provider';
8
8
  import {
9
- FetchFunction,
10
9
  generateId,
11
10
  loadApiKey,
12
11
  withoutTrailingSlash,
13
12
  withUserAgentSuffix,
13
+ type FetchFunction,
14
14
  } from '@ai-sdk/provider-utils';
15
15
  import { XaiChatLanguageModel } from './xai-chat-language-model';
16
- import { XaiChatModelId } from './xai-chat-options';
16
+ import type { XaiChatModelId } from './xai-chat-options';
17
17
  import { XaiImageModel } from './xai-image-model';
18
- import { XaiImageModelId } from './xai-image-settings';
18
+ import type { XaiImageModelId } from './xai-image-settings';
19
19
  import { XaiResponsesLanguageModel } from './responses/xai-responses-language-model';
20
- import { XaiResponsesModelId } from './responses/xai-responses-options';
20
+ import type { XaiResponsesModelId } from './responses/xai-responses-options';
21
21
  import { xaiTools } from './tool';
22
22
  import { VERSION } from './version';
23
23
  import { XaiVideoModel } from './xai-video-model';
24
- import { XaiVideoModelId } from './xai-video-settings';
24
+ import type { XaiVideoModelId } from './xai-video-settings';
25
25
 
26
26
  export interface XaiProvider extends ProviderV3 {
27
27
  /**