OpenAI Python SDK

Prerequisites

Installation

terminal
bash
pip install openai

Basic Usage

example.py
python
from openai import OpenAI

client = OpenAI(
    base_url="https://api.chuizi.ai/v1",
    api_key="ck-your-key-here",
)

response = client.chat.completions.create(
    model="anthropic/claude-sonnet-4-6",
    messages=[
        {"role": "user", "content": "Hello!"}
    ],
)

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

Streaming

example.py
python
stream = client.chat.completions.create(
    model="anthropic/claude-sonnet-4-6",
    messages=[
        {"role": "user", "content": "Write a quicksort in Python"}
    ],
    stream=True,
)

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

Using Different Models

The power of Chuizi.AI is accessing all models with a single SDK:

example.py
python
# Claude
response = client.chat.completions.create(
    model="anthropic/claude-sonnet-4-6",
    messages=[{"role": "user", "content": "Hello"}],
)

# GPT
response = client.chat.completions.create(
    model="openai/gpt-4.1",
    messages=[{"role": "user", "content": "Hello"}],
)

# DeepSeek
response = client.chat.completions.create(
    model="deepseek/deepseek-chat",
    messages=[{"role": "user", "content": "Hello"}],
)

Configuration via Environment Variables

You can also configure via environment variables without modifying code:

terminal
bash
export OPENAI_BASE_URL=https://api.chuizi.ai/v1
export OPENAI_API_KEY=ck-your-key-here

Then in your Python code, the client reads these automatically:

example.py
python
# Automatically reads environment variables
client = OpenAI()

Verify the Configuration

Run any of the code examples above. If you receive a successful response, the configuration is correct. You can also check request logs in the Chuizi.AI dashboard.

Common Issues

Invalid Model Name

Use the provider/model format, such as anthropic/claude-sonnet-4-6. See the full list on the models page.

Connection Timeout

Check that base_url is correctly set to https://api.chuizi.ai/v1. Make sure there is no trailing slash in the URL.

Compatibility with Existing Code

If your project previously used the OpenAI API directly, you only need to change the base_url and api_key parameters. All other code remains unchanged.

Next Steps