Skip to navigation

Vercel AI SDK

Use the OpenAI-compatible provider.

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

Generate text

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

Stream

import { streamText } from 'ai'
import { hyperflow } from './lib/hyperflow'
const result = streamText({
model: hyperflow('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 { hyperflow } from './lib/hyperflow'
const { text } = await generateText({
model: hyperflow('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 { hyperflow } from './lib/hyperflow'
const { embeddings } = await embedMany({
model: hyperflow.embeddingModel('cohere/cohere-embed-v4'),
values: ['Hello!', 'How are you?'],
})