OhMyGPT
SDK Integrations

Vercel AI SDK

Use OhMyGPT with Vercel AI SDK.

The Vercel AI SDK is a TypeScript library for building AI-powered applications. Since OhMyGPT is OpenAI-compatible, you can use the OpenAI provider.

Installation

npm install ai @ai-sdk/openai

Configuration

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

const ohmygpt = createOpenAI({
  baseURL: 'https://api.ohmygpt.com/v1',
  apiKey: process.env.OHMYGPT_API_KEY,
});

Usage

Text generation

import { generateText } from 'ai';

const { text } = await generateText({
  model: ohmygpt('gpt-4o'),
  prompt: 'Write a haiku about coding.',
});

Streaming

import { streamText } from 'ai';

const result = streamText({
  model: ohmygpt('gpt-4o'),
  prompt: 'Write a short story.',
});

for await (const chunk of result.textStream) {
  process.stdout.write(chunk);
}

Tool calling

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

const result = await generateText({
  model: ohmygpt('gpt-4o'),
  tools: {
    weather: tool({
      description: 'Get the weather for a location',
      parameters: z.object({
        location: z.string(),
      }),
      execute: async ({ location }) => {
        return { temperature: 72, condition: 'sunny' };
      },
    }),
  },
  prompt: 'What is the weather in San Francisco?',
});

For more details, see the Vercel AI SDK documentation.

How is this guide?

Last updated on

On this page