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

Vercel AI SDK

Use FreeModel models in TypeScript apps with the AI SDK's OpenAI-compatible provider.

⏱ 5 min read

Overview

The AI SDK (package ai) is a TypeScript toolkit for calling models from Node.js, Next.js and other frameworks. Its @ai-sdk/openai-compatible provider talks to any OpenAI-format endpoint, so you create one FreeModel provider and use it with generateText, streamText and tools. The same package is what OpenCode uses under the hood.

Prerequisites

npm install ai @ai-sdk/openai-compatible zod
  • A FreeModel key from Dashboard → API Keys, set as FREEMODEL_API_KEY in your server environment (for example .env.local in Next.js).
  • Free accounts: free models only, such as gpt-6-luna. Claude Haiku 5.5 and GPT-6.2 Astra are on the free plan; the other Claude models and premium models need a paid plan.

Keep the key on the server. Do not call FreeModel from browser code with your key in it; anyone could read it.

Create the provider

// lib/freemodel.ts
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";

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

freemodel("model-id") now returns a chat model that sends requests to https://freemodel.in/v1/chat/completions.

Generate text (test)

import { generateText } from "ai";
import { freemodel } from "./lib/freemodel";

const { text, usage } = await generateText({
  model: freemodel("gpt-6-luna"),
  prompt: "Reply with the word ok.",
});

console.log(text);
console.log(usage);

Run it with your usual TypeScript runner. Printing ok and a usage object means the key, URL and model id are right.

Stream text

import { streamText } from "ai";
import { freemodel } from "./lib/freemodel";

const result = streamText({
  model: freemodel("gpt-6-luna"),
  prompt: "Explain what an API gateway does in three sentences.",
});

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

Next.js route handler

// app/api/chat/route.ts
import { streamText } from "ai";
import { freemodel } from "@/lib/freemodel";

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

If you use the SDK's React chat hooks, return the response type your AI SDK version documents for them instead of a plain text stream.

Tools

import { generateText, tool } from "ai";
import { z } from "zod";
import { freemodel } from "./lib/freemodel";

const { toolCalls, toolResults } = await generateText({
  model: freemodel("gpt-6-luna"),
  prompt: "What is the weather in Pune?",
  tools: {
    getWeather: tool({
      description: "Return the current weather for a city",
      inputSchema: z.object({ city: z.string() }),
      execute: async ({ city }) => ({ city, forecast: "sunny" }),
    }),
  },
});

console.log(toolCalls, toolResults);

The tool schema option is called inputSchema in current AI SDK versions and parameters in older ones; use the name your installed version expects. The model must have the Tools capability.

Claude via the Anthropic provider (paid plan)

Claude models also work through the provider above. To use the SDK's Anthropic provider instead, install @ai-sdk/anthropic and set its base URL to FreeModel. This provider expects the base URL to include /v1:

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

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

// model: anthropic("claude-sonnet-5")

On a free account this returns 403 upgrade_required.

Which model ids to use

AccountIds
Freegpt-6-luna; other free models: GPT-6.2 Astra, GPT-6 Luna, Grok 4.6, Grok 4.7, Claude Haiku 5.5, GLM-5.3 Flash, Qwen 3.8 Omni Flash and DeepSeek V4.1 Flash 1017.
PaidAny id on Models, e.g. claude-sonnet-5 (3×), gpt-6-astra (1.75×).

Use exact ids; unlisted names such as gpt-4o are not mapped to another model. The usage field reports the model's own token counts; your plan is charged those at the model's multiplier.

Common errors and fixes

Failed calls throw an APICallError with statusCode and responseBody, so you can read FreeModel's error message.

StatusWhat it meansFix
401Key missing on the server.Check FREEMODEL_API_KEY is set where the code runs, not only locally.
403 upgrade_requiredFree account, paid model.Use a free id, or buy a plan.
404 model_not_foundModel id not listed.Copy it from Models.
402Tokens used up (tokens_exhausted).Renew or upgrade. Refused requests are not charged.
429Plan requests-per-minute limit.The SDK retries a couple of times (maxRetries); add your own back-off for bursts.
Was this page helpful?
Still stuck?
Open a support ticket from your dashboard or message our support bot on Telegram.
Telegram supportGet help