Python SDK

Integrate Alephant into your Python applications
View as Markdown

The official Alephant Python SDK provides access to the Alephant SaaS API from Python applications. It supports both synchronous and asynchronous usage and is fully type-hinted.

Installation

Install the SDK via pip:

$pip install alephantai-saas-api

Initialization

You can initialize either a synchronous or asynchronous client depending on your application architecture.

Synchronous Client

1import os
2from alephantai_saas import AlephantAi318537Api
3
4client = AlephantAi318537Api(
5 base_url=os.environ["ALEPHANT_SAAS_BASE_URL"],
6 api_key=f"Bearer {os.environ['ALEPHANT_API_TOKEN']}",
7)

Asynchronous Client

For modern async frameworks like FastAPI or Starlette:

1import os
2from alephantai_saas import AsyncAlephantAi318537Api
3
4async_client = AsyncAlephantAi318537Api(
5 base_url=os.environ["ALEPHANT_SAAS_BASE_URL"],
6 api_key=f"Bearer {os.environ['ALEPHANT_API_TOKEN']}",
7)

Example Usage

Smoke test

Use the health endpoint to verify that the SDK can reach your configured SaaS API host.

1response = client.system.health_check()
2print(response)

Listing Workspaces

1def fetch_workspaces():
2 try:
3 response = client.workspaces.list_users_workspaces()
4 for workspace in response.data:
5 print(f"Workspace: {workspace.name} (ID: {workspace.id})")
6 except Exception as e:
7 print(f"Error fetching workspaces: {e}")

Fetching Agent Analytics

1async def get_agent_metrics(agent_id: str):
2 analytics = await async_client.analytics.get_agent_analytics(
3 agent_id=agent_id,
4 period="7d"
5 )
6 print(f"Total Cost: ${analytics.total_cost}")
7 print(f"Total Requests: {analytics.total_requests}")

Base URL

The SaaS SDK requires an explicit base_url. Use the dev, production, or private deployment host for your environment.

1client = AlephantAi318537Api(
2 base_url="https://alephant.your-company.com/api",
3 api_key="Bearer <token>",
4)