API
Python example
Use the OpenAI Python SDK with the MaxLabs API.
Install and configure
pip install openai
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["MAXLABS_API_KEY"],
base_url=os.getenv("MAXLABS_BASE_URL", "https://api.maxlabs.ai/v1"),
)
response = client.chat.completions.create(
model="worker",
messages=[
{"role": "user", "content": "Return a three-step deployment checklist."}
],
max_tokens=500,
)
print(response.choices[0].message.content)
Stream output
stream = client.chat.completions.create(
model="worker",
messages=[{"role": "user", "content": "Explain the change."}],
stream=True,
stream_options={"include_usage": True},
extra_headers={
"X-Session-Id": "8aa82bbe-d489-49fc-b03d-f2d36e72ee50",
"Idempotency-Key": "2319592a-0d45-47ef-b2f2-186a0d2138f6",
},
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
Catch SDK status exceptions, inspect the HTTP status and error body, and apply the documented retry policy. Generate fresh UUIDs in production instead of copying the sample values.
