Hugging Face reasoning output streaming example
For reasoning models like deepseek-ai/DeepSeek-R1, streaming responses include parts with type 'reasoning' for the reasoning process and type 'text-delta' for the text output. Example:
import { huggingFace } from '@ai-sdk/huggingface';
import { streamText } from 'ai';
const result = streamText({
model: huggingFace('deepseek-ai/DeepSeek-R1'),
prompt: 'How many r letters are in the word strawberry?',
providerOptions: {
huggingface: {
reasoningEffort: 'high',
},
},
});
for await (const part of result.stream) {
if (part.type === 'reasoning') {
console.log(`Reasoning: ${part.textDelta}`);
} else if (part.type === 'text-delta') {
process.stdout.write(part.textDelta);
}
}
Hugging Face reasoning output non-streaming example
For non-streaming generateText calls with reasoning models, the reasoning content is available in the 'reasoning' field of the response. Example:
import { huggingFace } from '@ai-sdk/huggingface';
import { generateText } from 'ai';
const result = await generateText({
model: huggingFace('deepseek-ai/DeepSeek-R1'),
prompt: 'What is 25 * 37?',
providerOptions: {
huggingface: {
reasoningEffort: 'medium',
},
},
});
console.log('Reasoning:', result.reasoning);
console.log('Answer:', result.text);
Hugging Face image input with file data example
For vision-capable models like Qwen/Qwen2.5-VL-7B-Instruct, images can be passed as part of message content. Example:
import { huggingFace } from '@ai-sdk/huggingface';
import { generateText } from 'ai';
import { readFileSync } from 'fs';
const result = await generateText({
model: huggingFace('Qwen/Qwen2.5-VL-7B-Instruct'),
messages: [
{
role: 'user',
content: [
{ type: 'text', text: 'Describe this image in detail.' },
{
type: 'file',
mediaType: 'image',
data: readFileSync('./image.png'),
},
],
},
],
});
Hugging Face image input with URL example
Images can also be passed as URLs in the format: { type: 'file', mediaType: 'image', data: 'https://example.com/image.png' }
Hugging Face model capabilities table
Model capabilities for Hugging Face: meta-llama/Llama-3.1-8B-Instruct (Image Input: No, Object Generation: Yes, Tool Usage: Yes, Tool Streaming: Yes); meta-llama/Llama-3.1-70B-Instruct (Image Input: No, Object Generation: Yes, Tool Usage: Yes, Tool Streaming: Yes); meta-llama/Llama-3.3-70B-Instruct (Image Input: No, Object Generation: Yes, Tool Usage: Yes, Tool Streaming: Yes); meta-llama/Llama-4-Maverick-17B-128E-Instruct (Image Input: No, Object Generation: Yes, Tool Usage: Yes, Tool Streaming: Yes); deepseek-ai/DeepSeek-V3.1 (Image Input: No, Object Generation: Yes, Tool Usage: Yes, Tool Streaming: Yes); deepseek-ai/DeepSeek-V3-0324 (Image Input: No, Object Generation: Yes, Tool Usage: Yes, Tool Streaming: Yes); deepseek-ai/DeepSeek-R1 (Image Input: No, Object Generation: Yes, Tool Usage: Yes, Tool Streaming: Yes); deepseek-ai/DeepSeek-R1-Distill-Llama-70B (Image Input: No, Object Generation: Yes, Tool Usage: Yes, Tool Streaming: Yes); Qwen/Qwen3-32B (Image Input: No, Object Generation: Yes, Tool Usage: Yes, Tool Streaming: Yes); Qwen/Qwen3-Coder-480B-A35B-Instruct (Image Input: No, Object Generation: Yes, Tool Usage: Yes, Tool Streaming: Yes); Qwen/Qwen2.5-VL-7B-Instruct (Image Input: Yes, Object Generation: Yes, Tool Usage: Yes, Tool Streaming: Yes); google/gemma-3-27b-it (Image Input: No, Object Generation: Yes, Tool Usage: Yes, Tool Streaming: Yes); moonshotai/Kimi-K2-Instruct (Image Input: No, Object Generation: Yes, Tool Usage: Yes, Tool Streaming: Yes).
Hugging Face models support matrix
Hugging Face models and their capabilities: meta-llama/Llama-3.1-8B-Instruct and moonshotai/Kimi-K2-Instruct do not support Image Input but both support Object Generation, Tool Usage, and Tool Streaming.