Skip to main content

Python SDK

Official Python SDK for the Truedy API.

Installation

pip install trudy-python-sdk

Quick Start

from trudy import TrudyClient

# Initialize client
client = TrudyClient(api_key="YOUR_API_KEY")

# Create an agent
agent = client.agents.create(
    name="Support Agent",
    voice_id="VOICE_UUID",
    system_prompt="You are a helpful support agent."
)

# Make a call
call = client.calls.create(
    agent_id=agent.id,
    phone_number="+1234567890",
    direction="outbound"
)

# Get call status
status = client.calls.get(call.id)
print(f"Call status: {status.status}")

Authentication

from trudy import TrudyClient

# Using API key
client = TrudyClient(api_key="YOUR_API_KEY")

# Using JWT token (for frontend)
client = TrudyClient(jwt_token="YOUR_JWT_TOKEN")

Agents

# List agents
agents = client.agents.list()

# Get agent
agent = client.agents.get("agent-uuid")

# Create agent
agent = client.agents.create(
    name="My Agent",
    voice_id="voice-uuid",
    system_prompt="You are a helpful agent."
)

# Update agent
agent = client.agents.update(
    "agent-uuid",
    name="Updated Name"
)

# Delete agent
client.agents.delete("agent-uuid")

Calls

# List calls
calls = client.calls.list(limit=50, offset=0)

# Get call
call = client.calls.get("call-uuid")

# Create call
call = client.calls.create(
    agent_id="agent-uuid",
    phone_number="+1234567890",
    direction="outbound",
    call_settings={
        "recording_enabled": True,
        "transcription_enabled": True
    }
)

# Get transcript
transcript = client.calls.get_transcript("call-uuid")

# Get recording
recording = client.calls.get_recording("call-uuid")

Error Handling

from trudy import TrudyError, RateLimitError

try:
    call = client.calls.create(...)
except RateLimitError as e:
    print(f"Rate limit exceeded: {e}")
    print(f"Reset at: {e.reset_at}")
except TrudyError as e:
    print(f"Error: {e.message}")

Rate Limits

The SDK automatically handles rate limit headers:
# Check remaining quota
response = client.calls.list()
remaining = response.headers.get("X-RateLimit-Remaining-Minute")
print(f"Remaining requests: {remaining}")

Examples

See the GitHub repository for more examples.