The Vapi Python library provides convenient access to the Vapi API from Python.
This release supports Python 3.10 through 3.14.
python -m pip install vapi_server_sdkInstall the optional async transport:
python -m pip install "vapi_server_sdk[aiohttp]"Version 3.0.0 updates the generated types to the current Vapi API definition. Review the 3.0.0 migration notes before upgrading from 1.x. Public helper imports, declared model fields, and structured-output run response types have changed.
python -m pip install --upgrade "vapi_server_sdk>=3.0.0,<4"See the Python SDK reference for methods, parameters, and response types.
Set the VAPI_API_KEY environment variable to your Vapi private API key. Create a client and list up to 10 assistants in your organization:
import os
from vapi import Vapi
client = Vapi(token=os.environ["VAPI_API_KEY"])
assistants = client.assistants.list(limit=10)
for assistant in assistants:
print(assistant.id)Use AsyncVapi to await API requests:
import asyncio
import os
from vapi import AsyncVapi
async def main() -> None:
client = AsyncVapi(token=os.environ["VAPI_API_KEY"])
assistants = await client.assistants.list(limit=10)
for assistant in assistants:
print(assistant.id)
asyncio.run(main())Catch ApiError to inspect an unsuccessful API response:
import os
from vapi import Vapi
from vapi.core.api_error import ApiError
client = Vapi(token=os.environ["VAPI_API_KEY"])
try:
client.assistants.list(limit=10)
except ApiError as error:
print(error.status_code)
print(error.body)client.assistants.list() returns a Python list. Use its limit and timestamp filters to select results. Other endpoints have their own response types and pagination parameters; consult the SDK reference for the endpoint you use.
The SDK retries HTTP 408, 409, 429, and 5xx responses with backoff. The default maximum is two retries. Set max_retries for an individual request:
import os
from vapi import Vapi
client = Vapi(token=os.environ["VAPI_API_KEY"])
client.assistants.list(limit=10, request_options={"max_retries": 1})The default client timeout is 60 seconds. Set timeout when creating the client or override it with timeout_in_seconds for a request. When you supply a custom HTTPX client, its read timeout becomes the default unless you set timeout explicitly.
import os
from vapi import Vapi
client = Vapi(token=os.environ["VAPI_API_KEY"], timeout=20.0)
client.assistants.list(limit=10, request_options={"timeout_in_seconds": 1})Pass an HTTPX client to configure its transport. This example sets HTTPTransport.local_address and closes the custom client when the block finishes:
import os
import httpx
from vapi import Vapi
with httpx.Client(transport=httpx.HTTPTransport(local_address="0.0.0.0")) as http:
client = Vapi(token=os.environ["VAPI_API_KEY"], httpx_client=http)
assistants = client.assistants.list(limit=10)
for assistant in assistants:
print(assistant.id)While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!
On the other hand, contributions to the README are always very welcome!