Documentation Index
Fetch the complete documentation index at: https://docs.deepinfra.com/llms.txt
Use this file to discover all available pages before exploring further.
The AI SDK by Vercel is the AI toolkit for TypeScript and JavaScript from the creators of Next.js. DeepInfra has a first-party AI SDK provider.
See the full AI SDK docs for DeepInfra.
Installation
npm install ai @ai-sdk/deepinfra
Get your API key from the Dashboard.
Text generation
import { createDeepInfra } from "@ai-sdk/deepinfra";
import { generateText } from "ai";
const deepinfra = createDeepInfra({ apiKey: "$DEEPINFRA_TOKEN" });
const { text, usage, finishReason } = await generateText({
model: deepinfra("deepseek-ai/DeepSeek-V3"),
prompt: "Write a vegetarian lasagna recipe for 4 people.",
});
console.log(text);
With a system message:
const { text } = await generateText({
model: deepinfra("deepseek-ai/DeepSeek-V3"),
prompt: "Write a vegetarian lasagna recipe for 4 people.",
system: "You are a professional writer. You write simple, clear, and concise content.",
});
Streaming
import { createDeepInfra } from "@ai-sdk/deepinfra";
import { streamText } from "ai";
const deepinfra = createDeepInfra({ apiKey: "$DEEPINFRA_TOKEN" });
const result = streamText({
model: deepinfra("deepseek-ai/DeepSeek-V3"),
prompt: "Invent a new holiday and describe its traditions.",
system: "You are a professional writer. You write simple, clear, and concise content.",
});
for await (const textPart of result.textStream) {
process.stdout.write(textPart);
}
Conversations
const { text } = await generateText({
model: deepinfra("deepseek-ai/DeepSeek-V3"),
messages: [
{ role: "system", content: "Respond like a michelin starred chef." },
{ role: "user", content: "Can you name at least two different techniques to cook lamb?" },
{ role: "assistant", content: "Bonjour! Let me tell you..." },
{ role: "user", content: "Tell me more about the second method." },
],
});
Streaming conversations work the same way — use streamText with messages.
Structured data
Generate typed, structured output using Zod schemas:
import { createDeepInfra } from "@ai-sdk/deepinfra";
import { generateObject } from "ai";
import { z } from "zod";
const deepinfra = createDeepInfra({ apiKey: "$DEEPINFRA_TOKEN" });
const { object } = await generateObject({
model: deepinfra("deepseek-ai/DeepSeek-V3"),
schema: z.object({
recipe: z.object({
name: z.string(),
ingredients: z.array(z.object({ name: z.string(), amount: z.string() })),
steps: z.array(z.string()),
}),
}),
prompt: "Generate a lasagna recipe.",
});
console.log(object.recipe.name);
Enum output:
const { object } = await generateObject({
model: deepinfra("deepseek-ai/DeepSeek-V3"),
output: "enum",
enum: ["action", "comedy", "drama", "horror", "sci-fi"],
prompt: 'Classify: "A group of astronauts travel through a wormhole..."',
});
import { createDeepInfra } from "@ai-sdk/deepinfra";
import { generateText, tool } from "ai";
import { z } from "zod";
const deepinfra = createDeepInfra({ apiKey: "$DEEPINFRA_TOKEN" });
const result = await generateText({
model: deepinfra("deepseek-ai/DeepSeek-V3"),
tools: {
weather: tool({
description: "Get the weather in a location",
parameters: z.object({
location: z.string().describe("The location to get the weather for"),
}),
execute: async ({ location }) => ({
location,
temperature: 72 + Math.floor(Math.random() * 21) - 10,
}),
}),
},
prompt: "What is the weather in San Francisco?",
maxSteps: 2,
});
console.log(result.text);