Assistant UI Sync Server API
A Python client library for interacting with Assistant UI sync server backends, providing the same API structure as the JavaScript/TypeScript useChatRuntime.
Installation
pip install assistant-ui-sync-server-api
Or using uv:
uv add assistant-ui-sync-server-api
Usage
Basic Example
import asyncio
from assistant_ui import AssistantClient
# Create a client
client = AssistantClient(base_url="https://api.example.com")
# Create messages
messages = [
{
"role": "user",
"content": [{"type": "text", "text": "Hello, how are you?"}]
}
]
# Send a chat request to a specific thread
async def main():
thread = client.threads("thread-123")
response = await thread.chat(
messages=messages,
system="You are a helpful assistant."
)
print(response.json())
await client.close()
asyncio.run(main())
Using Context Managers
# Async context manager
async with AssistantClient(base_url="https://api.example.com") as client:
thread = client.threads("thread-123")
response = await thread.chat(messages=messages)
# Sync context manager
with AssistantClient(base_url="https://api.example.com") as client:
thread = client.threads("thread-123")
response = thread.chat_sync(messages=messages)
Authentication
# Static headers
client = AssistantClient(
base_url="https://api.example.com",
headers={"Authorization": "Bearer your-token"}
)
# Dynamic headers (async)
async def get_auth_headers():
token = await fetch_token()
return {"Authorization": f"Bearer {token}"}
client = AssistantClient(
base_url="https://api.example.com",
headers=get_auth_headers
)
Using Tools
tools = {
"get_weather": {
"description": "Get the current weather for a location",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string"},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
},
"required": ["location"]
}
}
}
thread = client.threads("thread-123")
response = await thread.chat(
messages=messages,
tools=tools
)
Canceling Operations
thread = client.threads("thread-123")
# Start a long-running chat
chat_task = asyncio.create_task(thread.chat(messages=messages))
# Cancel it
await thread.cancel()
chat_task.cancel()
Message Types
The package supports various message types matching the Assistant UI format:
from assistant_ui.types import Message
# Text message
text_message: Message = {
"role": "user",
"content": [{"type": "text", "text": "Hello!"}]
}
# Image message
image_message: Message = {
"role": "user",
"content": [
{"type": "text", "text": "What's in this image?"},
{"type": "image", "image": "https://example.com/image.jpg"}
]
}
# File message
file_message: Message = {
"role": "user",
"content": [
{"type": "file", "data": "https://example.com/file.pdf", "mimeType": "application/pdf"}
]
}
# Assistant message with tool calls
assistant_message: Message = {
"role": "assistant",
"content": [
{"type": "text", "text": "I'll help you with that."},
{
"type": "tool-call",
"toolCallId": "call-123",
"toolName": "get_weather",
"args": {"location": "San Francisco"}
}
]
}
# Tool result message
tool_message: Message = {
"role": "tool",
"content": [
{
"type": "tool-result",
"toolCallId": "call-123",
"toolName": "get_weather",
"result": {"temperature": 72, "condition": "sunny"},
"isError": False
}
]
}
API Reference
AssistantClient
Main client for interacting with Assistant UI backends.
Constructor:
AssistantClient(
base_url: str,
headers: Optional[Dict[str, str] | Callable] = None,
timeout: Optional[float] = None,
**kwargs
)
Methods:
threads(thread_id: str) -> ThreadClient: Get a ThreadClient for a specific threadclose(): Close the async clientclose_sync(): Close the sync client
ThreadClient
Client for interacting with a specific thread.
Methods:
chat(messages, system=None, tools=None, **kwargs): Send an async chat requestchat_sync(messages, system=None, tools=None, **kwargs): Send a sync chat requestcancel(): Cancel the current async operationcancel_sync(): Cancel the current sync operation
Type Definitions
The package includes TypedDict definitions for all message types and configuration options, providing full type hints for better IDE support and type checking.
Development
This package is part of the Assistant UI monorepo. To contribute:
- Clone the main repository
- Navigate to
python/assistant-ui - Install dependencies with
uv sync - Run tests with
uv run pytest
Metadata
Release files for assistant-ui-sync-server-api 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| assistant_ui_sync_server_api-0.1.1.tar.gz | 10.6 kB | Without provenance | Details for assistant_ui_sync_server_api-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| assistant_ui_sync_server_api-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for assistant_ui_sync_server_api-0.1.1-py3-none-any.whl |
Total release size: 18.5 kB
Release files / assistant_ui_sync_server_api-0.1.1.tar.gz
| Download URL | assistant_ui_sync_server_api-0.1.1.tar.gz |
|---|---|
| Size | 10.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
329862f9b0178e5dabb823e21708fcbd80ef130b23c93d8ae66b9b5c6a3cd75a
|
|
BLAKE2b-256 checksum How to use checksums |
3dfdfde82831714ad4df22560118f04e450cc3942c1b9d8d930f37a912f12ac4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.20
|
Release files / assistant_ui_sync_server_api-0.1.1-py3-none-any.whl
| Download URL | assistant_ui_sync_server_api-0.1.1-py3-none-any.whl |
|---|---|
| Size | 7.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ecef5f6c136f494659bd48e1f85318d19cf084e80635d114e38da23b76a07045
|
|
BLAKE2b-256 checksum How to use checksums |
92c1581ff5859ee54869e9d1d240619c2e4b2fb22077baae5de0a95992cdd6d7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.20
|
Security for assistant-ui-sync-server-api 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.