OneLi with OpenAI Agents SDK
How to let an agent built with OpenAI Agents SDK place Hebrew phone calls through OneLi, follow the call, answer consultations and read the result.
In the OpenAI Agents SDK, connect OneLi as a Streamable HTTP MCP server with your API key in a header. There is also a hosted variant where OpenAI calls the server, and a plain function tool over the REST API.
Setup
- Create an API key at oneli.io/app/connect and store it on the server as
ONELI_API_KEY. - Install the packages:
pip install openai-agents httpx # or: npm i @openai/agents zodChecked against: openai-agents 0.24.0 (Python) · @openai/agents 0.21.0 (JS)
Python: MCP server
import asyncio, os
from agents import Agent, Runner
from agents.mcp import MCPServerStreamableHttp
async def main():
async with MCPServerStreamableHttp(
name="OneLi",
params={"url": "https://mcp.oneli.io/mcp",
"headers": {"Authorization": f"Bearer {os.environ['ONELI_API_KEY']}"},
"timeout": 30},
client_session_timeout_seconds=60, # default 5s is too short
cache_tools_list=True,
) as oneli:
agent = Agent(name="Assistant", instructions="Use OneLi to place calls.", mcp_servers=[oneli])
print((await Runner.run(agent, "Call +972… and book a table for 2 at 19:00")).final_output)
asyncio.run(main())Python: hosted MCP (OpenAI calls the server)
from agents import Agent, HostedMCPTool
agent = Agent(name="Assistant", tools=[HostedMCPTool(tool_config={
"type": "mcp", "server_label": "oneli", "server_url": "https://mcp.oneli.io/mcp",
"headers": {"Authorization": f"Bearer {os.environ['ONELI_API_KEY']}"}, "require_approval": "never"})])Python: REST function tool
import os, uuid, httpx
from agents import function_tool
@function_tool
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()JavaScript: MCP server and REST tool
import { Agent, run, MCPServerStreamableHttp, tool } from '@openai/agents';
import { z } from 'zod';
const oneli = new MCPServerStreamableHttp({
name: 'OneLi', url: 'https://mcp.oneli.io/mcp',
requestInit: { headers: { Authorization: `Bearer ${process.env.ONELI_API_KEY}` } },
cacheToolsList: true,
});
await oneli.connect();
try {
const agent = new Agent({ name: 'Assistant', instructions: 'Use OneLi to place calls.', mcpServers: [oneli] });
console.log((await run(agent, 'Call +972… and book a table')).finalOutput);
} finally { await oneli.close(); }
// Hosted: hostedMcpTool({ serverLabel:'oneli', serverUrl:'https://mcp.oneli.io/mcp', headers:{Authorization:`Bearer ${key}`}, requireApproval:'never' })
export const createCallTask = tool({
name: 'create_call_task', description: 'Have OneLi place a phone call. to_number in E.164.',
parameters: z.object({ to_number: z.string(), goal: z.string(), instructions: z.string().nullable() }), // strict mode: nullable, not optional
async execute({ to_number, goal, instructions }) {
const r = await fetch('https://api.oneli.io/v1/call-tasks', { method: 'POST',
headers: { Authorization: `Bearer ${process.env.ONELI_API_KEY}`, 'Content-Type': 'application/json' },
body: JSON.stringify({ idempotency_key: crypto.randomUUID(), to_number, goal, ...(instructions ? { instructions } : {}) }) });
if (!r.ok) throw new Error(`OneLi ${r.status}: ${await r.text()}`);
return r.json();
},
});Notes
- For a static key, use headers, not authorization (which is meant for an OAuth access token).
- In Python the default client_session_timeout_seconds is 5 s, too short. Raise it.
- In JS the options have no headers field; pass them through requestInit.
- The hosted MCP tool only works with Responses API models, and local guardrails do not apply to it.
- httpx is not a declared dependency, so install it yourself.
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: openai.github.io/openai-agents-python/mcp/ · openai.github.io/openai-agents-js/guides/mcp/