Integration Guide

Vercel AI SDK + AIPower

Stream responses from 16 AI models in your Next.js app. GPT, Claude, DeepSeek, Qwen — all through @ai-sdk/openai with a custom provider.

Get free API key

Setup (3 minutes)

1. Install packages

npm install ai @ai-sdk/openai

2. Create AIPower provider (app/api/chat/route.ts)

import { createOpenAI } from '@ai-sdk/openai';
import { streamText } from 'ai';

// Custom AIPower provider (reuses @ai-sdk/openai)
const aipower = createOpenAI({
  baseURL: 'https://api.aipower.me/v1',
  apiKey: process.env.AIPOWER_API_KEY,
});

export async function POST(req: Request) {
  const { messages } = await req.json();

  const result = streamText({
    model: aipower('deepseek/deepseek-chat'),  // or auto, gpt-5.4, claude-sonnet
    messages,
  });

  return result.toDataStreamResponse();
}

3. Use in your React component

'use client';
import { useChat } from 'ai/react';

export default function Chat() {
  const { messages, input, handleInputChange, handleSubmit } = useChat();

  return (
    <div>
      {messages.map(m => (
        <div key={m.id}>
          <b>{m.role}:</b> {m.content}
        </div>
      ))}
      <form onSubmit={handleSubmit}>
        <input value={input} onChange={handleInputChange} />
      </form>
    </div>
  );
}

Advanced patterns

Smart routing with model="auto"

// Let AIPower pick the optimal model per request
const result = streamText({
  model: aipower('auto'),  // or auto-cheap, auto-code, auto-best
  messages,
});

Tool calling with Claude Sonnet

import { tool } from 'ai';
import { z } from 'zod';

const result = streamText({
  model: aipower('anthropic/claude-sonnet'),  // Best for tool use
  messages,
  tools: {
    getWeather: tool({
      description: 'Get current weather',
      parameters: z.object({ city: z.string() }),
      execute: async ({ city }) => {
        const res = await fetch(`https://wttr.in/${city}?format=j1`);
        return res.json();
      },
    }),
  },
});

Edge runtime

// app/api/chat/route.ts
export const runtime = 'edge';  // AIPower works on Vercel Edge

// AIPower API is on Cloudflare Workers
// Edge -> Edge = sub-50ms latency

Example apps you can build

💬 Multi-model chatbot

Let users pick between GPT, Claude, DeepSeek in dropdown. Real-time streaming via SSE.

🔍 AI search app

Use DeepSeek V3 for summarization (cheap), Claude Opus for complex analysis (quality).

🌐 Translation app

Qwen Plus for Chinese/English (best quality), Gemini for other languages.

📝 Content generator

Use GLM-4 Flash ($0.01/M) for drafts, GPT-5.4 for polishing.

Ship AI features faster

Vercel AI SDK + AIPower = 16 models in one Next.js app. 50 free calls, no credit card.

Get free API key