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:
| Id | Plan | Multiplier | Notes |
|---|---|---|---|
gpt-6-luna | Free | 1× on the free plan | Tools, JSON mode, vision, reasoning |
gpt-5.4-mini | Paid | 1.25× | Tools, JSON mode, vision |
gpt-6-astra | Paid | 1.75× | Reasoning, 1M context |
claude-sonnet-5 | Paid | 3× | 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
| Feature | On FreeModel |
|---|---|
chat.completions.create | Yes — same request and response shape (docs) |
Streaming (stream: true) | Yes — SSE, usage in the last chunk |
Tool calling, tool_choice, parallel calls | Yes, on models with the tools capability |
response_format json_object / json_schema | Passed 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 envelope | Same {"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
402with 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_tokensfloor. 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/modelslists 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
- Create an
fm_key and set the base URL tohttps://freemodel.in/v1. - Replace every model id with one from
/v1/models. - Run your test suite on
gpt-6-lunawith a free key. - Handle 402 and 403 explicitly.
- Check your peak requests per minute against the plan's limit.
- Move embeddings and any unsupported endpoints only when an equivalent is listed.
- 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.
Grab a free API key — 1M tokens on 8 free models after a one-time Telegram verification, no card. Every model from $1.20.