docs
Connection

OpenAI SDK

Markdown

The official OpenAI libraries for Python and Node.js work with Ailoot without changes to your code: only the URL and key change.

Full guide

Installation

pip install openai

Connection

Set the base URL to https://api.ailoot.ai/v1. You can set it in code or through the variables OPENAI_BASE_URL and OPENAI_API_KEY — then your code needs no changes at all.

from openai import OpenAI
import os

client = OpenAI(max_retries=0, 
    base_url="https://api.ailoot.ai/v1",
    api_key=os.environ["AILOOT_API_KEY"],
)

resp = client.chat.completions.create(
    model="claude-sonnet-5-5",
    messages=[{"role": "user", "content": "Explain what an API is in two sentences."}],
)
print(resp.choices[0].message.content)

Responses API

The newer OpenAI format. It is available for models whose catalog entry lists Responses: 53 identifiers, including Claude, GPT, DeepSeek, Qwen, Kimi, and GLM.

resp = client.responses.create(
    model="gpt-6.1-sol",
    instructions="Keep your answers brief and to the point.",
    input="How does TCP differ from UDP?",
)
print(resp.output_text)

Tools (function calling)

tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "Weather in a city",
        "parameters": {
            "type": "object",
            "properties": {"city": {"type": "string"}},
            "required": ["city"],
        },
    },
}]

import json

messages = [{"role": "user", "content": "What is the weather like in Kazan?"}]
# Disable automatic retries: after a timeout, check the Request ID in your usage history first.
client = client.with_options(max_retries=0)
for turn in range(4):
    resp = client.chat.completions.create(
        model="claude-sonnet-5-5", messages=messages, tools=tools,
    )
    message = resp.choices[0].message
    messages.append(message.model_dump(exclude_none=True))
    if not message.tool_calls:
        print(message.content)
        break
    for call in message.tool_calls:
        if call.function.name != "get_weather":
            raise ValueError("Unexpected function")
        arguments = json.loads(call.function.arguments)
        # Replace with your own weather function; this example is explicitly demo data.
        result = {"city": arguments["city"], "temperature_c": 20, "demo": True}
        messages.append({"role": "tool", "tool_call_id": call.id,
                         "content": json.dumps(result, ensure_ascii=False)})
else:
    raise RuntimeError("Tool loop limit reached")

Embeddings

emb = client.embeddings.create(
    model="nvidia/nemotron-3-embed-1b",
    input=["First document", "Second document"],
)
print(len(emb.data), len(emb.data[0].embedding))

Image inputs

resp = client.chat.completions.create(
    model="gpt-6.1-sol",
    messages=[{
        "role": "user",
        "content": [
            {"type": "text", "text": "What is in this picture?"},
            {"type": "image_url", "image_url": {"url": "https://example.com/photo.jpg"}},
        ],
    }],
)

Error handling

Ailoot errors use the OpenAI format, so standard SDK exceptions catch them. The message includes the Request ID.

import openai

try:
    resp = client.chat.completions.create(model="claude-sonnet-5-5", messages=[{"role": "user", "content": "Hello"}])
except openai.APIStatusError as e:
    print(e.status_code, e.response.json()["error"]["code"])
    print(e.response.headers.get("x-request-id"))
Still have questions? Send your Request ID and a description — we'll help you troubleshoot.Contact support
More details

API connection

How do I connect the OpenAI SDK to Ailoot?

Set the base URL to https://api.ailoot.ai/v1. You can set it in code or through the variables OPENAI_BASE_URL and OPENAI_API_KEY — then your code needs no changes at all.