Switching the OpenAI SDK to Modelflare (Python, JavaScript, curl)
Existing OpenAI SDK code works with Modelflare after changing the base URL to https://modelflare.dev/v1 and supplying a Modelflare key.
Modelflare's Chat Completions endpoint is compatible with the official OpenAI SDKs. Switching an application requires two changes: the base URL and the API key. This guide shows both for Python, JavaScript, and curl, and lists the errors you are most likely to see.
Only api_key and base_url change; the request code is unchanged.
Create a key
In the Modelflare console, open API Keys and create a key in a non-default group that lists the model you plan to call. No single group is required.
Set the base URL
Python
from openai import OpenAI
client = OpenAI(
api_key="YOUR_MODELFLARE_API_KEY",
base_url="https://modelflare.dev/v1",
)
response = client.chat.completions.create(
model="gpt-5.6-sol",
messages=[{"role": "user", "content": "Hello"}],
)
print(response.choices[0].message.content)
JavaScript (Node.js)
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "YOUR_MODELFLARE_API_KEY",
baseURL: "https://modelflare.dev/v1",
});
const response = await client.chat.completions.create({
model: "gpt-5.6-sol",
messages: [{ role: "user", content: "Hello" }],
});
console.log(response.choices[0].message.content);
curl
curl https://modelflare.dev/v1/chat/completions \
-H "Authorization: Bearer YOUR_MODELFLARE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.6-sol",
"messages": [
{"role": "user", "content": "Hello"}
]
}'
The examples use gpt-5.6-sol, the model from the Modelflare quickstart. Any model ID available to the key's group can be used instead.
Keep the key out of your code
Do not embed the key in a browser bundle, mobile app, or public repository. Load it from a secret store or the process environment.
Find a model ID
GET /v1/models returns the IDs the current key can call:
curl https://modelflare.dev/v1/models \
-H "Authorization: Bearer YOUR_MODELFLARE_API_KEY"
The response is not a price list. Prices, groups, and protocol labels are on Models & Pricing. Use the exact ID shown there, not a provider marketing name, a date suffix, or a nearby variant.
Common errors
A 401 means the key is missing, malformed, or revoked; recopy it and confirm it has not been deleted or disabled. A 403 means the key is valid but the selected model or group is not allowed. A request with valid JSON that still fails with model_not_found usually means the key's group has no channel for that model; edit the key and choose a group that lists it. Image and video requests sent to the wrong endpoint family return 400 with unsupported_endpoint; image and video models use /v1/images/generations and /v1/videos, as described in the endpoint guide.
Hosts
The default host is https://modelflare.dev/v1. China-facing EdgeOne traffic can use https://origin.modelflare.dev/v1. Choose the host before sending a request, and do not redirect an in-flight POST from one host to the other.
Other endpoints on the same key
The same key works with the Responses API (POST /v1/responses, used by Codex), Anthropic Messages (used by Claude Code), image generation, and asynchronous video. The Modelflare/openai-sdk Space contains this guide in English and Chinese. Modelflare/api-recipes and the Modelflare/api-examples dataset cover the other endpoints, and Modelflare/start links to everything else. For business inquiries, contact business@modelflare.dev. The full reference is at docs.modelflare.dev.