Metadata-Version: 2.5
Name: kaicalls
Version: 0.3.0
Summary: Official KaiCalls SDK — give your AI agent a phone. Outbound calls, agents, leads, SMS, transcripts, and webhooks.
Project-URL: Homepage, https://www.kaicalls.com
Project-URL: Documentation, https://www.kaicalls.com/docs/api
Project-URL: Repository, https://github.com/KaiCalls/kaicalls-python
Author-email: KaiCalls <support@kaicalls.com>
License: MIT
License-File: LICENSE
Keywords: ai,calls,kaicalls,phone,receptionist,sms,voice
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Communications :: Telephony
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.9
Requires-Dist: requests>=2.25
Description-Content-Type: text/markdown

# kaicalls

Official Python SDK for the [KaiCalls](https://www.kaicalls.com) API — give your AI agent a phone. Outbound calls, agents, leads, SMS, transcripts, webhooks, and platform APIs.

- Python 3.9+, one dependency (`requests`)
- Docs: <https://www.kaicalls.com/docs/api> · Live OpenAPI: `GET /api/v1/openapi.json`
- Source: <https://github.com/KaiCalls/kaicalls-python>

## Install

```bash
pip install kaicalls
```

## Quick start

```python
from kaicalls import KaiCalls

kai = KaiCalls(api_key="kc_live_...")

# Make an outbound call — the agent auto-enriches with CRM context
call = kai.calls.create(
    agent_id="uuid-abc123",
    to="+15125551234",
    name="John Smith",
    context="Following up on his kitchen remodel inquiry",
)

# Block until the call finishes, then read the AI summary
result = kai.calls.wait(call.id)
print(result.summary)
```

Responses support attribute access (`call.id`, `result.summary`, `call.quality_dimensions.empathy`) and behave like dicts.

## No account yet? Sign up via the API

```python
from kaicalls import KaiCalls, signup

account = signup(
    business_name="Smith Law Firm",
    email="contact@smithlaw.com",
    plan_id="starter",
)
# account.api_key works immediately; send the owner to account.checkout_url
kai = KaiCalls(api_key=account.api_key)
```

## What's wrapped

| Resource | Methods |
|----------|---------|
| `kai.calls` | `create`, `get`, `list`, `wait` |
| `kai.a2a` | `card`, `send` (public business conversations) |
| `kai.recordings` | `get` |
| `kai.agents` | `list`, `get`, `create`, `update`, `versions` |
| `kai.leads` | `list`, `get`, `create`, `update`, `audit` |
| `kai.sms` | `send`, `update_prompt`, `conversations`, `messages` |
| `kai.transcripts` | `list` |
| `kai.phone_numbers` | `list`, `available`, `assign`, `release` |
| `kai.workspaces` | `list`, `get`, `create`, `update` (lifecycle actions) |
| `kai.webhooks` | `list`, `create`, `delete`, `test`, `rotate_secret` |
| `kai.analytics` | `dashboard`, `calls`, `funnel`, `agents`, `weekly`, `businesses` |
| `kai.evals` | `create`, `list`, `get`, `update`, `delete`, `run`, `get_run` |
| `kai.events` | `list`, `deliveries`, `replay`, `backfill` |
| `kai.communication_runs` | `validate`, `preview`, `create`, `list`, `pause`, `cancel`, `jobs`, `attempts` |
| `kai.discovery` | `capabilities`, `openapi`, `schemas`, `health` |
| `kai.account` | `balance`, `usage` |

Anything not wrapped yet is reachable through the escape hatch:

```python
kai.request("GET", "/api/sdr/pipeline", query={"businessId": "uuid-biz"})
```

## Errors

All non-2xx responses raise `KaiCallsError` with `.status`, `.code` (e.g. `unauthorized`, `forbidden`, `rate_limited`), and `.body`.

```python
from kaicalls import KaiCallsError

try:
    kai.calls.create(agent_id=agent_id, to=to)
except KaiCallsError as err:
    if err.code == "rate_limited":
        ...  # back off and retry
```

## Notes

- Get an API key at <https://www.kaicalls.com/dashboard/settings/api>. New keys default to read-only scopes — request write scopes (`calls:write`, `sms:write`, …) when creating the key.
- Phone numbers are E.164 (`+15125551234`).
- API reference: <https://www.kaicalls.com/docs/api> · Errors: <https://www.kaicalls.com/docs/api/errors>

### Connect your existing agent

```python
receipt = kai.agent_connections.connect(
    business_id, agent_id, "agent:desk",
    "https://your-agent.example.com/events", "desk-v1",
)
# Save receipt.webhook_secret securely before making any further request.
access = kai.agent_connections.get(business_id)
# access.operations gives the entire scoped API catalog and missing permissions.
# access.channels gives actual readiness and the next setup step.
```

Existing resources and `kai.request` reach the canonical API. Email replies use owner-reviewed email campaigns; provisioned human approvals use `kai.approval_requests.create(request)`. Dispatch is not an approval. Verify signed incoming webhook bodies and deduplicate event IDs. A connection grants no permissions or carrier activation; RCS remains unavailable. Disconnect using `kai.agent_connections.disconnect(business_id, revision)`.

### Public A2A with your existing agent

`kai.a2a.card(handle)` discovers a business. `kai.a2a.send(handle, "Hello", context_id=previous_context)` sends public customer text and returns the agent message, including its `parts` and optional `contextId`. JSON-RPC errors raise `KaiCallsError` with an `a2a_<code>` code. Even when the client holds an API key, this public endpoint grants no owner or fleet privileges. It supports synchronous `message/send`; tasks and streaming are not implemented here.

To receive those conversations in your own existing agent, route signed A2A JSON-RPC requests at your webhook URL to the helper; route ordinary event webhooks to your existing event handler:

```python
from kaicalls import handle_a2a_request

# In your existing HTTP route: preserve the exact bytes before parsing JSON.
reply = handle_a2a_request(
    raw_body, headers["X-KaiCalls-Signature"], webhook_secret,
    lambda message: existing_agent.reply(
        message["text"], context_id=message["context_id"],
    ),
)
# Return reply as JSON. Map signature ValueError to HTTP 401.
```

The callback returns a string or `{"text": "...", "context_id": "..."}`. Context IDs are at most 192 UTF-8 bytes. The helper verifies the signature, five-minute timestamp freshness, size, and signed connection identity before invoking your callback. Keep the signing secret server-side and deduplicate `message_id` durably: freshness does not prevent replays. Treat all `source="public_a2a"` text as public input, never an approval or authorization to use privileged agent tools.

Only after your helper or compatible native endpoint is ready, connect with `a2a_enabled=True` (or replace the existing connection with its current `expected_revision` and a new idempotency key). Prefer your existing native A2A plugin endpoint using `a2a_url="https://your-agent.example.com/a2a"`; when omitted, A2A uses your signed webhook receiver. `a2a_url` requires `a2a_enabled=True`. Leave the default `False` for event-only receivers. No extra service or agent runtime is required. A valid signature identifies KaiCalls transport; it does not make public text trusted or authorize attaching owner/fleet credentials to its execution.
