A Python client library for the AssistantHub REST API. Provides both synchronous and asynchronous clients with full type annotations.
pip install assistanthub-sdkRequirements: Python 3.10+, httpx, pydantic >= 2.0
from assistanthub_sdk import AssistantHubClient
client = AssistantHubClient(
base_url="http://localhost:8000",
api_key="your-api-key",
)
# List assistants
result = client.list_assistants()
for assistant in result.objects:
print(assistant.name)
# Send a chat message
from assistanthub_sdk import ChatCompletionMessage
response = client.send_message(
assistant_id="ast_123",
messages=[ChatCompletionMessage(role="user", content="Hello!")],
)
print(response.choices[0].message.content)
client.close()with AssistantHubClient(base_url="http://localhost:8000", api_key="key") as client:
assistant = client.get_assistant("ast_123")
print(assistant.name)import asyncio
from assistanthub_sdk import AsyncAssistantHubClient, ChatCompletionMessage
async def main():
async with AsyncAssistantHubClient(
base_url="http://localhost:8000",
api_key="your-api-key",
) as client:
# List assistants
result = await client.list_assistants()
for assistant in result.objects:
print(assistant.name)
# Send a message
response = await client.send_message(
assistant_id="ast_123",
messages=[ChatCompletionMessage(role="user", content="Hello!")],
)
print(response.choices[0].message.content)
asyncio.run(main())Both clients support streaming responses via SSE.
from assistanthub_sdk import AssistantHubClient, ChatCompletionMessage
with AssistantHubClient(base_url="http://localhost:8000", api_key="key") as client:
for chunk in client.send_message_stream(
assistant_id="ast_123",
messages=[ChatCompletionMessage(role="user", content="Tell me a story")],
):
print(chunk, end="", flush=True)async with AsyncAssistantHubClient(base_url="http://localhost:8000", api_key="key") as client:
async for chunk in client.send_message_stream(
assistant_id="ast_123",
messages=[ChatCompletionMessage(role="user", content="Tell me a story")],
):
print(chunk, end="", flush=True)The SDK raises typed exceptions for common HTTP errors:
from assistanthub_sdk import (
AssistantHubClient,
AssistantHubError,
AuthenticationError,
NotFoundError,
ValidationError,
)
client = AssistantHubClient(base_url="http://localhost:8000", api_key="key")
try:
assistant = client.get_assistant("nonexistent")
except NotFoundError as e:
print(f"Not found: {e} (status={e.status_code})")
except AuthenticationError as e:
print(f"Auth failed: {e}")
except ValidationError as e:
print(f"Bad request: {e}")
except AssistantHubError as e:
print(f"API error: {e} (status={e.status_code})")list_assistants()-- List all assistants (paginated)get_assistant(assistant_id)-- Get a single assistantcreate_assistant(assistant)-- Create a new assistantupdate_assistant(assistant_id, assistant)-- Update an assistantdelete_assistant(assistant_id)-- Delete an assistant
send_message(assistant_id, messages, ...)-- Send a chat messagesend_message_stream(assistant_id, messages, ...)-- Stream a chat responsesearch(assistant_id, query, ...)-- RAG search via chatgenerate(assistant_id, messages, ...)-- Generate without RAGgenerate_stream(assistant_id, messages, ...)-- Stream generation without RAG
list_documents(collection_id, ...)-- List documents (paginated)get_document(document_id)-- Get a single documentupload_document(ingestion_rule_id, content, ...)-- Upload a documentdelete_document(document_id)-- Delete a documentbulk_delete_documents(document_ids)-- Delete multiple documents
list_ingestion_rules(...)-- List ingestion rules (paginated)get_ingestion_rule(rule_id)-- Get a single rulecreate_ingestion_rule(rule)-- Create a ruleupdate_ingestion_rule(rule_id, rule)-- Update a ruledelete_ingestion_rule(rule_id)-- Delete a rule
list_collections(...)-- List collections (paginated)get_collection(collection_id)-- Get a single collectioncreate_collection(collection)-- Create a collectionupdate_collection(collection_id, collection)-- Update a collectiondelete_collection(collection_id)-- Delete a collection
list_threads(assistant_id, ...)-- List threadsget_thread(assistant_id, thread_id)-- Get thread historycreate_thread(assistant_id)-- Create a new threaddelete_thread(thread_id)-- Delete a thread
list_embedding_endpoints(...)-- List endpoints (paginated)get_embedding_endpoint(endpoint_id)-- Get a single endpointcreate_embedding_endpoint(endpoint)-- Create an endpointupdate_embedding_endpoint(endpoint_id, endpoint)-- Update an endpointdelete_embedding_endpoint(endpoint_id)-- Delete an endpointcheck_embedding_health()-- Check all endpoint healthcheck_embedding_endpoint_health(endpoint_id)-- Check single endpoint health
list_completion_endpoints(...)-- List endpoints (paginated)get_completion_endpoint(endpoint_id)-- Get a single endpointcreate_completion_endpoint(endpoint)-- Create an endpointupdate_completion_endpoint(endpoint_id, endpoint)-- Update an endpointdelete_completion_endpoint(endpoint_id)-- Delete an endpointcheck_completion_health()-- Check all endpoint healthcheck_completion_endpoint_health(endpoint_id)-- Check single endpoint health
list_models(assistant_id)-- List available modelspull_model(model_name)-- Start pulling a modelget_pull_status()-- Check pull progressdelete_model(model_name)-- Delete a model
list_eval_facts(...)-- List eval facts (paginated)get_eval_fact(fact_id)-- Get a single factcreate_eval_fact(fact)-- Create a factupdate_eval_fact(fact_id, fact)-- Update a factdelete_eval_fact(fact_id)-- Delete a factstart_eval_run(run_request)-- Start an eval runlist_eval_runs(...)-- List eval runs (paginated)get_eval_run(run_id)-- Get a single rundelete_eval_run(run_id)-- Delete a runlist_eval_results(run_id)-- Get run resultsget_eval_result(result_id)-- Get a single resultstream_eval_run(run_id)-- Stream run updates via SSEget_default_judge_prompt()-- Get the default judge prompt
list_crawl_plans(...)-- List crawl plans (paginated)get_crawl_plan(plan_id)-- Get a single plancreate_crawl_plan(plan)-- Create a planupdate_crawl_plan(plan_id, plan)-- Update a plandelete_crawl_plan(plan_id)-- Delete a planstart_crawl(plan_id)-- Start a crawlstop_crawl(plan_id)-- Stop a crawltest_crawl_connectivity(plan_id)-- Test connectivityenumerate_crawl_contents(plan_id)-- Enumerate available contents
list_crawl_operations(plan_id, ...)-- List operations (paginated)get_crawl_operation(plan_id, operation_id)-- Get a single operationdelete_crawl_operation(plan_id, operation_id)-- Delete an operationget_crawl_plan_statistics(plan_id)-- Get plan statisticsget_crawl_operation_statistics(plan_id, operation_id)-- Get operation statistics
get_config()-- Get server configurationupdate_config(config)-- Update server configuration
health_check()-- Check server healthwhoami()-- Get authenticated user info
list_tenants(...)-- List tenants (paginated)get_tenant(tenant_id)-- Get a single tenantcreate_tenant(tenant)-- Create a tenantupdate_tenant(tenant_id, tenant)-- Update a tenantdelete_tenant(tenant_id)-- Delete a tenant
list_users(tenant_id, ...)-- List users (paginated)get_user(tenant_id, user_id)-- Get a single usercreate_user(tenant_id, user)-- Create a userupdate_user(tenant_id, user_id, user)-- Update a userdelete_user(tenant_id, user_id)-- Delete a user
list_credentials(tenant_id, ...)-- List credentials (paginated)get_credential(tenant_id, credential_id)-- Get a single credentialcreate_credential(tenant_id, credential)-- Create a credentialupdate_credential(tenant_id, credential_id, credential)-- Update a credentialdelete_credential(tenant_id, credential_id)-- Delete a credential