Python SDK
SDKMAX is fully OpenAI-compatible, so you can use the official openai Python package directly — no separate SDKMAX SDK needed.
Install
bash
pip install openaiInitialize the client
python
from openai import OpenAI
client = OpenAI(
api_key="sk-your-key", # created in the SDKMAX console
base_url="https://api.sdkmax.com/v1",
)Prefer environment variables
bash
export OPENAI_API_KEY="sk-your-key"
export OPENAI_BASE_URL="https://api.sdkmax.com/v1"With these set, client = OpenAI() works with no hardcoded secrets.
Chat completions
python
resp = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain SDKMAX's core capabilities."},
],
)
print(resp.choices[0].message.content)Streaming
python
stream = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Write a short poem about an AI gateway."}],
stream=True,
)
for chunk in stream:
delta = chunk.choices[0].delta.content or ""
print(delta, end="", flush=True)Switching models
Just change the model parameter — everything else stays the same:
python
for model in ["gpt-4o", "claude-opus-4-8", "deepseek-chat"]:
resp = client.chat.completions.create(
model=model,
messages=[{"role": "user", "content": "What's 1+1?"}],
)
print(model, "->", resp.choices[0].message.content)Embeddings
python
resp = client.embeddings.create(
model="text-embedding-3-small",
input="SDKMAX is an enterprise AI gateway",
)
print(len(resp.data[0].embedding))Generating images
python
resp = client.images.generate(
model="dall-e-3",
prompt="A cat riding a motorcycle through a cyberpunk city",
size="1024x1024",
)
print(resp.data[0].url)See Images API.
Error handling
The openai library maps SDKMAX's 4xx/5xx responses to the corresponding exception types:
python
from openai import APIStatusError, RateLimitError
try:
client.chat.completions.create(model="gpt-4o", messages=[...])
except RateLimitError:
# 429: quota exhausted or rate-limited — back off and retry
...
except APIStatusError as e:
# any other 4xx/5xx; e.status_code / e.message help with debugging
print(e.status_code, e.message)Full error code reference: Error Codes.
Async usage
python
import asyncio
from openai import AsyncOpenAI
client = AsyncOpenAI(api_key="sk-your-key", base_url="https://api.sdkmax.com/v1")
async def main():
resp = await client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello"}],
)
print(resp.choices[0].message.content)
asyncio.run(main())