Use the OpenAI SDK with free models through Ficelle
Set one base URL in the OpenAI Python or JavaScript SDK and your scripts call free models with failover. Code for Python, JavaScript, curl and env vars.
Status
Supported. Ficelle serves the OpenAI Chat Completions API, which the official Python and JavaScript SDKs call when you set a base URL. Use chat.completions: Ficelle does not serve the Responses API.
Set up OpenAI SDK
-
Python
Pass the Ficelle base URL and a placeholder key to the client, then call
chat.completionswith a routing profile as the model.python from openai import OpenAI client = OpenAI(base_url="http://127.0.0.1:8646/v1", api_key="ficelle-local") response = client.chat.completions.create( model="ficelle/auto-tools", messages=[{"role": "user", "content": "Say hello from a free model."}], ) print(response.choices[0].message.content) -
JavaScript and TypeScript
Same two settings in the JavaScript SDK:
baseURLandapiKey.javascript import OpenAI from "openai"; const client = new OpenAI({ baseURL: "http://127.0.0.1:8646/v1", apiKey: "ficelle-local", }); const response = await client.chat.completions.create({ model: "ficelle/auto-tools", messages: [{ role: "user", content: "Say hello from a free model." }], }); console.log(response.choices[0].message.content); -
Environment variables
The Python SDK reads
OPENAI_BASE_URLandOPENAI_API_KEYwhen you build a client without arguments, and many other tools read the same names, so they need no code change.shell export OPENAI_BASE_URL="http://127.0.0.1:8646/v1" export OPENAI_API_KEY="ficelle-local"
Check it works
This checks Ficelle's Chat Completions endpoint with ficelle/auto-fast.
A successful response confirms that route works, but does not verify the profile or
protocol OpenAI SDK uses. If the client still fails, check its error and the limits below
as well as its configuration.
curl -s http://127.0.0.1:8646/v1/chat/completions -H 'Content-Type: application/json' -d '{"model":"ficelle/auto-fast","messages":[{"role":"user","content":"Reply exactly: ficelle-ok"}],"temperature":0}'
Limits to know
- Call
client.chat.completions, neverclient.responses: Ficelle does not serve the Responses API, so those calls fail. - When streaming, pass
stream_options: {"include_usage": true}so your tokens are counted on the local dashboard at http://127.0.0.1:8646/admin. Ficelle records usage only when the provider reports it. - Pick the profile for the job:
ficelle/auto-toolsfor tool calls,ficelle/auto-jsonfor structured output,ficelle/auto-fastfor short calls.
Troubleshooting
- On a listener that is not local, set the API key to the token from
ficelle access-token api; it is sent asAuthorization: Bearer. - A 404 on
/v1/responsesmeans the code calls the Responses API. Switch it tochat.completions.
Questions
Can I use the OpenAI SDK with free models?
Yes. Set the SDK's base URL to Ficelle and keep calling chat.completions. Ficelle routes each request to a free model from the providers you configure and moves to another one when it fails.
Does Ficelle support the OpenAI Responses API?
No. Ficelle serves Chat Completions only. Code that calls client.responses fails against Ficelle; use client.chat.completions instead.
What API key do I put in the SDK?
Any non-empty placeholder on the default local listener: Ficelle keeps your real provider keys itself. On a listener that is not local, use the token from ficelle access-token api.
Sources
Official pages and the Ficelle recipe this guide rests on, read on 11 November 2026: