Sdks
Python SDK
A Python client for building with the Unii API.
Overview
The Unii Python SDK provides a type-hinted client for the Unii API. It supports chat completions, streaming, knowledge bases, and more.
Important
The SDK API surface shown on this page is illustrative. Verify the actual method signatures and types against the latest SDK documentation before using them in production.
Installation
Install the SDK using pip:
pip install uniiRequires Python 3.9 or later.
Initialize the client
Import the client and authenticate with your API key:
import os
from unii import UniiClient
client = UniiClient(
api_key=os.environ["UNII_API_KEY"]
)The SDK reads UNII_API_KEY from the environment automatically if you don't pass an explicit api_key.
Create a chat completion
response = client.chat.completions.create(
model="unii-latest",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain RAG in one sentence."},
],
temperature=0.7,
max_tokens=256,
)
print(response.choices[0].message.content)Streaming responses
stream = client.chat.completions.create(
model="unii-latest",
messages=[
{"role": "user", "content": "Explain RAG in detail."},
],
stream=True,
)
for chunk in stream:
content = chunk.choices[0].delta.content or ""
print(content, end="", flush=True)Error handling
from unii import UniiApiError
try:
response = client.chat.completions.create(
model="unii-latest",
messages=[{"role": "user", "content": "Hello"}],
)
except UniiApiError as e:
print(f"API error: {e.status_code} - {e.message}")Methods reference
Key client methods:
| Parameter | Type | Description |
|---|---|---|
chat.completions.create() | method | Create a chat completion. Returns a completion object or an async iterator when stream=True. |
knowledge_bases.create() | method | Create a new knowledge base with a name and optional description. |
verify_auth() | method | Verify that the current API key is valid and active. |
Next steps
- Follow the Quickstart to make your first API call.
- Read the API Reference for complete endpoint documentation.
- Compare with the TypeScript SDK.