Models → Pricing → Docs → Blog → Changelog → Contact → Status →
Get started freeLog in

Vercel AI SDK with FreeModel: OpenAI and Anthropic

Three AI SDK provider packages can reach FreeModel. A side-by-side comparison, the exact baseURL for each, and working examples for text, streaming, tools and a Next.js route.

The Vercel AI SDK is a TypeScript toolkit for building AI features: generateText, streamText, tools, and helpers for React and Next.js. Models come from provider packages, and three of them can point at FreeModel by changing baseURL.

Three providers compared

@ai-sdk/openai@ai-sdk/openai-compatible@ai-sdk/anthropic
FactorycreateOpenAIcreateOpenAICompatiblecreateAnthropic
FreeModel baseURLhttps://freemodel.in/v1https://freemodel.in/v1https://freemodel.in/v1
Wire formatResponses or Chat CompletionsChat CompletionsAnthropic Messages
FreeModel endpoint/v1/responses or /v1/chat/completions/v1/chat/completions/v1/messages
Good forMost appsGeneric setups, other tools built on itClaude models in Anthropic format

All three work with every model on your plan. The choice is about which wire format you prefer, not which models you get. The free models (for example gpt-6-luna, claude-haiku-5.5 and gpt-6.2-astra) work on a free key; the other Claude models and premium models need a paid plan.

Option 1: createOpenAI

npm install ai @ai-sdk/openai zod
import { createOpenAI } from '@ai-sdk/openai';
import { generateText } from 'ai';

const freemodel = createOpenAI({
  baseURL: 'https://freemodel.in/v1',
  apiKey: process.env.FREEMODEL_API_KEY,
});

const { text } = await generateText({
  model: freemodel.chat('gpt-6-luna'),
  prompt: 'Explain debouncing in two sentences.',
});
console.log(text);

freemodel.chat(id) uses Chat Completions. In recent AI SDK versions, calling freemodel(id) directly uses the Responses API instead. FreeModel serves both, so either works; .chat() is the most widely compatible choice.

Option 2: createOpenAICompatible

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

const freemodel = createOpenAICompatible({
  name: 'freemodel',
  baseURL: 'https://freemodel.in/v1',
  apiKey: process.env.FREEMODEL_API_KEY,
});

// model: freemodel('gpt-6-luna')

This is the same package opencode uses for custom providers (see our opencode guide). It only speaks Chat Completions.

Option 3: createAnthropic

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

const fmClaude = createAnthropic({
  baseURL: 'https://freemodel.in/v1',
  apiKey: process.env.FREEMODEL_API_KEY,
});

const { text } = await generateText({
  model: fmClaude('claude-sonnet-5'), // paid plan needed
  prompt: 'Review this function name: getData2.',
});

One detail: FreeModel's Anthropic base URL is https://freemodel.in for most clients (Claude Code, the Anthropic SDK). The AI SDK's Anthropic provider is different: its baseURL already includes /v1 and it appends /messages. So here it is https://freemodel.in/v1.

FreeModel accepts the key as x-api-key, which is what this provider sends. Claude Sonnet 5 uses plan tokens at 3×.

Streaming

import { streamText } from 'ai';

const result = streamText({
  model: freemodel.chat('gpt-6-luna'),
  prompt: 'List five uses for a Raspberry Pi.',
});

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

Tools

Tool calling needs a model with the Tools capability; every free model has it. This example uses the current AI SDK tool syntax:

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

const { text } = await generateText({
  model: freemodel.chat('gpt-6-luna'),
  tools: {
    weather: tool({
      description: 'Get the weather for a city',
      inputSchema: z.object({ city: z.string() }),
      execute: async ({ city }) => ({ city, forecast: 'sunny, 31 C' }),
    }),
  },
  stopWhen: stepCountIs(3),
  prompt: 'What is the weather in Dhaka?',
});
console.log(text);

Older AI SDK versions call these fields parameters and maxSteps instead of inputSchema and stopWhen. Each step is a separate billed request; input and output tokens both count. The protocol underneath is in the tool calling docs.

A Next.js route handler

// app/api/chat/route.ts
import { createOpenAI } from '@ai-sdk/openai';
import { streamText } from 'ai';

const freemodel = createOpenAI({
  baseURL: 'https://freemodel.in/v1',
  apiKey: process.env.FREEMODEL_API_KEY,
});

export async function POST(req: Request) {
  const { prompt } = await req.json();
  const result = streamText({ model: freemodel.chat('gpt-6-luna'), prompt });
  return result.toTextStreamResponse();
}

Keep FREEMODEL_API_KEY in a server-only environment variable. Never prefix it with NEXT_PUBLIC_, or it is bundled into the browser code.

Keeping costs predictable

Because the model is just a string, it is easy to make it configurable per route: a free model for autocomplete-style helpers, a stronger paid model for the one feature that needs it.

  • Read the usage. generateText returns a usage object with input and output token counts. Log it while you develop so you know what a typical request costs.
  • Mind the multiplier. Each model uses plan tokens at its own rate. One token on a 3× model counts as three plan tokens. The table is on the pricing page.
  • Plans are prepaid. 30 days, from $1.20, no auto-renew. Unused tokens can be refunded at any time; see refunds.

Errors

  • 401: the key is missing in this environment. Check your deployment's variables, not just .env.local.
  • 404 model_not_found: use an exact id from GET /v1/models. Names like gpt-4o are not mapped to another model.
  • 403 upgrade_required: a free key asked for a paid model.
  • 402: tokens used up (tokens_exhausted). The rejected request is not charged.
  • 429: per-key rate limit for your plan. The SDK retries a few times by default.

FAQ

Which provider package should I use?

Any of the three works. createOpenAI is the most common choice, createOpenAICompatible is the generic one, and createAnthropic is for the Anthropic message format with Claude models.

Why is the Anthropic baseURL https://freemodel.in/v1?

The AI SDK Anthropic provider expects a base URL that already includes /v1 and then adds /messages. FreeModel serves the Anthropic format at /v1/messages, so the provider base is https://freemodel.in/v1.

Can I call FreeModel from the browser with the AI SDK?

Keep the key on the server. Call FreeModel from a route handler or server action and stream the result to the browser, so the key is never shipped to users.

Do the free models support tools in the AI SDK?

Yes. All of the free models, including gpt-6-luna, have the Tools capability, so generateText and streamText can call your tools.

Ready to build?

Grab a free API key — 1M tokens on 8 free models after a one-time Telegram verification, no card. Every model from $1.20.