עבריתLog in

OneLi with Vercel AI SDK

How to let an agent built with Vercel AI SDK place Hebrew phone calls through OneLi, follow the call, answer consultations and read the result.

In AI SDK v7, create an MCP client with createMCPClient from @ai-sdk/mcp and pass its tools to generateText or an agent.

Setup

  1. Create an API key at oneli.io/app/connect and store it on the server as ONELI_API_KEY.
  2. Install the packages:
Terminal
npm i ai @ai-sdk/mcp @ai-sdk/openai zod

Checked against: ai 7.0.148 · @ai-sdk/mcp 2.0.81

MCP connection and REST tool

TypeScript
import { createMCPClient } from '@ai-sdk/mcp';
import { generateText, stepCountIs, tool } from 'ai';
import { openai } from '@ai-sdk/openai';
import { z } from 'zod';

const mcp = await createMCPClient({
  transport: { type: 'http', url: 'https://mcp.oneli.io/mcp',
    headers: { Authorization: `Bearer ${process.env.ONELI_API_KEY}` } },
});
try {
  const { text } = await generateText({
    model: openai('gpt-5'), tools: await mcp.tools(),
    stopWhen: stepCountIs(10),               // default is 1 step: without this the model never answers after the tool call
    prompt: 'Call +972… and book a table for 2 at 19:00',
  });
  console.log(text);
} finally { await mcp.close(); }

export const createCallTask = tool({
  description: 'Have OneLi place a phone call. to_number in E.164.',
  inputSchema: z.object({ to_number: z.string(), goal: z.string(), instructions: z.string().optional() }), // inputSchema, not parameters
  execute: async (input) => {
    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(), ...input }) });
    if (!r.ok) throw new Error(`OneLi ${r.status}`);
    return r.json();
  },
});
// generateText({ ..., tools: { create_call_task: createCallTask } })

Notes

  • Without stopWhen the default is one step, so the model never answers after the tool call.
  • In v7 the primary name is isStepCount; stepCountIs is still exported as an alias.
  • tool() takes inputSchema, not parameters.
  • The ToolLoopAgent class defaults to 20 steps.
  • OpenAI-only hosted alternative: openai.tools.mcp({ serverLabel, serverUrl, headers }).

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: ai-sdk.dev/docs/ai-sdk-core/mcp-tools