AI HUB Docs
English
Console →
Guides

OpenAI Python SDK

The official OpenAI Python SDK works unchanged. Point it at the AI HUB base URL and use a Hub key. No AI HUB-specific library is required.

Install

Shell
pip install openai

Configure the client

Set the base URL to the AI HUB endpoint and read the key from an environment variable.

Python
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["AIHUB_API_KEY"],
    base_url="https://console.aimodelhub.ai/v1",
)

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

Streaming

Python
stream = client.chat.completions.create(
    model="anthropic-claude-sonnet-4-6",
    messages=[{"role": "user", "content": "Hello!"}],
    stream=True,
)
for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="")

The model must be a published slug. See the Models list.