Skip to main content
This guide sends a chat completion through the OpenAI-compatible API.

Before you begin

Create an API key in the FreeModel Console under API Keys. Add prepaid balance under Billing before sending requests.

Send a chat completion

Set your key in the current shell, then run the request.
export FREEMODEL_API_KEY="sk-xxxx"

curl https://api.freemodel.app/v1/chat/completions \
  -H "Authorization: Bearer $FREEMODEL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.4-mini",
    "messages": [
      {
        "role": "user",
        "content": "Write a one-sentence welcome to FreeModel."
      }
    ]
  }'
The response contains the generated text at choices[0].message.content.

Use an OpenAI SDK

FreeModel works with the official OpenAI SDKs. Set base_url to the FreeModel API base URL.
from openai import OpenAI

client = OpenAI(
    api_key="sk-xxxx",
    base_url="https://api.freemodel.app/v1",
)

completion = client.chat.completions.create(
    model="gpt-5.4-mini",
    messages=[
        {"role": "user", "content": "Write a one-sentence welcome to FreeModel."}
    ],
)

print(completion.choices[0].message.content)
const OpenAI = require("openai");

async function main() {
  const client = new OpenAI({
    apiKey: "sk-xxxx",
    baseURL: "https://api.freemodel.app/v1",
  });

  const completion = await client.chat.completions.create({
    model: "gpt-5.4-mini",
    messages: [
      { role: "user", content: "Write a one-sentence welcome to FreeModel." },
    ],
  });

  console.log(completion.choices[0].message.content);
}

main();
Install the matching SDK before running the example:
pip install openai
npm install openai

Stream the response

Set stream to true to receive server-sent events as text is generated.
curl -N https://api.freemodel.app/v1/chat/completions \
  -H "Authorization: Bearer sk-xxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.4-mini",
    "stream": true,
    "messages": [
      {
        "role": "user",
        "content": "Count from one to three."
      }
    ]
  }'
See Chat completions for the streaming event format.

Generate media

Keep your first integration chat-first. When you need generated media, use Images to create and decode a synchronous image response, or use Video generation to submit, poll, and download an asynchronous video.