@ai-sdk/alibaba 0.0.0-6b196531-20260710185421

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/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2023 Vercel, Inc.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,151 @@
1
+ # AI SDK - Alibaba Provider
2
+
3
+ The **[Alibaba provider](https://ai-sdk.dev/providers/ai-sdk-providers/alibaba)** for the [AI SDK](https://ai-sdk.dev/docs) contains language model, embedding model, and video model support for [Alibaba Cloud Model Studio](https://modelstudio.console.alibabacloud.com/), including the Qwen model series with advanced reasoning capabilities.
4
+
5
+ > **Deploying to Vercel?** With Vercel's AI Gateway you can access Alibaba (and hundreds of models from other providers) — no additional packages, API keys, or extra cost. [Get started with AI Gateway](https://vercel.com/ai-gateway).
6
+
7
+ ## Setup
8
+
9
+ The Alibaba provider is available in the `@ai-sdk/alibaba` module. You can install it with
10
+
11
+ ```bash
12
+ npm i @ai-sdk/alibaba
13
+ ```
14
+
15
+ ## Skill for Coding Agents
16
+
17
+ If you use coding agents such as Claude Code or Cursor, we highly recommend adding the AI SDK skill to your repository:
18
+
19
+ ```shell
20
+ npx skills add vercel/ai
21
+ ```
22
+
23
+ ## Provider Instance
24
+
25
+ You can import the default provider instance `alibaba` from `@ai-sdk/alibaba`:
26
+
27
+ ```ts
28
+ import { alibaba } from '@ai-sdk/alibaba';
29
+ ```
30
+
31
+ ## Language Model Example
32
+
33
+ ```ts
34
+ import { alibaba } from '@ai-sdk/alibaba';
35
+ import { generateText } from 'ai';
36
+
37
+ const { text } = await generateText({
38
+ model: alibaba('qwen-plus'),
39
+ prompt: 'Write a vegetarian lasagna recipe for 4 people.',
40
+ });
41
+ ```
42
+
43
+ ## Thinking Mode Example (Qwen Reasoning Models)
44
+
45
+ Alibaba's Qwen models support thinking/reasoning mode for complex problem-solving:
46
+
47
+ ```ts
48
+ import { alibaba } from '@ai-sdk/alibaba';
49
+ import { generateText } from 'ai';
50
+
51
+ const { text, reasoningText } = await generateText({
52
+ model: alibaba('qwen3-max'),
53
+ providerOptions: {
54
+ alibaba: {
55
+ enableThinking: true,
56
+ thinkingBudget: 2048,
57
+ },
58
+ },
59
+ prompt: 'How many "r"s are in the word "strawberry"?',
60
+ });
61
+
62
+ console.log('Reasoning:', reasoningText);
63
+ console.log('Answer:', text);
64
+ ```
65
+
66
+ ## Embedding Model Example
67
+
68
+ ```ts
69
+ import { alibaba, type AlibabaEmbeddingModelOptions } from '@ai-sdk/alibaba';
70
+ import { embed } from 'ai';
71
+
72
+ const { embedding, usage } = await embed({
73
+ model: alibaba.embedding('text-embedding-v4'),
74
+ value: 'sunny day at the beach',
75
+ providerOptions: {
76
+ alibaba: {
77
+ textType: 'document',
78
+ dimension: 1024,
79
+ outputType: 'dense',
80
+ } satisfies AlibabaEmbeddingModelOptions,
81
+ },
82
+ });
83
+ ```
84
+
85
+ ## Tool Calling Example
86
+
87
+ ```ts
88
+ import { alibaba } from '@ai-sdk/alibaba';
89
+ import { generateText, tool } from 'ai';
90
+ import { z } from 'zod';
91
+
92
+ const { text } = await generateText({
93
+ model: alibaba('qwen-plus'),
94
+ tools: {
95
+ weather: tool({
96
+ description: 'Get the weather in a location',
97
+ parameters: z.object({
98
+ location: z.string().describe('The location to get the weather for'),
99
+ }),
100
+ execute: async ({ location }) => ({
101
+ location,
102
+ temperature: 72 + Math.floor(Math.random() * 21) - 10,
103
+ }),
104
+ }),
105
+ },
106
+ prompt: 'What is the weather in San Francisco?',
107
+ });
108
+ ```
109
+
110
+ ## Explicit Caching Example
111
+
112
+ Alibaba supports both implicit and explicit prompt caching to reduce costs for repeated prompts.
113
+
114
+ **Implicit caching** works automatically - the provider caches appropriate content without any configuration. For more control, you can use **explicit caching** by marking specific messages with `cacheControl`:
115
+
116
+ ```ts
117
+ import { alibaba } from '@ai-sdk/alibaba';
118
+ import { generateText } from 'ai';
119
+
120
+ const longDocument = '... large document content ...';
121
+
122
+ const { text, usage } = await generateText({
123
+ model: alibaba('qwen-plus'),
124
+ messages: [
125
+ {
126
+ role: 'user',
127
+ content: [
128
+ {
129
+ type: 'text',
130
+ text: 'Context: Please analyze this document.',
131
+ },
132
+ {
133
+ type: 'text',
134
+ text: longDocument,
135
+ providerOptions: {
136
+ alibaba: {
137
+ cacheControl: { type: 'ephemeral' },
138
+ },
139
+ },
140
+ },
141
+ ],
142
+ },
143
+ ],
144
+ });
145
+ ```
146
+
147
+ **Note:** The minimum content length for a cache block is 1,024 tokens.
148
+
149
+ ## Documentation
150
+
151
+ Please check out the **[Alibaba provider documentation](https://ai-sdk.dev/providers/ai-sdk-providers/alibaba)** for more information.
@@ -0,0 +1,171 @@
1
+ import { z } from 'zod/v4';
2
+ import { ProviderV4, LanguageModelV4, EmbeddingModelV4, Experimental_VideoModelV4 } from '@ai-sdk/provider';
3
+ import { FetchFunction } from '@ai-sdk/provider-utils';
4
+
5
+ type AlibabaChatModelId = 'qwen3.7-max' | 'qwen3-max' | 'qwen3-max-preview' | 'qwen-plus' | 'qwen-plus-latest' | 'qwen-flash' | 'qwen-turbo' | 'qwen-turbo-latest' | 'qwen3-235b-a22b' | 'qwen3-32b' | 'qwen3-30b-a3b' | 'qwen3-14b' | 'qwen3-next-80b-a3b-thinking' | 'qwen3-235b-a22b-thinking-2507' | 'qwen3-30b-a3b-thinking-2507' | 'qwq-plus' | 'qwq-plus-latest' | 'qwq-32b' | 'qwen-coder' | 'qwen3-coder-plus' | 'qwen3-coder-flash' | (string & {});
6
+ declare const alibabaLanguageModelChatOptions: z.ZodObject<{
7
+ enableThinking: z.ZodOptional<z.ZodBoolean>;
8
+ thinkingBudget: z.ZodOptional<z.ZodNumber>;
9
+ parallelToolCalls: z.ZodOptional<z.ZodBoolean>;
10
+ }, z.core.$strip>;
11
+ type AlibabaLanguageModelChatOptions = z.infer<typeof alibabaLanguageModelChatOptions>;
12
+
13
+ type AlibabaCacheControl = {
14
+ type: string;
15
+ };
16
+
17
+ type AlibabaEmbeddingModelId = 'text-embedding-v4' | 'text-embedding-v3' | (string & {});
18
+ declare const alibabaEmbeddingModelOptions: z.ZodObject<{
19
+ textType: z.ZodOptional<z.ZodEnum<{
20
+ query: "query";
21
+ document: "document";
22
+ }>>;
23
+ dimension: z.ZodOptional<z.ZodNumber>;
24
+ outputType: z.ZodOptional<z.ZodEnum<{
25
+ dense: "dense";
26
+ sparse: "sparse";
27
+ "dense&sparse": "dense&sparse";
28
+ }>>;
29
+ }, z.core.$strip>;
30
+ type AlibabaEmbeddingModelOptions = z.infer<typeof alibabaEmbeddingModelOptions>;
31
+
32
+ type AlibabaVideoModelId = 'wan2.6-t2v' | 'wan2.5-t2v-preview' | 'wan2.7-t2v' | 'wan2.7-t2v-2026-06-12' | 'wan2.6-i2v' | 'wan2.6-i2v-flash' | 'wan2.6-r2v' | 'wan2.6-r2v-flash' | 'wan2.7-r2v' | 'wan2.7-r2v-2026-06-12' | (string & {});
33
+
34
+ interface AlibabaProvider extends ProviderV4 {
35
+ (modelId: AlibabaChatModelId): LanguageModelV4;
36
+ /**
37
+ * Creates a model for text generation.
38
+ */
39
+ languageModel(modelId: AlibabaChatModelId): LanguageModelV4;
40
+ /**
41
+ * Creates a chat model for text generation.
42
+ */
43
+ chatModel(modelId: AlibabaChatModelId): LanguageModelV4;
44
+ /**
45
+ * Creates a model for text embeddings.
46
+ */
47
+ embedding(modelId: AlibabaEmbeddingModelId): EmbeddingModelV4;
48
+ /**
49
+ * Creates a model for text embeddings.
50
+ */
51
+ embeddingModel(modelId: AlibabaEmbeddingModelId): EmbeddingModelV4;
52
+ /**
53
+ * Creates a model for video generation.
54
+ */
55
+ video(modelId: AlibabaVideoModelId): Experimental_VideoModelV4;
56
+ /**
57
+ * Creates a model for video generation.
58
+ */
59
+ videoModel(modelId: AlibabaVideoModelId): Experimental_VideoModelV4;
60
+ }
61
+ interface AlibabaProviderSettings {
62
+ /**
63
+ * Use a different URL prefix for API calls, e.g. to use proxy servers or regional endpoints.
64
+ * The default prefix is `https://dashscope-intl.aliyuncs.com/compatible-mode/v1`.
65
+ */
66
+ baseURL?: string;
67
+ /**
68
+ * Use a different URL prefix for video generation API calls.
69
+ * The video API uses the DashScope native endpoint (not the OpenAI-compatible endpoint).
70
+ * The default prefix is `https://dashscope-intl.aliyuncs.com`.
71
+ */
72
+ videoBaseURL?: string;
73
+ /**
74
+ * Use a different URL prefix for embedding API calls.
75
+ * The embedding API uses the DashScope native endpoint (not the OpenAI-compatible endpoint).
76
+ * The default prefix is `https://dashscope-intl.aliyuncs.com/api/v1`.
77
+ */
78
+ embeddingBaseURL?: string;
79
+ /**
80
+ * API key that is being sent using the `Authorization` header.
81
+ * It defaults to the `ALIBABA_API_KEY` environment variable.
82
+ */
83
+ apiKey?: string;
84
+ /**
85
+ * Custom headers to include in the requests.
86
+ */
87
+ headers?: Record<string, string>;
88
+ /**
89
+ * Custom fetch implementation. You can use it as a middleware to intercept requests,
90
+ * or to provide a custom fetch implementation for e.g. testing.
91
+ */
92
+ fetch?: FetchFunction;
93
+ /**
94
+ * Include usage information in streaming responses.
95
+ * When enabled, token usage will be included in the final chunk.
96
+ *
97
+ * @default true
98
+ */
99
+ includeUsage?: boolean;
100
+ }
101
+ /**
102
+ * Create an Alibaba Cloud (Qwen) provider instance.
103
+ */
104
+ declare function createAlibaba(options?: AlibabaProviderSettings): AlibabaProvider;
105
+ declare const alibaba: AlibabaProvider;
106
+
107
+ type AlibabaVideoModelOptions = {
108
+ /** Negative prompt to specify what to avoid (max 500 chars). */
109
+ negativePrompt?: string | null;
110
+ /** URL to audio file for audio-video sync (WAV/MP3, 3-30s, max 15MB). */
111
+ audioUrl?: string | null;
112
+ /** Enable prompt extension/rewriting for better generation. Defaults to true. */
113
+ promptExtend?: boolean | null;
114
+ /**
115
+ * Shot type: 'single' for single-shot or 'multi' for multi-shot narrative
116
+ * (wan2.6 and earlier; wan2.7 models describe shot structure in the prompt).
117
+ */
118
+ shotType?: 'single' | 'multi' | null;
119
+ /** Whether to add watermark to generated video. Defaults to false. */
120
+ watermark?: boolean | null;
121
+ /**
122
+ * Enable audio generation (for wan2.6 I2V/R2V models;
123
+ * wan2.7 models always generate audio).
124
+ */
125
+ audio?: boolean | null;
126
+ /**
127
+ * Reference URLs for reference-to-video mode (wan2.6 models).
128
+ * Array of URLs to images (0-5) and/or videos (0-3), max 5 total.
129
+ * Use character identifiers (character1, character2) in prompts to reference them.
130
+ */
131
+ referenceUrls?: string[] | null;
132
+ /**
133
+ * Explicit media array for reference-to-video mode (wan2.7 models).
134
+ * Overrides the automatic mapping from `inputReferences` and `frameImages`.
135
+ * Use `Image 1`, `Video 1`, etc. in prompts to reference media items
136
+ * (images and videos are counted separately, in array order).
137
+ */
138
+ media?: Array<{
139
+ type: 'reference_image' | 'reference_video' | 'first_frame';
140
+ /** Public URL, or a `data:{mime};base64,{data}` URI for images. */
141
+ url: string;
142
+ /** URL to an audio file used as voice reference for this media item. */
143
+ referenceVoice?: string | null;
144
+ }> | null;
145
+ /**
146
+ * Aspect ratio (wan2.7 text-to-video and reference-to-video models).
147
+ */
148
+ ratio?: '16:9' | '9:16' | '1:1' | '4:3' | '3:4' | null;
149
+ /** Polling interval in milliseconds. Defaults to 5000 (5 seconds). */
150
+ pollIntervalMs?: number | null;
151
+ /** Maximum wait time in milliseconds for video generation. Defaults to 600000 (10 minutes). */
152
+ pollTimeoutMs?: number | null;
153
+ [key: string]: unknown;
154
+ };
155
+
156
+ type AlibabaUsage = {
157
+ prompt_tokens?: number | null;
158
+ completion_tokens?: number | null;
159
+ total_tokens?: number | null;
160
+ prompt_tokens_details?: {
161
+ cached_tokens?: number | null;
162
+ cache_creation_input_tokens?: number | null;
163
+ } | null;
164
+ completion_tokens_details?: {
165
+ reasoning_tokens?: number | null;
166
+ } | null;
167
+ };
168
+
169
+ declare const VERSION: string;
170
+
171
+ export { type AlibabaCacheControl, type AlibabaChatModelId, type AlibabaEmbeddingModelId, type AlibabaEmbeddingModelOptions, type AlibabaLanguageModelChatOptions, type AlibabaLanguageModelChatOptions as AlibabaLanguageModelOptions, type AlibabaProvider, type AlibabaLanguageModelChatOptions as AlibabaProviderOptions, type AlibabaProviderSettings, type AlibabaUsage, type AlibabaVideoModelId, type AlibabaVideoModelOptions, type AlibabaVideoModelOptions as AlibabaVideoProviderOptions, VERSION, alibaba, createAlibaba };