Official Python SDK for Aitronos. Build AI-powered applications with type safety, async support, and automatic retries.
pip install aitronos-sdkRequirements:
- Python 3.8+
- httpx (automatically installed)
Import:
from aitronos import Aitronos # Sync client
from aitronos import AsyncAitronos # Async clientfrom 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)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())The SDK supports two authentication methods.
from aitronos import Aitronos
client = Aitronos(api_key="your-api-key")The API key is sent via the x-api-key header.
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.
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_keystring - Your Aitronos API keytokenstring - Bearer token (alternative to API key)base_urlstring - API base URL (default:https://api.aitronos.com)timeoutint - Request timeout in seconds (default:60)
Generate AI responses using various models.
response = client.responses.create(
organization_id="org_...",
inputs=[
{
"role": "user",
"content": [{"type": "input_text", "text": "What is the capital of France?"}]
}
],
)# 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_...",
)response = client.responses.create(
organization_id="org_...",
inputs=[{"role": "user", "content": [{"type": "input_text", "text": "Analyze this data"}]}],
assistant_id="ast_...",
)Manage conversation threads.
thread = client.threads.create(
organization_id="org_...",
assistant_id="ast_...",
)
print(thread.id)threads = client.threads.list_threads(
organization_id="org_...",
)List and retrieve available AI models.
models = client.models.list_models(
organization_id="org_...",
)model = client.models.retrieve_model(
model_id="gpt-4o",
organization_id="org_...",
)Upload and manage files for use with vector stores and assistants.
file = client.files.upload(
organization_id="org_...",
file="document.pdf",
purpose="vector_store",
)
print(f"Uploaded: {file.id}")files = client.files.list_files(
organization_id="org_...",
)result = client.files.delete(
organization_id="org_...",
file_id="file_...",
)Create and manage vector stores for semantic search and RAG applications.
store = client.vector_stores.create(
organization_id="org_...",
name="Company Knowledge Base",
description="Internal documentation and policies",
)
print(f"Created: {store.id}")stores = client.vector_stores.list_vector_stores(
organization_id="org_...",
)results = client.vector_stores.search(
organization_id="org_...",
vector_store_id="vs_...",
query="What is our vacation policy?",
limit=5,
)Generate images using AI models.
image = client.images.generate(
organization_id="org_...",
prompt="A serene mountain landscape at sunset",
model="dall-e-3",
size="1024x1024",
quality="hd",
n=1,
)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}")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())Store your API key securely using environment variables.
# .env
AITRONOS_API_KEY=your-api-keyimport os
from dotenv import load_dotenv
from aitronos import Aitronos
load_dotenv()
client = Aitronos(api_key=os.getenv("AITRONOS_API_KEY"))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)# 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(...)# Longer timeout for complex LLM operations
client = Aitronos(api_key="...", timeout=120)Built by Aitronos