Skip to navigation

Vercel AI SDK

Use the OpenAI-compatible provider.

npm install ai @ai-sdk/openai-compatible
lib/flow.ts
import { createOpenAICompatible } from '@ai-sdk/openai-compatible'
export const flow = createOpenAICompatible({
name: 'flow',
baseURL: 'https://ai.hyperflow.fun/v1',
apiKey: process.env.HYPERFLOW_API_KEY,
includeUsage: true,
})

Generate text

import { generateText } from 'ai'
import { flow } from './lib/flow'
const { text, usage } = await generateText({
model: flow('openai/gpt-6-luna'),
prompt: 'Write a haiku about the sea.',
})

Stream

import { streamText } from 'ai'
import { flow } from './lib/flow'
const result = streamText({
model: flow('openai/gpt-6-luna'),
prompt: 'Write a haiku about the sea.',
})
for await (const part of result.textStream) process.stdout.write(part)

In a Next.js route handler, return result.toUIMessageStreamResponse() to stream to useChat.

Tools

import { generateText, stepCountIs, tool } from 'ai'
import { z } from 'zod'
import { flow } from './lib/flow'
const { text } = await generateText({
model: flow('openai/gpt-6-luna'),
tools: {
getWeather: tool({
description: 'Current weather for a city',
inputSchema: z.object({ city: z.string() }),
execute: async ({ city }) => ({ city, temperatureC: 31 }),
}),
},
stopWhen: stepCountIs(3),
prompt: "What's the weather in Hanoi?",
})

Embeddings

import { embedMany } from 'ai'
import { flow } from './lib/flow'
const { embeddings } = await embedMany({
model: flow.textEmbeddingModel('cohere/cohere-embed-v4'),
values: ['Hello!', 'How are you?'],
})