Docs · OpenAI SDK

How do I use the OpenAI SDK with FreeModel? One argument changes

最后更新:

FreeModel is an AI model gateway: one key for 200+ models across dozens of providers, routed by task with free capacity tried first. If you already call the OpenAI API from code, you already know every line below. The only difference is where the client points.

Python

from openai import OpenAI

client = OpenAI(
    base_url="https://freemodel.online/v1",
    api_key="sk-your-key",
)

r = client.chat.completions.create(
    model="fm/qwen-plus",
    messages=[{"role": "user", "content": "Hello"}],
)
print(r.choices[0].message.content)

Node

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://freemodel.online/v1",
  apiKey: "sk-your-key",
});

const r = await client.chat.completions.create({
  model: "fm/qwen-plus",
  messages: [{ role: "user", content: "Hello" }],
});
console.log(r.choices[0].message.content);

Note the spelling difference: the Python SDK takes base_url, the Node one takes baseURL. Both stop at /v1.

What still works

Because the shape is unchanged, everything you normally use keeps working:

What changes is which model answers. If you name one, you get it. If you name a route, the router picks per request and a provider failure moves the call on rather than raising.

Ids worth using from code

IdWhen
fm-v1-proCode generation, patches, refactors
fm-v1-standardEveryday calls where cost and quality balance
fm-v1-liteHigh-volume, low-stakes calls
auto/imageImage generation from the same client

An alias is not a guarantee about which model you get — it is a guarantee about what the router optimises for. See Routing for the order of decisions.

Next

Set up in three steps

  1. Step 1: Keep the client you already have. There is no FreeModel SDK to install: pip install openai or npm install openai is the whole dependency list.
  2. Step 2: Change one constructor argument. Python takes base_url="https://freemodel.online/v1" and Node takes baseURL with the same value. Both stop at /v1, because the SDK appends /chat/completions itself.
  3. Step 3: Confirm against the catalogue before you build on it. client.models.list() is an ordinary SDK call and the list endpoint is public, so it still answers when the key is the thing that is wrong.

If you would rather not have the base in source, both SDKs read OPENAI_BASE_URL and OPENAI_API_KEY from the environment, so an otherwise unmodified client already points here once those two are exported.

What the catalogue means for your code

The catalogue is wider than the chat ids alone. The 199 listed models put chat, image, video, speech and embeddings in one list[1], so a client already pointed at /v1 can generate an image or a transcript without a second SDK. Chat itself is reached by naming a concrete id, or one of three subscription tier aliases — fm-v1-lite, fm-v1-standard and fm-v1-pro — each re-resolved per call rather than fixed to a model.

fm-v1-standard is an alias, which is a different kind of promise from a model id. It does not name the model that will answer; it names what the router should optimise for on that request, and it moves the call on when a provider fails. That makes an alias a good default for code that runs unattended, and a poor choice while you are debugging a prompt and need the same model on both sides of a comparison.

Model names are exact strings rather than a menu. When a call comes back with a model-not-found error, the id is absent from the catalogue rather than temporarily down — check it against /v1/models, which lists every id this gateway accepts, modality routes included.

An alias is re-evaluated on every call, so caching a response against an alias name caches it against a decision rather than a model. If you need that cache to be meaningful, pin a concrete id for the calls you intend to cache.

OpenAI SDK FAQ

These come up once the first call returns. Errors keep the OpenAI shape, aliases re-decide per request, and a concrete id behaves exactly as it does against OpenAI — so the move is mostly about where the client points rather than what it sends.

Do I need a FreeModel client library?
No. The official OpenAI SDK is the client: nothing is patched, no import changes, and no wrapper sits in front of it. The gateway speaks the same Chat Completions shape, so the request you were already sending is the request that arrives.
Which failures should my code retry?
Errors arrive in the OpenAI error shape, so existing except and catch branches keep matching. A 429 is usually your own client sending too fast, 402 means the balance is out, and 401 is the key. A provider failing behind a route is not an error you see — the call moves to the next candidate.
Does streaming still work?
Yes. stream: true is passed through and chunks arrive in the usual order. The async clients are constructed the same way, with the same single argument changed.
How do I keep the model stable while I iterate on a prompt?
Name a concrete id instead of a route. A route optimises per request, which is the right default for a job that runs unattended and the wrong one while you are comparing two prompts and need both of them to reach the same model.
Can I find out which model a route picked?
The console keeps a routing log that records which candidate served a call, which is the reliable answer. The response also carries a model field, but the log is the record of what actually ran rather than what was asked for.

Sources

Every third-party figure quoted on this site was read from the vendor documentation linked below, on the date stated. None of these links are affiliate links and none of these vendors paid to be listed. If a number here disagrees with the page it came from, the page is right — tell us and it gets corrected.

Where the percentages come from

Every share quoted on this site is counted from the live model list, not estimated. Divide the two counts in the last column, round to the nearest whole percent, and you get the number in the first.

ShareOf whatCount
77%are chat models153 of 199 listed entries
9%generate images18 of 199 listed entries
23%are not chat models46 of 199 listed entries
3%are modality routes6 of 199 listed entries
17%carry a context length34 of 199 listed entries

[1] Counted on 29 September 2026 from GET https://freemodel.online/v1/models, which needs no key and no account. Every row uses all 199 listed entries as the denominator, because the only thing the endpoint states for every entry is its modality. It no longer publishes per-model capability flags such as tool calling or reasoning, so this site quotes no shares for them. Fetch the list and recount whenever you want to check the arithmetic.