> ## Documentation Index
> Fetch the complete documentation index at: https://docs.freemodel.app/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenAI Python SDK

> Use FreeModel with the official OpenAI Python SDK.

Install the official SDK.

```bash theme={null}
pip install openai
```

Set `base_url` to the FreeModel OpenAI-compatible endpoint.

```python theme={null}
from openai import OpenAI

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

response = client.chat.completions.create(
    model="gpt-5.4-mini",
    messages=[
        {"role": "user", "content": "Give me one API reliability tip."}
    ],
)

print(response.choices[0].message.content)
```

To stream, pass `stream=True` and iterate over the returned events.

```python theme={null}
from openai import OpenAI

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

stream = client.chat.completions.create(
    model="gpt-5.4-mini",
    messages=[{"role": "user", "content": "Say hello in three words."}],
    stream=True,
)

for event in stream:
    content = event.choices[0].delta.content
    if content:
        print(content, end="")
```

See [Chat completions](/api-reference/chat-completions) for request options.
