OhMyGPT
SDK Integrations

Vercel AI SDK

Use every OhMyGPT model from the Vercel AI SDK with the OpenAI provider you already know.

The AI SDK works with OhMyGPT through its standard OpenAI provider. Give createOpenAI the OhMyGPT base URL and key, and generateText, streamText and tool calling run on Claude, GPT, GLM and every other chat model in the catalog. The examples use ai 7 and @ai-sdk/openai 4.

Install

npm install ai @ai-sdk/openai zod

Create the provider

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

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

Pass any model ID from GET /v1/models to ohmygpt(...). Requests go to OhMyGPT's Responses endpoint, which every chat model accepts.

Generate text

Start with the free test model ohmygpt/mock, then change the ID:

import { generateText } from 'ai';
import { ohmygpt } from './ohmygpt';

const { text, usage } = await generateText({
  model: ohmygpt('ohmygpt/mock'),
  prompt: 'Write a haiku about the sea.',
});
console.log(text);
console.log(usage.inputTokens, usage.outputTokens);
This is a mock reply from OhMyGPT. Your integration works; switch to a real model when ready.
21 17

With zhipu/glm-5.3-flash:

Waves crash on the shore—
salt spray kisses the warm sand,
the tide pulls me home.
20 383

The output count includes the model's reasoning tokens.

Stream

import { streamText } from 'ai';
import { ohmygpt } from './ohmygpt';

const result = streamText({
  model: ohmygpt('zhipu/glm-5.3-flash'),
  prompt: 'Write a haiku about the sea.',
});
for await (const chunk of result.textStream) {
  process.stdout.write(chunk);
}

Call tools

execute runs the tool, and stopWhen lets the SDK send the result back for a final answer:

import { generateText, isStepCount, tool } from 'ai';
import { z } from 'zod';
import { ohmygpt } from './ohmygpt';

const { text } = await generateText({
  model: ohmygpt('zhipu/glm-5.3-flash'),
  tools: {
    getWeather: tool({
      description: 'Get the current weather for a city',
      inputSchema: z.object({ city: z.string() }),
      execute: async ({ city }) => ({ city, temperatureC: 18, condition: 'cloudy' }),
    }),
  },
  stopWhen: isStepCount(3),
  prompt: 'What is the weather in Paris?',
});
console.log(text);
The current weather in Paris is **cloudy** with a temperature of **18°C** (about 64°F). It's a mild day, so you might want a light jacket if you're heading out!

On ohmygpt/mock, the same program calls getWeather with city: "" and then prints the mock reply, so the whole loop runs at no cost. Tool Calling shows the request and response shapes.

Choose providers

To send OhMyGPT's provider object, for example to prefer the lowest price, use @ai-sdk/openai-compatible. It copies providerOptions.ohmygpt into the request body:

npm install @ai-sdk/openai-compatible
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
import { generateText } from 'ai';

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

const { text } = await generateText({
  model: ohmygpt('zhipu/glm-5.3-flash'),
  prompt: 'Say hi.',
  providerOptions: {
    ohmygpt: { provider: { sort: 'price' } },
  },
});

Provider Routing lists the fields.

Anthropic provider

If your code uses @ai-sdk/anthropic, point it at OhMyGPT the same way. Its baseURL includes /v1:

import { createAnthropic } from '@ai-sdk/anthropic';
import { generateText } from 'ai';

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

const { text } = await generateText({
  model: anthropic('anthropic/claude-haiku-4-5'),
  prompt: 'Say hi.',
});

On this page