OneLi with Pydantic AI
How to let an agent built with Pydantic AI place Hebrew phone calls through OneLi, follow the call, answer consultations and read the result.
In Pydantic AI v2, use MCPToolset, which infers the transport, and pass it to the agent’s toolsets.
Setup
- Create an API key at oneli.io/app/connect and store it on the server as
ONELI_API_KEY. - Install the packages:
Terminal
pip install pydantic-ai # or: pip install "pydantic-ai-slim[mcp,openai]"Checked against: pydantic-ai 2.59.0
MCP and a REST tool
Python
import os, uuid, httpx
from pydantic_ai import Agent
from pydantic_ai.mcp import MCPToolset
oneli = MCPToolset("https://mcp.oneli.io/mcp",
headers={"Authorization": f"Bearer {os.environ['ONELI_API_KEY']}"}) # or auth=os.environ["ONELI_API_KEY"]
agent = Agent("openai:gpt-5", instructions="Use OneLi to place calls.", toolsets=[oneli])
@agent.tool_plain
async def create_call_task(to_number: str, goal: str, instructions: str | None = None) -> dict:
"""Have OneLi place a phone call. to_number in E.164."""
body = {"idempotency_key": str(uuid.uuid4()), "to_number": to_number, "goal": goal}
if instructions: body["instructions"] = instructions
async with httpx.AsyncClient(timeout=30) as c:
r = await c.post("https://api.oneli.io/v1/call-tasks", json=body,
headers={"Authorization": f"Bearer {os.environ['ONELI_API_KEY']}"})
r.raise_for_status(); return r.json()
print(agent.run_sync("Call +972… and book a table for 2 at 19:00").output)Notes
- v2 removed MCPServerStreamableHTTP and replaced it with MCPToolset.
- headers= is confirmed from the 2.59.0 source; the docs’ only example uses auth=.
- On 1.x: MCPServerStreamableHTTP(url, headers=…) with toolsets=[…].
Phone numbers: OneLi accepts an Israeli number in any common format (050-1234567, +972501234567). Once the call starts, the agent follows it with get_call_events or GET /v1/call-tasks/:id/events to answer consultations and get the summary.
Next steps
Sources: pydantic.dev/docs/ai/mcp/client/ · pydantic.dev/docs/ai/overview/migration/