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

OpenAI SDKs (Python + Node)

The generic way in: the official OpenAI clients, pointed at FreeModel.

⏱ 5 min read

Overview

FreeModel's OpenAI-format API lives at https://freemodel.in/v1. The official openai packages for Python and Node.js only need a different base URL and a FreeModel key; method names, request fields and response objects stay the same. Most other libraries and tools on this list build on these clients, so if something works here, it works there.

Endpoints you can call through the SDKs: /v1/chat/completions, /v1/responses, /v1/models, /v1/images/generations and /v1/images/edits. Images are paid per image from the account balance; see Image Generation.

Prerequisites

pip install openai        # Python
npm install openai        # Node.js
  • A FreeModel key from Dashboard → API Keys.
  • Free accounts: the free models only, for example gpt-6-luna. Claude Haiku 5.5 and GPT-6.2 Astra are on the free plan; the other Claude models, GPT-6 Astra, Gemini and the other premium models need a paid plan.

Configuration

Both SDKs read two environment variables, so existing code often needs no change at all:

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

Or pass the values explicitly:

# Python
from openai import OpenAI

client = OpenAI(
    api_key="fm_your_key_here",
    base_url="https://freemodel.in/v1",
)
// Node.js
import OpenAI from "openai";

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

The base URL ends in /v1, never in /v1/chat/completions. The SDKs send the key as Authorization: Bearer ….

Test the connection

List models, then send one chat request:

for m in client.models.list():
    print(m.id)

r = client.chat.completions.create(
    model="gpt-6-luna",
    messages=[{"role": "user", "content": "Reply with the word ok."}],
)
print(r.choices[0].message.content, r.usage)
const models = await client.models.list();
for (const m of models.data) console.log(m.id);

const r = await client.chat.completions.create({
  model: "gpt-6-luna",
  messages: [{ role: "user", content: "Reply with the word ok." }],
});
console.log(r.choices[0].message.content, r.usage);

Streaming

stream = client.chat.completions.create(
    model="gpt-6-luna",
    messages=[{"role": "user", "content": "Write a haiku about servers."}],
    stream=True,
)
for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)
const stream = await client.chat.completions.create({
  model: "gpt-6-luna",
  messages: [{ role: "user", content: "Write a haiku about servers." }],
  stream: true,
});
for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}

More on the event format in Streaming.

Responses API

Newer OpenAI code often uses client.responses.create. FreeModel serves /v1/responses as well:

resp = client.responses.create(
    model="gpt-6-luna",
    input="Reply with the word ok.",
)
print(resp.output_text)
const resp = await client.responses.create({
  model: "gpt-6-luna",
  input: "Reply with the word ok.",
});
console.log(resp.output_text);

Which model ids to use

AccountIds
Freegpt-6-luna; all 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. On the free plan they use tokens at 1×.
PaidAny of the 40 chat models on Models, e.g. claude-opus-5-5 (3×), gpt-6-astra (1.75×), claude-haiku-5.5 (1.5×).

Claude models work through this OpenAI-format client too. Ids are matched with dots or dashes (claude-opus-4.8 = claude-opus-4-8), but names FreeModel does not list, such as gpt-4o or claude-3-5-sonnet, return 404 rather than being mapped to another model.

Error handling

Errors come back in the OpenAI shape, {"error": {"message", "type", "code"}}, and the SDKs raise typed exceptions:

StatusPython exceptionMeaning and fix
401AuthenticationErrorBad, missing or revoked key. Check the key and that the base URL points to FreeModel.
402APIStatusErrorTokens used up (tokens_exhausted). Renew or upgrade; nothing is charged for the refused request.
403PermissionDeniedErrorupgrade_required: a free account asked for a paid model. Use a free model or buy a plan.
404NotFoundErrormodel_not_found: the id is not listed. Check client.models.list().
429RateLimitErrorPlan requests-per-minute limit. The SDK retries automatically a few times; add back-off for bursts.
503InternalServerErrorModel temporarily unavailable. Retry later or switch model.
import openai

try:
    client.chat.completions.create(
        model="claude-opus-5-5",
        messages=[{"role": "user", "content": "Hi"}],
    )
except openai.APIStatusError as e:
    print(e.status_code, e.message)

In Node the classes have the same names on the OpenAI export (for example OpenAI.APIError), with the HTTP status in err.status.

Anthropic SDK

If your code uses Anthropic's SDK instead, set its base URL to https://freemodel.in (without /v1) and pass your FreeModel key as the API key. It calls /v1/messages. Claude models other than Claude Haiku 5.5 need a paid plan. See Claude Code for the same endpoint used by an agent.

Was this page helpful?
Still stuck?
Open a support ticket from your dashboard or message our support bot on Telegram.
Telegram supportGet help