Skip to contentSkip to content

Migrate from the OpenAI SDK

Keep the OpenAI-compatible request shape, point the SDK base URL to the AI Credits data API, and read the key from the environment. Select models from /v1/models; do not assume that a particular model is always available.

python
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["API_KEY"],
    base_url=os.environ["API_BASE_URL"].rstrip("/") + "/v1",
)
response = client.chat.completions.create(
    model=os.environ["MODEL"],
    messages=[{"role": "user", "content": "Reply briefly."}],
)

Review streaming, retry, and rate-limit behavior as part of the migration. Never attach prompts, responses, or keys to error reports.