Skip to content

Python SDK ​

kolwire (import kolwire) — sync and async clients on httpx, pydantic v2 models, websockets for realtime and media streams.

bash
pip install kolwire

Client ​

python
from kolwire import Kolwire, AsyncKolwire

client = Kolwire(
    api_key="vi_live_…",                     # default: env KOLWIRE_API_KEY
    base_url="https://api.kolwire.com/v1",  # default: env KOLWIRE_BASE_URL
    max_retries=2,
    timeout=60.0,
    webhook_secret="whsec_…",                # default: env KOLWIRE_WEBHOOK_SECRET
)

call = client.calls.create(from_="+15550001111", to="+15550002222", agent_id="agt_123")
client.calls.actions(call.id, commands=[{"command": "say", "text": "One moment."}])
print(client.calls.insights(call.id).summary)

Async: the same API with await:

python
aclient = AsyncKolwire()
call = await aclient.calls.create(from_="+15550001111", to="+15550002222", agent_id="agt_123")

Resources mirror Node in snake_case: client.numbers, client.calls, client.call_flows, client.contacts, client.messages, client.conversations, client.whatsapp.templates, client.agents, client.playbooks, client.knowledge_bases, client.team_agents, client.queues, client.campaigns, client.dispositions, client.webhook_endpoints, client.api_keys, client.stream_tokens, client.search, client.billing, client.usage, client.wallboard. Every method: resources & methods.

Keyword parameters: request fields are keyword arguments. One trailing underscore is stripped, so Python keywords work: from_= → from. Method names that are keywords get an underscore: client.campaigns.import_(campaign_id, contacts=[…]). Models expose the wire field from as .from_ (e.g. call.from_, event.data.from_).

Per-request options ​

python
client.messages.create(
    from_=sender, to=to, body="…",
    request_options={"idempotency_key": "order-1042-shipped", "timeout": 10, "max_retries": 0, "headers": {"x-trace-id": trace}},
)

Pagination ​

python
for call in client.calls.list(status="completed"):     # every item, fetched lazily
    ...
page = client.calls.list(limit=50).get_page()          # one page: data, has_more, next_cursor

async for call in aclient.calls.list():
    ...

Errors ​

Same hierarchy as Node: APIError (status, code, details) with BadRequestError, AuthenticationError, InsufficientFundsError, PermissionDeniedError, NotFoundError, ConflictError, UnprocessableEntityError, RateLimitError, InternalServerError; plus APIConnectionError, APITimeoutError, WebhookVerificationError.

python
from kolwire import NotFoundError
try:
    client.calls.get("call_missing")
except NotFoundError as e:
    print(e.status, e.code)

Webhooks ​

python
event = client.webhooks.construct_event(raw_body, request.headers)   # verifies + parses
from kolwire.webhooks import construct_event, verify_signature
event = construct_event(raw_body, headers, secret=[new_secret, old_secret])

event is a typed pydantic model: check event.type, read event.data. See webhook security.

Commands ​

python
from kolwire import VoiceResponse, Flow, say

VoiceResponse().say("Hi!").connect_agent("agt_123").to_dict()   # {"commands": [...]}
Flow().say("Welcome").hangup().to_dict()                         # {"version": 1, "start": [...]}

Methods mirror Node in snake_case: say, play, pause, answer, hangup, reject, gather, dial, transfer, conference, enqueue, record, stream, connect_agent, assist, transcribe, send_dtmf, redirect, sms, detect_machine, add.

Realtime ​

python
stream = await aclient.realtime(call_id="call_123", events=["call.transcript.*"])
stream.on("call.transcript.final", lambda e: print(e.data.text))
async for e in stream.events("call.assist.suggestion"):
    print(e.data.title)
await stream.close()

from kolwire.realtime import StreamClient
stream = StreamClient(url="wss://stream.kolwire.com/v1/stream", token=get_token)  # token: str or (async) callable
await stream.connect()

Media streams ​

python
from kolwire.media import serve_media_stream

async def handler(session):
    info = await session.started()             # dict: call_id, codec, sample_rate, track, ...
    async for frame in session.audio_frames():  # frame.pcm: PCM16 LE bytes
        ...
    await session.send_audio(pcm_bytes, sample_rate=24000)
    await session.mark("x")
    await session.clear()

server = await serve_media_stream(handler, port=8080, path="/media", token=os.environ["MEDIA_TOKEN"])
await server.serve_forever()   # a websockets server; extra kwargs are passed to websockets.serve

session.audio_frames() is single-consumer (frames are buffered from stream start); use session.on("audio", fn) when several listeners need them.

Audio helpers in kolwire.audio. See BYO voice agent.