Back to Documentation

Getting started – Python SDK

Python SDK Reference

Installation

pip install consilium

Client Configuration

from consilium import ConsiliumClient, AsyncConsiliumClient

# Synchronous client
client = ConsiliumClient(
    api_url="http://localhost:4000/api/v1",
    api_key="your-api-key",
    timeout=120,          # seconds
    max_retries=2,
    retry_delay=1.0       # seconds
)

# Asynchronous client
async_client = AsyncConsiliumClient(api_url="...", api_key="...")

# Context manager support
with ConsiliumClient(...) as client:
    result = client.deliberate(...)

Methods


Types (Pydantic)


Full Example

from consilium import ConsiliumClient

client = ConsiliumClient(api_url="http://localhost:4000/api/v1", api_key="your-key")

# Check health
health = client.health_check()
print(f"Status: {health.status}")

# Estimate cost
estimate = client.estimate_cost(
    topic="Should we migrate from REST to GraphQL?",
    mode="council",
    models=["claude-sonnet-4-20250514", "gpt-4o", "gemini-2.0-flash"]
)
print(f"Estimated: ${estimate.estimated_cost:.4f}")

# Run deliberation
result = client.deliberate(
    topic="Should we migrate from REST to GraphQL?",
    mode="council",
    models=["claude-sonnet-4-20250514", "gpt-4o", "gemini-2.0-flash"],
    max_rounds=3
)
print(result.golden_prompt)
print(f"Cost: ${result.cost:.4f}")

# Stream events
for event in client.stream_deliberation(
    topic="Is Kubernetes overkill for our startup?",
    mode="jury",
    models=["claude-sonnet-4-20250514", "gpt-4o", "gemini-2.5-flash"]
):
    if event.event == "agent:chunk":
        print(event.chunk, end="")
    elif event.event == "convergence:detected":
        print("\nConsensus reached!")

Error Handling

  • Exponential backoff: min(BASE × 2^attempt, 30s) between retries
  • Automatic retries: On 5xx and 429 status codes
  • Connection pooling: HTTP connections managed by httpx