Alibaba
Learn how to use Alibaba Cloud Model Studio (Qwen) models with the AI SDK.
Alibaba Cloud Model Studio provides access to the Qwen model series, including advanced reasoning capabilities.
API keys can be obtained from the Console.
Setup
The Alibaba provider is available via the @ai-sdk/alibaba module. You can install it with:
$ pnpm add @ai-sdk/alibaba
$ npm install @ai-sdk/alibaba
$ yarn add @ai-sdk/alibaba
$ bun add @ai-sdk/alibaba
Provider Instance
You can import the default provider instance alibaba from @ai-sdk/alibaba:
For custom configuration, you can import createAlibaba and create a provider instance with your settings:
You can use the following optional settings to customize the Alibaba provider instance:
-
baseURL string
Use a different URL prefix for API calls, e.g. to use proxy servers or regional endpoints. The default prefix is
https://dashscope-intl.aliyuncs.com/compatible-mode/v1. -
videoBaseURL string
Use a different URL prefix for video generation API calls. The video API uses the DashScope native endpoint (not the OpenAI-compatible endpoint). The default prefix is
https://dashscope-intl.aliyuncs.com. -
embeddingBaseURL string
Use a different URL prefix for embedding API calls. The embedding API uses the DashScope native endpoint (not the OpenAI-compatible endpoint). The default prefix is
https://dashscope-intl.aliyuncs.com/api/v1. -
apiKey string
API key that is being sent using the
Authorizationheader. It defaults to theALIBABA_API_KEYenvironment variable. -
headers Record<string,string>
Custom headers to include in the requests.
-
fetch (input: RequestInfo, init?: RequestInit) => Promise<Response>
Custom fetch implementation.
-
includeUsage boolean
Include usage information in streaming responses. When enabled, token usage will be included in the final chunk. Defaults to
true.
Language Models
You can create language models using a provider instance:
You can also use the .chatModel() or .languageModel() factory methods:
Alibaba language models can be used in the streamText function
(see AI SDK Core).
The following optional provider options are available for Alibaba models:
-
enableThinking boolean
Enable thinking/reasoning mode for supported models. When enabled, the model generates reasoning content before the response. Defaults to
false. -
thinkingBudget number
Maximum number of reasoning tokens to generate. Limits the length of thinking content.
-
preserveThinking boolean
Preserve reasoning from previous assistant messages for supported models. When enabled, reasoning is sent separately as Alibaba
reasoning_contentandpreserve_thinkingis enabled. Defaults totruefor models that support preserved thinking; set tofalseto opt out. Append AI SDKresponseMessagesunchanged when continuing the conversation. See Alibaba's preserved-thinking documentation for the list of supported models. -
parallelToolCalls boolean
Whether to enable parallel function calling during tool use. Defaults to
true.
Thinking Mode
Alibaba's Qwen models support thinking/reasoning mode for complex problem-solving:
For models that are thinking-only (like qwen3-235b-a22b-thinking-2507), thinking mode is enabled by default.
Preserved Thinking in Multi-Turn Conversations
For models that support preserved thinking, the AI SDK replays reasoning from
previous assistant messages as Alibaba reasoning_content by default, so the
model can build on its earlier thought process:
When continuing the conversation, append responseMessages unchanged. If you
rebuild assistant history from visible text only, the reasoning parts are
discarded before the provider can serialize them as reasoning_content. Set
preserveThinking: false to opt out of replay, and note the following caveats:
preserveThinkingdoes not enable thinking by itself. Pair it withenableThinking/thinkingBudgetor the top-levelreasoningoption.- It is enabled by default only for models that Alibaba documents as supporting
preserved thinking; for other models,
preserve_thinkingis not sent unless you set the option explicitly. See Alibaba's preserved-thinking documentation for the current list of supported models. - Reasoning from the current tool-call round (after the last user message) is always sent back with tool results, as Alibaba recommends; the option only controls reasoning from earlier rounds.
- Preserved reasoning increases input token usage and billing.
- Historical reasoning remains separate from visible assistant text; it is never
merged into
content.
Tool Calling
Alibaba models support tool calling with parallel execution:
Prompt Caching
Alibaba supports both implicit and explicit prompt caching to reduce costs for repeated prompts.
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:
Single message cache control
Multi-part message cache control
Note: The minimum content length for a cache block is 1,024 tokens.
Embedding Models
You can create text embedding models using the .embedding() factory method.
For more on embeddings with the AI SDK see embed()
and embedMany().
You can use Alibaba embedding models to generate embeddings with the embed function:
Use embedMany to embed multiple text values. Alibaba text embedding models support
up to 10 values per API call; larger batches are split automatically by embedMany.
Alibaba embedding models support additional provider options that can be passed via
providerOptions.alibaba:
-
textType 'query' | 'document'
Differentiates query text from document text for asymmetric retrieval tasks. Defaults to
document. -
dimension number
The dimension of the output embedding vectors. Defaults to 1024.
text-embedding-v4also supports 1536 and 2048 dimensions. -
outputType 'dense' | 'sparse' | 'dense&sparse'
Specifies the output vector type. Defaults to
dense. The AI SDK embedding interface returns densenumber[]vectors, so sparse-only output is not supported and will throw. Usedense&sparseto receive dense embeddings inembedding/embeddingsand sparse vectors inproviderMetadata.alibaba.sparseEmbeddings.
Embedding Model Capabilities
| Model | Default Dimensions | Flexible Dimensions | Max Values per Call |
|---|---|---|---|
text-embedding-v4 | 1024 | 64, 128, 256, 512, 768, 1024, 1536, 2048 | 10 |
text-embedding-v3 | 1024 | 512, 768, 1024 | 10 |
The tables above list currently documented Alibaba text embedding models. You can also pass any available provider model ID as a string if needed.
Video Models
You can create Wan video models that call the Alibaba Cloud DashScope API
using the .video() factory method. For more on video generation with the AI SDK see generateVideo().
Alibaba supports three video generation modes: text-to-video, image-to-video (first frame), and reference-to-video.
Text-to-Video
Generate videos from text prompts:
wan2.7 models additionally support the aspectRatio option (mapped to the
API's ratio parameter) and always generate audio. Multi-shot structure is
described directly in the prompt instead of the shotType option:
Image-to-Video
Generate videos from a first-frame image and optional text prompt:
You can also pass the first frame using the top-level frameImages option:
Reference-to-Video
Generate videos using reference images and/or videos for character consistency.
For wan2.6 models, use character identifiers (character1, character2, etc.)
in your prompt to reference them. References must be public URLs:
For wan2.7 models, use Image 1, Image 2, Video 1, etc. in your prompt
(images and videos are counted separately, in reference order). Image references
can be public URLs or inline file data; video references must be public URLs:
For full control over the wan2.7 media array (e.g. voice references or explicit
media types), use the media provider option, which overrides the automatic
mapping from inputReferences and frameImages:
Video Provider Options
The following provider options are available via providerOptions.alibaba:
-
negativePrompt string
A description of what to avoid in the generated video (max 500 characters).
-
audioUrl string
URL to an audio file for audio-video sync (WAV/MP3, 3-30 seconds, max 15MB).
-
promptExtend boolean
Enable prompt extension/rewriting for better generation quality. Defaults to
true. -
shotType
'single'|'multi'Shot type for video generation.
'multi'enables multi-shot cinematic narrative (wan2.6 models only). -
watermark boolean
Whether to add a watermark to the generated video. Defaults to
false. -
audio boolean
Whether to generate audio (for
wan2.6I2V and R2V models;wan2.7models always generate audio). -
referenceUrls string[]
Array of reference image/video URLs for reference-to-video mode (
wan2.6models). Supports 0-5 images and 0-3 videos, max 5 total. Prefer the top-levelinputReferencesoption when passing reference images. -
media Array<{ type, url, referenceVoice? }>
Explicit media array for reference-to-video mode (
wan2.7models). Each item has atype('reference_image','reference_video', or'first_frame'), aurl(public URL, or adata:{mime};base64,{data}URI for images), and an optionalreferenceVoiceaudio URL. Overrides the automatic mapping frominputReferencesandframeImages. -
ratio
'16:9'|'9:16'|'1:1'|'4:3'|'3:4'Aspect ratio (
wan2.7text-to-video and reference-to-video models). The top-levelaspectRatiooption is mapped to this parameter automatically. -
pollIntervalMs number
Polling interval in milliseconds for checking task status. Defaults to 5000.
-
pollTimeoutMs number
Maximum wait time in milliseconds for video generation. Defaults to 600000 (10 minutes).
Video generation is an asynchronous process that can take several minutes.
Consider setting pollTimeoutMs to at least 10 minutes (600000ms) for
reliable operation.
Video Model Capabilities
Text-to-Video
| Model | Audio | Resolution | Duration |
|---|---|---|---|
wan2.6-t2v | Yes | 720P, 1080P | 2-15s |
wan2.5-t2v-preview | Yes | 480P, 720P, 1080P | 5s, 10s |
wan2.7-t2v | Yes | 720P, 1080P | 2-15s |
wan2.7-t2v-2026-06-12 | Yes | 720P, 1080P | 2-15s |
Image-to-Video (First Frame)
| Model | Audio | Resolution | Duration |
|---|---|---|---|
wan2.6-i2v-flash | Optional | 720P, 1080P | 2-15s |
wan2.6-i2v | Yes | 720P, 1080P | 2-15s |
Reference-to-Video
| Model | Audio | Resolution | Duration |
|---|---|---|---|
wan2.6-r2v-flash | Optional | 720P, 1080P | 2-10s |
wan2.6-r2v | Yes | 720P, 1080P | 2-10s |
wan2.7-r2v | Yes | 720P, 1080P | 2-10s (with video ref), 2-15s |
wan2.7-r2v-2026-06-12 | Yes | 720P, 1080P | 2-10s (with video ref), 2-15s |
The tables above list models available in the Singapore International region. You can also pass any available provider model ID as a string if needed.
Model Capabilities
Please see the Alibaba Cloud Model Studio docs for a full list of available models. You can also pass any available provider model ID as a string if needed.