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:
- Streaming.
stream: trueis passed through. - Tool calling. Tool-call payloads pass through unchanged, in the shape you already send.
- Usage reporting.
usagecomes back on the response. - Error handling. Failures arrive in the OpenAI error shape, so your
existing
except/catchbranches still match.
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
| Id | When |
|---|---|
fm-v1-pro | Code generation, patches, refactors |
fm-v1-standard | Everyday calls where cost and quality balance |
fm-v1-lite | High-volume, low-stakes calls |
auto/image | Image 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
- Step 1: Keep the client you already have. There is no FreeModel SDK to install:
pip install openaiornpm install openaiis the whole dependency list. - Step 2: Change one constructor argument. Python takes
base_url="https://freemodel.online/v1"and Node takesbaseURLwith the same value. Both stop at/v1, because the SDK appends/chat/completionsitself. - 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?
Which failures should my code retry?
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?
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?
Can I find out which model a route picked?
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.
- OpenRouter — credit-purchase fees and free-model rate limits
- OpenRouter — rate-limit reference
- OpenRouter — public model list
- LiteLLM — licence, deployment options and supported models
- Cloudflare AI Gateway — features and pricing
- Vercel AI Gateway — features
- Portkey — plans
- Helicone — plans
- Model Context Protocol — specification
- OpenAI Python SDK — base_url and OPENAI_BASE_URL
- Anthropic Messages API — request format
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.
| Share | Of what | Count |
|---|---|---|
| 77% | are chat models | 153 of 199 listed entries |
| 9% | generate images | 18 of 199 listed entries |
| 23% | are not chat models | 46 of 199 listed entries |
| 3% | are modality routes | 6 of 199 listed entries |
| 17% | carry a context length | 34 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.