Official Python SDK for the Tone API
Project description
tone-sdk (Python)
Official Python SDK for the Tone API.
Give your AI agent a real phone number. One API call provisions a number, one webhook handles calls and SMS.
Installation
pip install tone-sdk
Async Quickstart
import asyncio
from tone import ToneClient
async def main():
tone = ToneClient(api_key='tone_live_...')
# Give your agent a phone number
number = await tone.numbers.provision(country_code='IN')
print(f'Your number: {number.phone_number}') # +918035001234
# Make a call
await tone.calls.initiate(
to='+919876543210',
from_number=number.phone_number,
instructions='You are a helpful assistant. Greet the caller in Hindi.',
)
# Send an SMS
await tone.sms.send(
to='+919876543210',
from_number=number.phone_number,
message='Your OTP is 4821',
)
asyncio.run(main())
Sync Quickstart
from tone import SyncToneClient
tone = SyncToneClient(api_key='tone_live_...')
number = tone.numbers.provision(country_code='IN')
tone.sms.send(
to='+919876543210',
from_number=number.phone_number,
message='Hello from Tone!',
)
API Reference
ToneClient(api_key, ...)
| Parameter | Type | Required | Default |
|---|---|---|---|
api_key |
str |
✓ | — |
base_url |
str |
https://api.usetone.ai |
|
timeout |
float (seconds) |
30.0 |
|
max_retries |
int |
3 |
tone.numbers
provision(country_code='IN', friendly_name=None) → PhoneNumber
number = await tone.numbers.provision(
country_code='IN', # 'IN' | 'US' | 'GB' | 'AU'
friendly_name='Support', # optional
)
list() → NumberList
result = await tone.numbers.list()
for n in result.numbers:
print(n.phone_number)
release(phone_number) → None
await tone.numbers.release('+918035001234')
tone.calls
initiate(to, from_number, instructions, max_duration=300) → Call
Note: from_number is used instead of from (Python reserved word).
call = await tone.calls.initiate(
to='+919876543210',
from_number='+918035001234',
instructions='You are a support agent.',
max_duration=300,
)
list(number=None, limit=20, cursor=None) → CallLogList
result = await tone.calls.list(limit=50)
for log in result.logs:
print(log.call_id, log.state)
if result.next_cursor:
more = await tone.calls.list(cursor=result.next_cursor)
tone.sms
send(to, from_number, message) → SmsResult
result = await tone.sms.send(
to='+919876543210',
from_number='+918035001234',
message='Your OTP is 4821', # max 1600 chars
)
list(number=None, limit=20, cursor=None) → SmsLogList
result = await tone.sms.list(limit=50)
Error Handling
from tone import ToneClient, ToneApiError, ToneValidationError, ToneNetworkError
tone = ToneClient(api_key='tone_live_...')
try:
await tone.sms.send(to='invalid', from_number='+91...', message='hi')
except ToneValidationError as e:
print(f"Validation error on '{e.field}': {e}")
except ToneApiError as e:
print(f"API error {e.status_code} [{e.code}]: {e}")
print(f"Request ID: {e.request_id}")
except ToneNetworkError as e:
print(f"Network failure: {e.cause}")
LangChain Integration
from tone import ToneClient
from tone.integrations.langchain import ToneSendSmsTool, ToneInitiateCallTool
tone = ToneClient(api_key='tone_live_...')
tools = [
ToneSendSmsTool(client=tone),
ToneInitiateCallTool(client=tone),
]
# Use with any LangChain agent
from langchain.agents import initialize_agent
agent = initialize_agent(tools, llm, agent='zero-shot-react-description')
Install with LangChain extras:
pip install "tone-sdk[langchain]"
HTTP Behaviour
- Retries: 429 and 5xx are retried with exponential backoff (1s → 2s → 4s). 4xx not retried.
- Retry-After: Honoured on 429 responses.
- User-Agent:
tone-sdk-python/1.0.0on every request. - X-Request-Id: UUID per request for server-side tracing.
- Timeout: Full lifecycle (default 30s).
Requirements
- Python ≥ 3.10
- httpx ≥ 0.27
- pydantic ≥ 2.0
License
MIT © Bellatech Marketing Pvt. Ltd.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tone_sdk-1.2.0.tar.gz.
File metadata
- Download URL: tone_sdk-1.2.0.tar.gz
- Upload date:
- Size: 17.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
812355ab43bfd78740899898e47df6a8c974eec67d50d841f847076abca7284a
|
|
| MD5 |
a760f745026a1cdeeea59001e7ea542c
|
|
| BLAKE2b-256 |
a01a6ea4c5f39781d86ec44de5b15bc18a260e00075b880012dcb2aeb65c3541
|
File details
Details for the file tone_sdk-1.2.0-py3-none-any.whl.
File metadata
- Download URL: tone_sdk-1.2.0-py3-none-any.whl
- Upload date:
- Size: 24.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8abc818b1fa1b476acebdef75bdfd3411f85320cc00febb87d0a8dfb19daa85c
|
|
| MD5 |
b47dc0733ce902374dd3088397837528
|
|
| BLAKE2b-256 |
0404370f0744433d7fd4c0d68e18b18688394260fe4559cf9ec9ab45c0ce99a8
|