SDKs
Python SDK
The official Satryx Python library — sync and async clients with full type hints.
Installation
bash
pip install satryxRequires Python 3.9+ and httpx ≥ 0.25.
Setup
python
from satryx import Satryx
# Reads SATRYX_API_KEY env var automatically
client = Satryx()
# Or pass explicitly
client = Satryx(api_key="satryx_live_…")Tip:Set
SATRYX_API_KEY in your environment so you never hard-code the key.Chat completions
Non-streaming
python
response = client.chat.completions.create(
model="llama-3.1-70b",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Summarize quantum entanglement."},
],
temperature=0.7,
max_tokens=1024,
)
print(response.choices[0].message.content)
print(f"Tokens used: {response.usage.total_tokens}")Streaming
python
with client.chat.completions.create(
model="llama-3.1-70b",
messages=[{"role": "user", "content": "Write a poem about the sea."}],
stream=True,
) as stream:
for chunk in stream:
delta = chunk.choices[0].delta.content
if delta:
print(delta, end="", flush=True)
print() # newline when doneImage generation
python
response = client.images.generate(
prompt="Cyberpunk cityscape at dusk, neon reflections on wet pavement",
model="flux-dev",
n=2,
size="1024x1024",
)
for img in response.data:
print(img.url) # download before URL expires (1 hour)Async client
python
import asyncio
from satryx import AsyncSatryx
async def main():
async with AsyncSatryx() as client:
response = await client.chat.completions.create(
model="llama-3.1-70b",
messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)
# Async streaming
async with client.chat.completions.create(
model="llama-3.1-70b",
messages=[{"role": "user", "content": "Count to 5."}],
stream=True,
) as stream:
async for chunk in stream:
delta = chunk.choices[0].delta.content
if delta:
print(delta, end="", flush=True)
asyncio.run(main())Error handling
python
from satryx import (
Satryx,
AuthenticationError,
RateLimitError,
APIConnectionError,
APIStatusError,
)
client = Satryx()
try:
response = client.chat.completions.create(
model="llama-3.1-70b",
messages=[{"role": "user", "content": "Hello"}],
)
except AuthenticationError:
print("Bad API key")
except RateLimitError as e:
print(f"Rate limited — retry in {e.retry_after_seconds}s")
except APIConnectionError:
print("Network error")
except APIStatusError as e:
print(f"HTTP {e.status_code}: {e.message}")List models
python
models = client.models.list()
for m in models.data:
print(m.id, m.capabilities)Configuration options
| Parameter | Type | Description |
|---|---|---|
| api_key | str | API key. Defaults to SATRYX_API_KEY env var. |
| base_url | str | API base URL. Default: "https://api.satryx.ai". |
| timeout | float | Request timeout in seconds. Default 60. |
| max_retries | int | Automatic retries on 429/5xx. Default 3. |