Alibaba thinking mode example
To enable thinking mode for Qwen models, pass providerOptions with enableThinking and thinkingBudget: `const { text, reasoning } = await generateText({ model: alibaba('qwen3-max'), providerOptions: { alibaba: { enableThinking: true, thinkingBudget: 2048 } }, prompt: 'How many "r"s are in the word "strawberry"?' });` The result includes both reasoning and text properties. For thinking-only models like `qwen3-235b-a22b-thinking-2507`, thinking mode is enabled by default.
Alibaba prompt caching support
Alibaba supports both implicit and explicit prompt caching. Implicit caching works automatically. For explicit caching, mark specific messages with `cacheControl: { type: 'ephemeral' }` in providerOptions. The minimum content length for a cache block is 1,024 tokens.
Alibaba single message cache control example
To enable cache control on a single message: `const { text, usage } = await generateText({ model: alibaba('qwen-plus'), messages: [{ role: 'system', content: 'You are a helpful assistant. [... long system prompt ...]', providerOptions: { alibaba: { cacheControl: { type: 'ephemeral' } } } }] });`
Alibaba multi-part message cache control example
To enable cache control on specific parts of a multi-part message: `const { text, usage } = await generateText({ model: alibaba('qwen-plus'), messages: [{ role: 'user', content: [{ type: 'text', text: 'Context: Please analyze this document.' }, { type: 'text', text: longDocument, providerOptions: { alibaba: { cacheControl: { type: 'ephemeral' } } } }] }] });`
Alibaba embedding model usage example
To generate embeddings with the `embed` function: `const { embedding, usage } = await embed({ model: alibaba.embedding('text-embedding-v4'), value: 'sunny day at the beach', providerOptions: { alibaba: { textType: 'document', dimension: 1024, outputType: 'dense' } } });`
Alibaba embedMany example
To embed multiple text values: `const { embeddings } = await embedMany({ model: alibaba.embedding('text-embedding-v4'), values: ['sunny day at the beach', 'rainy afternoon in the city', 'snowy night in the mountains'], providerOptions: { alibaba: { textType: 'document', dimension: 1024 } } });` Alibaba text embedding models support up to 10 values per API call; larger batches are split automatically.
Alibaba text-to-video example
To generate videos from text prompts: `const { video } = await generateVideo({ model: alibaba.video('wan2.6-t2v'), prompt: 'A serene mountain lake at sunset with gentle ripples on the water.', resolution: '1280x720', duration: 5, providerOptions: { alibaba: { promptExtend: true, pollTimeoutMs: 600000 } } });`
Alibaba wan2.7 text-to-video with aspect ratio
wan2.7 text-to-video models support the `aspectRatio` option and always generate audio. Multi-shot structure is described directly in the prompt. Example: `const { video } = await generateVideo({ model: alibaba.video('wan2.7-t2v'), prompt: 'A serene mountain lake at sunset. The camera pans across the water, then cuts to a close-up of ripples catching the light.', resolution: '1920x1080', aspectRatio: '16:9', duration: 5 });`
Alibaba image-to-video example with URL
To generate videos from a first-frame image: `const { video } = await generateVideo({ model: alibaba.video('wan2.6-i2v'), prompt: { image: 'https://example.com/landscape.jpg', text: 'Camera slowly pans across the landscape' }, duration: 5, providerOptions: { alibaba: { pollTimeoutMs: 600000 } } });`
Alibaba image-to-video with frameImages option
First frame can be passed using the top-level `frameImages` option: `const { video } = await generateVideo({ model: alibaba.video('wan2.6-i2v'), prompt: 'Camera slowly pans across the landscape', frameImages: [{ image: 'https://example.com/landscape.jpg', frameType: 'first_frame' }], duration: 5, providerOptions: { alibaba: { pollTimeoutMs: 600000 } } });`
Alibaba reference-to-video wan2.6 example
For wan2.6 models, use character identifiers (character1, character2, etc.) in the prompt to reference them. Example: `const { video } = await generateVideo({ model: alibaba.video('wan2.6-r2v-flash'), prompt: 'character1 walks through a beautiful garden and waves at the camera', resolution: '1280x720', duration: 5, inputReferences: ['https://example.com/character-reference.jpg'], providerOptions: { alibaba: { pollTimeoutMs: 600000 } } });`
Alibaba reference-to-video wan2.7 example
For wan2.7 models, use `Image 1`, `Image 2`, `Video 1`, etc. in the prompt. Image references can be public URLs or inline file data; video references must be public URLs. Example: `const { video } = await generateVideo({ model: alibaba.video('wan2.7-r2v'), prompt: 'Image 1 walks through the scene shown in Image 2.', resolution: '1920x1080', duration: 5, inputReferences: [imageBytes, 'https://example.com/background.png'], providerOptions: { alibaba: { ratio: '16:9', pollTimeoutMs: 600000 } } });`
Alibaba wan2.7 explicit media array example
For full control over wan2.7 media array, use the `media` provider option which overrides automatic mapping: `const { video } = await generateVideo({ model: alibaba.video('wan2.7-r2v'), prompt: 'Video 1 walks into the room. Image 1 looks up and says hello.', providerOptions: { alibaba: { media: [{ type: 'reference_video', url: 'https://example.com/character.mp4', referenceVoice: 'https://example.com/voice.mp3' }, { type: 'reference_image', url: 'https://example.com/scene.png' }, { type: 'first_frame', url: 'https://example.com/opening-frame.png' }] } } });`
Alibaba Qwen models support matrix
Alibaba Qwen models and their capabilities: qwen3-max does not support Image Input but supports Object Generation, Tool Usage, and Tool Streaming; qwen-plus does not support Image Input but supports Object Generation, Tool Usage, and Tool Streaming.