Skip to content
Last updated

Official Python SDK for Aitronos. Build AI-powered applications with type safety, async support, and automatic retries.

Installation

pip install aitronos-sdk

Requirements:

  • Python 3.8+
  • httpx (automatically installed)

Import:

from aitronos import Aitronos          # Sync client
from aitronos import AsyncAitronos     # Async client

Quick Start

Synchronous Client

from aitronos import Aitronos

# API key authentication
client = Aitronos(api_key="your-api-key")

# Create a response
response = client.responses.create(
    organization_id="org_...",
    inputs=[{"role": "user", "content": [{"type": "input_text", "text": "Hello!"}]}],
)

print(response)

Asynchronous Client

import asyncio
from aitronos import AsyncAitronos

async def main():
    async with AsyncAitronos(api_key="your-api-key") as client:
        response = await client.responses.create(
            organization_id="org_...",
            inputs=[{"role": "user", "content": [{"type": "input_text", "text": "Hello!"}]}],
        )
        print(response)

asyncio.run(main())

Authentication

The SDK supports two authentication methods.

API Key Authentication

from aitronos import Aitronos

client = Aitronos(api_key="your-api-key")

The API key is sent via the x-api-key header.

Bearer Token Authentication

from aitronos import Aitronos

# Pass api_key="" to skip API key validation
client = Aitronos(api_key="", token="your-bearer-token")

The Bearer token is sent via the Authorization: Bearer header. Pass api_key="" so the SDK does not send a non-empty API key header.

Client Configuration

from aitronos import Aitronos

client = Aitronos(
    api_key="your-api-key",                       # Required
    base_url="https://api.aitronos.com",           # Optional (default)
    timeout=60,                                    # Optional (seconds)
)

Parameters:

  • api_key string - Your Aitronos API key
  • token string - Bearer token (alternative to API key)
  • base_url string - API base URL (default: https://api.aitronos.com)
  • timeout int - Request timeout in seconds (default: 60)

Responses API

Generate AI responses using various models.

Create Response

response = client.responses.create(
    organization_id="org_...",
    inputs=[
        {
            "role": "user",
            "content": [{"type": "input_text", "text": "What is the capital of France?"}]
        }
    ],
)

With Thread Context

# Maintain conversation context
response = client.responses.create(
    organization_id="org_...",
    inputs=[{"role": "user", "content": [{"type": "input_text", "text": "Remember my name is Alice"}]}],
    thread_id="thrd_...",
)

# Continue conversation
response = client.responses.create(
    organization_id="org_...",
    inputs=[{"role": "user", "content": [{"type": "input_text", "text": "What's my name?"}]}],
    thread_id="thrd_...",
)

With Assistant

response = client.responses.create(
    organization_id="org_...",
    inputs=[{"role": "user", "content": [{"type": "input_text", "text": "Analyze this data"}]}],
    assistant_id="ast_...",
)

Threads API

Manage conversation threads.

Create Thread

thread = client.threads.create(
    organization_id="org_...",
    assistant_id="ast_...",
)
print(thread.id)

List Threads

threads = client.threads.list_threads(
    organization_id="org_...",
)

Models API

List and retrieve available AI models.

List Models

models = client.models.list_models(
    organization_id="org_...",
)

Retrieve Model

model = client.models.retrieve_model(
    model_id="gpt-4o",
    organization_id="org_...",
)

Files API

Upload and manage files for use with vector stores and assistants.

Upload File

file = client.files.upload(
    organization_id="org_...",
    file="document.pdf",
    purpose="vector_store",
)
print(f"Uploaded: {file.id}")

List Files

files = client.files.list_files(
    organization_id="org_...",
)

Delete File

result = client.files.delete(
    organization_id="org_...",
    file_id="file_...",
)

Vector Stores API

Create and manage vector stores for semantic search and RAG applications.

Create Vector Store

store = client.vector_stores.create(
    organization_id="org_...",
    name="Company Knowledge Base",
    description="Internal documentation and policies",
)
print(f"Created: {store.id}")

List Vector Stores

stores = client.vector_stores.list_vector_stores(
    organization_id="org_...",
)

Search Vector Store

results = client.vector_stores.search(
    organization_id="org_...",
    vector_store_id="vs_...",
    query="What is our vacation policy?",
    limit=5,
)

Images API

Generate images using AI models.

Generate Image

image = client.images.generate(
    organization_id="org_...",
    prompt="A serene mountain landscape at sunset",
    model="dall-e-3",
    size="1024x1024",
    quality="hd",
    n=1,
)

Error Handling

The SDK raises typed exceptions for different error scenarios.

from aitronos import Aitronos
from aitronos.core.api_error import ApiError

client = Aitronos(api_key="your-api-key")

try:
    response = client.responses.create(
        organization_id="org_...",
        inputs=[{"role": "user", "content": [{"type": "input_text", "text": "Hello!"}]}],
    )
except ApiError as e:
    print(f"API error: {e.status_code} - {e.body}")

Async Operations

All methods have async equivalents via AsyncAitronos.

from aitronos import AsyncAitronos
import asyncio

async def main():
    async with AsyncAitronos(api_key="your-api-key") as client:
        # All methods are awaitable
        models = await client.models.list_models(organization_id="org_...")
        threads = await client.threads.list_threads(organization_id="org_...")
        response = await client.responses.create(
            organization_id="org_...",
            inputs=[{"role": "user", "content": [{"type": "input_text", "text": "Hello!"}]}],
        )

asyncio.run(main())

Environment Variables

Store your API key securely using environment variables.

# .env
AITRONOS_API_KEY=your-api-key
import os
from dotenv import load_dotenv
from aitronos import Aitronos

load_dotenv()

client = Aitronos(api_key=os.getenv("AITRONOS_API_KEY"))

Best Practices

1. Use Async for Concurrency

import asyncio
from aitronos import AsyncAitronos

async def process_batch(questions: list[str]):
    async with AsyncAitronos(api_key="...") as client:
        tasks = [
            client.responses.create(
                organization_id="org_...",
                inputs=[{"role": "user", "content": [{"type": "input_text", "text": q}]}],
            )
            for q in questions
        ]
        return await asyncio.gather(*tasks)

2. Reuse Client Instances

# Good - reuse client
client = Aitronos(api_key="...")
for item in items:
    response = client.responses.create(...)

# Bad - creates new connection each time
for item in items:
    client = Aitronos(api_key="...")
    response = client.responses.create(...)

3. Set Appropriate Timeouts

# Longer timeout for complex LLM operations
client = Aitronos(api_key="...", timeout=120)

Support


Built by Aitronos