Skip to main content

Python

Because Serenity* Star exposes OpenAI-compatible endpoints for its inference models, you can drive them with the official openai Python package. There is no Serenity-specific SDK to install, and once the client is configured everything else (streaming, client tools, input files) works exactly as it does against OpenAI.

For more information about request and response shapes for the inference OpenAI-compatible endpoints, see the REST API reference.

Install

pip install openai

Configure the client

Two things differ from a plain OpenAI setup:

  • base_url must point at the generic inference path .../api/v2/inference (no model in the URL). With it set, the SDK appends /chat/completions and /responses for you, and you choose the model per call through the standard model argument. A single client can therefore reach any configured vendor.
  • A User-Agent header is required by the Serenity* Star API, and the OpenAI SDK does not send one. Set it yourself via default_headers, otherwise the request fails with a 403 Forbidden.

Your Serenity API key goes in api_key; the bearer form is accepted, so it is sent as Authorization: Bearer YOUR_API_KEY.

from openai import OpenAI

client = OpenAI(
base_url="https://api.serenitystar.ai/api/v2/inference",
api_key="YOUR_API_KEY",
default_headers={"User-Agent": "mySerenityClient/1.0"}, # required
)
Legacy per-model base URL

You can still point base_url at a specific model path (for example .../api/v2/inference/qwen/qwen3.6). That form reaches only pre-declared SerenityCloud models and ignores the per-call model argument, so the generic base URL above is preferred. See the REST API reference for both styles.

Selecting the model

With the generic base URL, the model argument you pass on each call chooses the model, just like against OpenAI. Prefix it with a vendor to reach a specific vendor; omit the prefix to default to SerenityCloud:

model="anthropic:claude-sonnet-4-5"   # a specific vendor's model
model="orion/pro-26.2" # shorthand — vendor defaults to SerenityCloud

The model must be active in Serenity* Star for that vendor; there is no need to pre-declare it. Vendor names are case-insensitive, and only the first colon is used to split the value, so a model id that itself contains colons (for example a Bedrock ARN) stays intact.

See the REST API reference for the full rules, error cases, and the legacy per-model form.

Examples

Simple request

response = client.chat.completions.create(
model="orion/pro-26.2",
max_completion_tokens=5000,
messages=[
{"role": "user", "content": "Hello! Tell me a fun fact about Valencia."},
],
)

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

Function calling

Inference supports client tools — standard OpenAI function calling: the model asks for a function, you run it, and you send the result back for the model to finish its answer. (Server tools such as web search or image generation are not available, because there is no agent in front of the model.)

tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather for a given city",
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string", "description": "The city name"},
},
"required": ["city"],
},
},
}
]

messages = [
{"role": "user", "content": "What is the weather like in Paris right now? Use the tool."},
]

# Step 1 — the model requests the tool.
first = client.chat.completions.create(
model="orion/pro-26.2",
max_completion_tokens=512,
messages=messages,
tools=tools,
)

tool_call = first.choices[0].message.tool_calls[0]

# Step 2 — run the function and send the result back.
messages.append(first.choices[0].message)
messages.append(
{
"role": "tool",
"tool_call_id": tool_call.id,
"content": '{"city":"Paris","temperature_c":18,"condition":"light rain","humidity":72}',
}
)

second = client.chat.completions.create(
model="orion/pro-26.2",
max_completion_tokens=512,
messages=messages,
tools=tools,
)

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