Integrations
Connect DEVUP AI to the Vercel AI SDK 7 using the official devupai/ai integration, part of the devupai 4.0.0 package. Build generative AI applications in Next.js and Node.js with text generation, streaming with token usage, embeddings, tool calling, and streaming route handlers.
ai 7, @ai-sdk/openai-compatible 3, and @ai-sdk/provider 4. The integration uses both @ai-sdk/* packages, so install both.devupai/ai is ESM-only. Load it with import, not require.Install the DEVUP AI SDK, the Vercel AI SDK core library, and its two peer packages:
npm install devupai ai @ai-sdk/openai-compatible @ai-sdk/providerCreate the integration instance by importing createDevupAI from devupai/ai:
import { createDevupAI } from "devupai/ai";
const devupai = createDevupAI({
apiKey: process.env.DEVUP_API_KEY!,
});createDevupAI() takes apiKey, baseURL, headers, fetch, and models.apiKey is omitted, the integration reads DEVUP_API_KEY, then DEVUPAI_API_KEY, from the environment when a request is made. With no key, the request throws LoadAPIKeyError. A default instance is exported as devupai.devupai/ai only. The core DevupAI client takes its key from the apiKey option: new DevupAI({ apiKey: process.env.DEVUP_API_KEY! }).devupai(id), devupai.languageModel(id), and devupai.chatModel(id) return LanguageModelV4; devupai.embeddingModel(id) returns EmbeddingModelV4; devupai.imageModel(id) returns ImageModelV4 for text-to-image generation.DevupAIIntegrationSettings and DevupAIModelData, and the integration type as DevupAIIntegration.Generate non-streaming text completions using generateText. The result carries the token count in usage:
import { generateText } from "ai";
import { createDevupAI } from "devupai/ai";
const devupai = createDevupAI({
apiKey: process.env.DEVUP_API_KEY!,
});
async function main() {
const { text, usage } = await generateText({
model: devupai("deepseek-ai/DeepSeek-V4.1-Flash-1017"),
prompt: "Explain neural networks in simple terms.",
});
console.log(text);
console.log("Tokens:", usage.totalTokens);
}
main().catch(console.error);Stream tokens in real time using streamText and iterate over textStream. Streaming requests send stream_options: { include_usage: true }, so usage is available on the result once the stream ends:
import { streamText } from "ai";
import { createDevupAI } from "devupai/ai";
const devupai = createDevupAI({
apiKey: process.env.DEVUP_API_KEY!,
});
async function main() {
const result = streamText({
model: devupai("deepseek-ai/DeepSeek-V4.1-Flash-1017"),
prompt: "Write a short story set in Algiers.",
});
for await (const text of result.textStream) {
process.stdout.write(text);
}
console.log("\nTokens:", (await result.usage).totalTokens);
}
main().catch(console.error);Create vector embeddings with devupai.embeddingModel(id) and the AI SDK's embed or embedMany:
import { embed } from "ai";
import { createDevupAI } from "devupai/ai";
const devupai = createDevupAI({
apiKey: process.env.DEVUP_API_KEY!,
});
async function main() {
const { embedding } = await embed({
model: devupai.embeddingModel("BAAI/bge-m3"),
value: "Sunny day at the beach",
});
console.log("Dimensions:", embedding.length);
}
main().catch(console.error);devupai.imageModel(id) generates images from text with generateImage. It accepts text prompts only; for image edits, use client.images.edit() from the core SDK.
Pass the model list from GET /v1/models as models. For each model whose supports.structured_output is true, structured output requests then use a json_schema response format. Without models, the adapter default applies:
import DevupAI from "devupai";
import { createDevupAI } from "devupai/ai";
const apiKey = process.env.DEVUP_API_KEY!;
const client = new DevupAI({ apiKey });
const { data: models } = await client.models.list();
const devupai = createDevupAI({ apiKey, models });Define typed tools with Zod schemas and run them across several steps. This example also needs Zod:
npm install zodimport { generateText, tool, stepCountIs } from "ai";
import { createDevupAI } from "devupai/ai";
import { z } from "zod";
const devupai = createDevupAI({
apiKey: process.env.DEVUP_API_KEY!,
});
const getWeather = tool({
description: "Get the current weather for a city",
inputSchema: z.object({
city: z.string().describe("The name of the city"),
}),
execute: async ({ city }) => {
return { city, temperature: "22C" };
},
});
async function main() {
const result = await generateText({
model: devupai("deepseek-ai/DeepSeek-V4.1-Flash-1017"),
prompt: "What is the weather in Algiers? Use the get_weather tool.",
tools: { get_weather: getWeather },
stopWhen: stepCountIs(2),
});
const toolNames = result.steps.flatMap((step) => step.toolCalls.map((call) => call.toolName));
console.log("Tools called:", toolNames);
console.log("Final text:", result.text.trim());
console.log("Tokens:", result.totalUsage.totalTokens);
}
main().catch(console.error);result.steps lists the tool calls of every step, and result.totalUsage sums the tokens of all steps.
Return a streaming HTTP response from an App Router route handler, as plain text with toTextStreamResponse, or as a UI message stream for useChat with toUIMessageStreamResponse:
import { streamText } from "ai";
import { createDevupAI } from "devupai/ai";
const devupai = createDevupAI({
apiKey: process.env.DEVUP_API_KEY!,
});
export async function POST(request: Request) {
const body = await request.json();
const result = streamText({
model: devupai("deepseek-ai/DeepSeek-V4.1-Flash-1017"),
messages: body.messages,
});
return result.toTextStreamResponse();
}