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

Migrate from the OpenAI SDK to FreeModel

Move an OpenAI SDK app to FreeModel with a two-line change: base URL and key, choosing model ids, what stays the same, what differs and which errors to handle.

FreeModel speaks the OpenAI API format at https://freemodel.in/v1. If your app already uses the official OpenAI SDK for Python or Node, moving it over is a change of base URL and key — plus picking model ids we actually serve. This guide covers the change, what keeps working, and the few places where behaviour differs.

FreeModel is an independent service; it is not affiliated with OpenAI or any other vendor.

The two-line change

Python

 from openai import OpenAI

-client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
+client = OpenAI(api_key=os.environ["FREEMODEL_API_KEY"],
+                base_url="https://freemodel.in/v1")

 resp = client.chat.completions.create(
-    model="gpt-4o",
+    model="gpt-6-luna",
     messages=[{"role": "user", "content": "Hello"}],
 )

Node

 import OpenAI from "openai";

-const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
+const client = new OpenAI({
+  apiKey: process.env.FREEMODEL_API_KEY,
+  baseURL: "https://freemodel.in/v1",
+});

Create the key at dashboard → API keys; it starts with fm_. The base URL ends at /v1 — do not add /chat/completions, the SDK does that.

Or no code change at all

Both SDKs read their settings from the environment when you do not pass them in code:

export OPENAI_API_KEY=fm_your_key_here
export OPENAI_BASE_URL=https://freemodel.in/v1

This is handy for third-party tools built on the OpenAI SDK. You still need to change the model id wherever it is set.

Choose model ids we serve

This is the step people skip, and the one that breaks. FreeModel only serves the models it lists. Names we do not list, such as gpt-4o, gpt-4o-mini or claude-3-5-sonnet, return 404 model_not_found. They are never mapped to another model. We would rather fail clearly than quietly answer with a model you did not ask for.

Get the list from the API or from the models page:

curl https://freemodel.in/v1/models -H "Authorization: Bearer $OPENAI_API_KEY"

A few ids to start with:

IdPlanMultiplierNotes
gpt-6-lunaFree1× on the free planTools, JSON mode, vision, reasoning
gpt-5.4-miniPaid1.25×Tools, JSON mode, vision
gpt-6-astraPaid1.75×Reasoning, 1M context
claude-sonnet-5Paid3×Works through the same OpenAI SDK

Put the model id in configuration, not in code, so you can switch without a deploy.

What stays the same

FeatureOn FreeModel
chat.completions.createYes — same request and response shape (docs)
Streaming (stream: true)Yes — SSE, usage in the last chunk
Tool calling, tool_choice, parallel callsYes, on models with the tools capability
response_format json_object / json_schemaPassed through to the model
Responses API/v1/responses
Model list/v1/models
Image generation and edits/v1/images/generations, /v1/images/edits — paid per image from the account balance
Error envelopeSame {"error": {"message", "type", "code"}} shape

What differs

  • Plans instead of a pay-per-token bill. You buy a 30-day plan of tokens (Starter $1.20 = 30M up to Ultra $19.99 = 1B). Each model uses plan tokens at its own multiplier; input and output both count. Plans are prepaid and do not auto-renew.
  • Free tokens only on free models. The free 1M tokens work on the 8 free models. Asking for a paid model with a free account returns 403 upgrade_required.
  • 402 when tokens run out. The API answers 402 with a clear message, and nothing is charged on top. Do not retry it.
  • Rate limits per plan. From 30 requests per minute on Free to 1,500 on Ultra, counted across all keys of the account (details).
  • max_tokens floor. Values below 2048 are raised to 2048, and the default is 8192, so reasoning models do not return empty answers.
  • Embeddings. At the time of writing /v1/models lists no embedding model. Keep your current embedding provider for now.
  • Endpoints we do not offer. There are no files, batch, fine-tuning, audio or assistants endpoints. If your app uses them, keep those calls on their current provider.

Errors to handle

Your existing error handling mostly carries over, because the SDK raises the same exception classes. Add explicit cases for the codes that are specific to plans:

import openai

try:
    resp = client.chat.completions.create(model=MODEL, messages=messages)
except openai.NotFoundError:
    raise SystemExit(f"{MODEL} is not served; pick an id from /v1/models")
except openai.PermissionDeniedError as err:       # 403, e.g. upgrade_required
    raise SystemExit(err.body.get("message") if isinstance(err.body, dict) else err)
except openai.APIStatusError as err:
    if err.status_code == 402:                    # tokens used up: do not retry
        raise SystemExit("Plan tokens used up — renew or upgrade the plan")
    raise

429 and 5xx are retried by the SDK itself (twice by default). The full list of codes is in handling 402, 403 and 429 errors.

Migration checklist

  1. Create an fm_ key and set the base URL to https://freemodel.in/v1.
  2. Replace every model id with one from /v1/models.
  3. Run your test suite on gpt-6-luna with a free key.
  4. Handle 402 and 403 explicitly.
  5. Check your peak requests per minute against the plan's limit.
  6. Move embeddings and any unsupported endpoints only when an equivalent is listed.
  7. Watch the first days of usage in the dashboard before switching all traffic.

FAQ

Will gpt-4o work if I keep my old model name?

No. Names we do not list, such as gpt-4o or claude-3-5-sonnet, return 404 model_not_found. They are never mapped to another model. Use an id from GET /v1/models.

Do I need a different SDK?

No. The official OpenAI SDKs for Python and Node work unchanged. Only the base URL, the key and the model ids change.

Can I use Claude models through the OpenAI SDK?

Yes. Claude ids such as claude-sonnet-5 work on /v1/chat/completions with the same code. Claude models other than Claude Haiku 5.5 need a paid plan.

Is FreeModel affiliated with OpenAI?

No. FreeModel is an independent service that speaks the OpenAI API format. It is not affiliated with OpenAI or any other model vendor.

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.