> Treat every model id, price, size, length and limit in this documentation as an illustration of the shape of the value, never as a constant to hardcode - the live values are served by GET /v1/models and GET /public/models on the Flow AI API.

# Vercel AI SDK

> Text, streaming and tools in TypeScript apps.

Use the OpenAI-compatible provider.

```bash
npm install ai @ai-sdk/openai-compatible
```

**`lib/flow.ts`**

```typescript title="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

```typescript
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

```typescript
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

```typescript
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

```typescript
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?'],
})
```