cd /news/ai-agents/a-real-phone-number-answered-by-an-a… · home › topics › ai-agents › article
[ARTICLE · art-179758] src=dev.to ↗ pub= topic=ai-agents verified=true sentiment=↑ positive

A real phone number answered by an AI voice agent: OpenAI, ElevenLabs, Gemini and Grok behind one small PHP endpoint

A developer built a working AI voice agent on a real phone line using DotSIP, a self-hosted telephony engine that routes incoming SIP calls to a PHP endpoint and hands them to a live voice session. The setup uses two short PHP files—one to answer and assign an agent, one to serve tool calls—and swapping a single constant switches the same number between OpenAI, ElevenLabs, Google Gemini and xAI Grok. In a recorded call, the Gemini-backed agent checked opening hours twice via the tool endpoint and ended the call on its own three seconds after the caller said goodbye, without any hang-up instruction in its three-sentence prompt.

recommendation

Separate call routing from tool lookups into two endpoints so the voice provider can be swapped by changing one agent identifier while the prompt and tools stay fixed.

more in playbook: Designing agent systems
by read20 min views8 publishedDec 1, 2026

I build DotSIP, the telephony engine used in this article. Everything below ran on a real phone line; every transcript is from a real call.

A phone rings. An AI voice answers, the caller asks when the office is open on Wednesday and on Saturday, the agent asks my code each time, says the answer, and when the caller says goodbye it hangs up. Nobody told it how to hang up.

The video below shows the whole set-up for this call, from the tool endpoint to the call history. Everything in it is also written out in this article.

This is the conversation from the call history. The caller's lines are what the speech recognition heard, word for word:

Agent: Good morning, this is the DotSIP assistant on Google Gemini. How can I help you?
Caller: I would like to check when you are open on Wednesday.
Agent: On Wednesday, we are open from 8:00 to 18:00.
Caller: Okay, how about Saturday?
Agent: We are closed on Saturday.
Caller: Okay, thank you. Bye.
Agent: Goodbye.

And this is what happened underneath, from the same history (times in UTC):

1. check_opening_hours   10:44:11
2. check_opening_hours   10:44:20
3. end_call              10:44:26      call ended by the agent 3 seconds later

My part of it is two short PHP files. The agent's prompt is three sentences, and none of them is about ending the call. That call was answered by Google Gemini. Below I build the same line with OpenAI first, and then change one line so that the same number is answered by ElevenLabs, Gemini and xAI Grok, with the same tool and the same prompt.

caller ──▶ your phone number (a SIP account) ──▶ DotSIP ──▶ route.php   "answer, give it to agent-desk"
                                                    │
                                          the voice agent talks
                                                    │
                                 the agent needs a fact ──▶ tool.php   "open from 8:00 to 18:00"

DotSIP is a program you run on your own Windows or Linux machine. It registers to your phone provider, takes the call, and has no opinion about what should happen next. It asks a web address you give it, once per call. Whatever answers there decides. That is the route endpoint.

When the answer is "put an agent on it", DotSIP runs the live voice session. When the agent needs something from the real world, DotSIP calls a second web address of yours. That is the tool endpoint.

A GSM gateway works the same way as a provider's number. To DotSIP both are SIP accounts, so nothing in this article changes.

The provider charges for the minutes, the voice provider charges for the model, and DotSIP needs a license after the trial. None of that is hidden in the steps below.

DotSIP POSTs one JSON object when a call arrives: who is calling, which number was dialed, through which account. You answer with a list of commands.

<?php
// route.php: DotSIP asks this endpoint what to do with each call.
// Every incoming call is answered and handed to one agent, with the right "right-1".

// Who answers. This one line is the whole choice of the voice:
//   'agent-desk'    OpenAI
//   'agent-eleven'  ElevenLabs
//   'agent-gemini'  Google Gemini
//   'agent-grok'    xAI Grok
const AGENT = 'agent-desk';

header('Content-Type: application/json');

$ask = json_decode(file_get_contents('php://input'), true) ?: [];

// The call is over. DotSIP only reports it; the answer is discarded.
if (($ask['event'] ?? '') === 'ended') {
    echo json_encode(['format_version' => 1, 'action' => 'reject']);
    exit;
}

// A new call: answer it and hand it to the agent.
echo json_encode([
    'format_version' => 2,
    'commands' => [
        ['do' => 'answer'],
        ['do' => 'agent', 'agent' => AGENT, 'rights' => 'right-1'],
    ],
]);

This is the place where your own logic would go. The request carries the caller's number, so the same file can look the caller up in your database first, check the time, and answer with something else: ring a group of phones, forward to a mobile, play a message. Here every call gets the agent.

rights is a label for this one call. A tool is offered to the agent only on calls whose label allows it, which is how the same agent can do more for a known customer than for a stranger.

When the agent decides it needs a tool, DotSIP POSTs the tool's name and the arguments the model filled in. You answer ok and the facts. The agent says them.

<?php
// tool.php: DotSIP POSTs here each time the agent uses a tool.
// "tool" says which tool, "arguments" holds what the model filled in.
// Hanging up needs nothing here: DotSIP confirms end_call itself.

header('Content-Type: application/json');

$call = json_decode(file_get_contents('php://input'), true) ?: [];
$tool = (string)($call['tool'] ?? '');
$args = is_array($call['arguments'] ?? null) ? $call['arguments'] : [];

if ($tool === 'check_opening_hours') {
    // In a real system these come from your database.
    $hours = [
        'monday' => '8:00 to 16:00', 'tuesday' => '8:00 to 16:00', 'wednesday' => '8:00 to 18:00',
        'thursday' => '8:00 to 16:00', 'friday' => '8:00 to 14:00',
        'saturday' => 'closed', 'sunday' => 'closed',
    ];
    $day = strtolower(trim((string)($args['day'] ?? '')));

    // Never trust the arguments: the model filled them from what a stranger said.
    if (!isset($hours[$day])) {
        echo json_encode([
            'ok' => false,
            'message' => 'I can tell you the opening hours for any day of the week, Monday to Sunday. Which day do you mean?',
        ]);
        exit;
    }

    $open = $hours[$day];
    echo json_encode([
        'ok' => true,
        'result' => ['day' => $day, 'hours' => $open],
        'message' => $open === 'closed' ? "On $day we are closed." : "On $day we are open from $open.",
    ]);
    exit;
}

// A tool this endpoint does not know.
echo json_encode(['ok' => false, 'error' => 'unknown tool']);

Two things I would not skip in real code:

There is no branch for hanging up. Every agent has a tool called end_call, and DotSIP answers it itself. More on that after the first call.

Run both files with anything that serves PHP. For a test on the same machine as DotSIP:

php -S 127.0.0.1:8099 -t .

Before DotSIP is involved at all, send each file the request DotSIP will send:

curl -s -X POST http://127.0.0.1:8099/tool.php -H "Content-Type: application/json" \
  -d '{"format":"dotsip.tool-call","format_version":1,"call_id":"test-1","tool":"check_opening_hours","arguments":{"day":"wednesday"},"caller":{"number":"+421905123456","name":null,"rights":"right-1"}}'

curl -s -X POST http://127.0.0.1:8099/route.php -H "Content-Type: application/json" \
  -d '{"format":"dotsip.route","format_version":1,"event":"incoming","direction":"inbound","call_id":"test-1","sip_account":{"id":"main","name":"main"},"sip_phone":null,"dialed":"0212345678","route":"route-main","caller":{"number":"+421905123456","name":null,"rights":null,"groups":[]}}'

Everything in the administration can also be done through DotSIP's own HTTP API, so I will show the requests. It is the same thing you would click, and it is what you would script for the tenth customer.

Create an API key in the administration (API) with the scopes config:read, config:write, tools:write, credentials:write, system:write and recordings:read (or *), and copy the secret and the port. Then:

API=http://127.0.0.1:19555
KEY=dsk_your_key
send() { curl -s -X "$1" "$API$2" -H "Authorization: Bearer $KEY" -H "Content-Type: application/json" -d "$3"; echo; }

The route. Where DotSIP asks what to do with a call.

send POST /v1/routes '{
  "id": "route-main", "scheme": "http", "url": "http://127.0.0.1:8099/route.php",
  "verify_ssl": false, "timeout_ms": 5000}'

Use https and leave verify_ssl out when the endpoint is on another computer.

The tool. Its description is what the model reads to decide when to use it. The parameters are a JSON Schema.

send POST /v1/tools '{
  "id": "check_opening_hours", "endpoint": "http://127.0.0.1:8099/tool.php",
  "description": "Tells the opening hours for one day of the week, Monday to Sunday. Use it whenever the caller asks when we are open or closed.",
  "parameters": {"type": "object",
    "properties": {"day": {"type": "string",
      "description": "The day of the week the caller asks about, in English, lower case: monday, tuesday, wednesday, thursday, friday, saturday or sunday."}},
    "required": ["day"]},
  "rights": ["right-1"]}'

Every word of that description is there for a reason; one of them cost me a call (see What I learned on the way). There is no request for hanging up: end_call already exists, and every agent has it.

The key of the voice provider. For OpenAI it belongs to the models, not to the agent. GET /v1/models?provider=openai lists them with their numeric ids; save the key on the live model the agent speaks with and on the responses model that runs the tools (the text model of the tool router, GET /v1/routers/tool-router-builtin names it in model_id). The ids differ between installations; on mine they are 1 and 2.

send PATCH /v1/models/1 '{"api_key": "sk-your-openai-key"}'
send PATCH /v1/models/2 '{"api_key": "sk-your-openai-key"}'

The agent. Its model, its tool, the first sentence, and the prompt.

send POST /v1/agents '{
  "id": "agent-desk", "live_model": "1", "router_id": "tool-router-builtin",
  "tools": ["check_opening_hours"],
  "voice_provider": "openai",
  "voice_config": {"first_message": "Good morning, this is the DotSIP assistant. How can I help you?"},
  "prompt": "You are the receptionist of our office. You tell callers when we are open. You never invent opening hours."}'

That is the whole prompt. It says who the agent is, what it does, and what it must not make up. It does not name the tool (the tool's description does that), and it says nothing about saying goodbye or hanging up. DotSIP sends its own built-in instructions with every call, and those carry the mechanics that are the same for every business: how a tool result is spoken, and how a call ends.

An OpenAI agent's voice_config takes only first_message and language. Anything else, voice for example, is refused with 400 and the answer names the key.

The phone number. The data from your provider, and the route its calls should take.

send POST /v1/sip-accounts '{
  "account_id": "main", "display_name": "Main number",
  "registrar_uri": "sip:sip.provider.example:5060",
  "account_uri": "sip:0212345678@sip.provider.example",
  "username": "0212345678", "password": "provider-password", "realm": "sip.provider.example",
  "transfer_uri_template": "sip:{extension}@sip.provider.example",
  "inbound_route": "route-main"}'

send PATCH /v1/sip-settings '{"incoming_account_ids": ["main"]}'

incoming_account_ids replaces the whole list. If other accounts already take calls, read GET /v1/sip-settings first and send their ids too.

Check it before you pick up a phone.

send POST /v1/sip-accounts/main/test '{}'

That is seven requests and one check. From here on, DotSIP itself needs no more attention: what a call does is decided by your two files.

Call it and ask "When are you open on Wednesday?", then "And on Saturday?", then say "Thank you, bye." The agent answers both through the tool and hangs up after its farewell. The history has the proof:

curl -s "$API/v1/history?limit=1" -H "Authorization: Bearer $KEY"       # the newest call and its call_id
curl -s "$API/v1/history/<call_id>" -H "Authorization: Bearer $KEY"     # its result, steps and transcript

This is the stored transcript of my call, unchanged. I asked about Thursday that time:

Agent: Good morning, this is the DotSIP assistant. How can I help you?
Caller: When you are open on a Wednesday
Agent: Let me check that for you. On Wednesday, we're open from 8:00 in the morning until 6:00 in the evening. Anything else you'd like to know?
Caller: And Thursday
Agent: I'll check Thursday for you. On Thursday, we're open from 8:00 in the morning until 4:00 in the afternoon. Would you like to ask about another day?
Caller: No, I am satisfied, thank you
Agent: Okay, you're welcome. Thank you for calling. Have a great day!
1. check_opening_hours   18:38:57
2. check_opening_hours   18:39:08
3. end_call              18:39:21      call ended by the agent 4 seconds later

Two questions, two tool calls, and the end of the call came from the agent: "No, I am satisfied, thank you" has no "bye" in it, and the agent still understood that the caller was finished.

The same is on the page Call history in the administration, with the call flow and the text.

It works out of the box. You do not create a tool for it, you do not tick anything on the agent, your tool endpoint has no branch for it, and the prompt has no sentence about it. This is what happens:

1. The caller is finished: says goodbye in any words, says that is all, or asks to end the call.
2. The model calls the tool end_call. Every agent has it, with every provider, on every call.
3. DotSIP confirms it itself.
4. The agent says its farewell, and DotSIP plays it to the caller.
5. DotSIP drops the line: when the farewell has been played, at least 3 seconds after step 3,
   and at the latest after the agent's end_call_seconds (4 by default) if no farewell comes at all.

A spoken goodbye alone ends nothing. DotSIP never hangs up because of a word; it hangs up only after a successful end_call.

You do not have to listen for a click to know who ended the call. This is the history of the Gemini call from the top of this article:

{"ok": true, "item": {"call_id": "f2ae65cd4edbb297", "started_at": "2026-12-01T10:44:00+00:00", "ended_at": "2026-12-01T10:44:30+00:00",
  "direction": "inbound", "caller": "+421905123456", "target": null, "extension": null, "sip_account": "main",
  "result": "hangup", "has_transcript": true,
  "steps": [
    {"ts": "2026-12-01T10:44:11+00:00", "kind": "check_opening_hours", "payload": ""},
    {"ts": "2026-12-01T10:44:20+00:00", "kind": "check_opening_hours", "payload": ""},
    {"ts": "2026-12-01T10:44:26+00:00", "kind": "end_call", "payload": ""}],
  "transcript": "..."}}

result hangup means DotSIP ended the call, and the last step end_call means the agent asked for it. result ended with no end_call step would mean the caller had to hang up. In dotsip.log the same ending is three lines:

tool.call name=end_call call_id=f2ae65cd4edbb297
call.supervisor.armed state=farewell_armed:end_call call_id=f2ae65cd4edbb297
call.end_by_supervisor trigger=agent_farewell call_id=f2ae65cd4edbb297

The videos above use a longer prompt that spells the ending out in its own sentences. Both forms work: the longer prompt, and the three sentences of this article.

The agent, not the route, knows which provider speaks. So another provider is one more agent, and the same two PHP files serve it unchanged. This video shows the four agents side by side on the same number:

The three agents below have the same tool and the same three-sentence prompt as agent-desk. What differs is where the key goes and what the voice settings are called:

OpenAI ElevenLabs, direct mode Google Gemini Live xAI Grok Voice
voice_provider openai elevenlabs gemini grok
Who calls the tools a text model inside DotSIP; the speaking model hands work over to it the model that speaks the model that speaks the model that speaks
The provider's key on the models ( PATCH /v1/models/{id} ) on the agent ( voice_api_key ) on the agent ( voice_api_key ) on the agent ( voice_api_key )
live_model needed not used not used not used
After you change a tool's description nothing POST /v1/agents/{id}/voice-setup nothing nothing

A provider cannot be changed on an existing agent; another provider is another agent.

The ElevenLabs key goes on the agent. DotSIP creates the agent in your ElevenLabs account and gives it the tools, end_call included; you set nothing up in the ElevenLabs dashboard.

send POST /v1/agents '{
  "id": "agent-eleven",
  "tools": ["check_opening_hours"],
  "voice_provider": "elevenlabs", "voice_api_key": "sk_your-elevenlabs-key",
  "voice_config": {"mode": "direct", "voice_id": "your-voice-id", "language": "en",
                   "conversation_llm": "gpt-4o-mini",
                   "first_message": "Good morning, this is the DotSIP assistant on ElevenLabs. How can I help you?"},
  "prompt": "You are the receptionist of our office. You tell callers when we are open. You never invent opening hours."}'

In route.php:

const AGENT = 'agent-eleven';

Save the file and call again. This is the stored transcript of that call, unchanged:

Agent: Good morning, this is the DotSIP assistant on ElevenLabs. How can I help you?
Caller: What hours you are open on Wednesday?
Agent: On Wednesday, we are open from eight in the morning to six in the evening.
Caller: And how about Saturday?
Agent: On Saturday, we are closed.
Caller: Okay. Thank you.
Agent: Is there anything else you need?
Caller: No, no, no. Thank you. Bye.
Agent: Goodbye!
1. check_opening_hours   10:54:08
2. check_opening_hours   10:54:17
3. end_call              10:54:28      call ended by the agent 3 seconds later

Look at the middle. "Okay. Thank you." after an answer did not end the call; the agent asked whether there was anything else. Only "No, no, no. Thank you. Bye." did. That distinction comes from DotSIP's built-in instructions, not from my prompt.

Two things are specific to ElevenLabs:

  send POST /v1/agents/agent-eleven/voice-setup '{}'

ElevenLabs has a second mode, "mode": "delegate", where the ElevenLabs model only speaks and an OpenAI text model inside DotSIP runs the tools (it needs the OpenAI key on the models, as in Step 3). I called it on 0.2.0 too, with the same prompt: "Okay. Thank you." after an answer did not end the call, "No, that's all. Thank you. Bye." did. It was slower: the first tool call came four seconds after my question, and I had asked again before the answer came.

Gemini Live is one model that hears, speaks and calls the tools. It needs one Google API key, on the agent, and nothing else: no account to prepare, no second model.

send POST /v1/agents '{
  "id": "agent-gemini",
  "tools": ["check_opening_hours"],
  "voice_provider": "gemini", "voice_api_key": "your-google-api-key",
  "voice_config": {"voice": "Kore", "language": "en-US",
                   "first_message": "Good morning, this is the DotSIP assistant on Google Gemini. How can I help you?"},
  "prompt": "You are the receptionist of our office. You tell callers when we are open. You never invent opening hours."}'
js
const AGENT = 'agent-gemini';

This is the call at the top of the article. Its steps:

1. check_opening_hours   10:44:11
2. check_opening_hours   10:44:20
3. end_call              10:44:26      call ended by the agent 3 seconds later

Grok Voice is the same arrangement as Gemini: one xAI model hears, speaks and calls the tools. The xAI key goes on the agent, and nothing is set up at xAI; DotSIP sends the prompt, the voice and the tools with every call.

send POST /v1/agents '{
  "id": "agent-grok",
  "tools": ["check_opening_hours"],
  "voice_provider": "grok", "voice_api_key": "your-xai-api-key",
  "voice_config": {"voice": "eve", "language": "en",
                   "first_message": "Good morning, this is the DotSIP assistant on Grok. How can I help you?"},
  "prompt": "You are the receptionist of our office. You tell callers when we are open. You never invent opening hours."}'
js
const AGENT = 'agent-grok';

The stored transcript, unchanged, and the steps:

Agent: Good morning, this is the DotSIP assistant on Grok. How can I help you?
Caller: When we are open at Wednesday?
Agent: Let me check Wednesday for you.
Agent: On Wednesday we are open from 8:00 to 18:00. Is there anything else you'd like to know?
Caller: So how about Saturday?
Agent: Checking Saturday now.
Agent: On Saturday we are closed. Would you like the hours for another day?
Caller: No, no, no. Thank you. Bye.
Agent: I'll hang up for you.
Agent: Goodbye!
1. check_opening_hours   10:42:15
2. check_opening_hours   10:42:27
3. end_call              10:42:38      call ended by the agent 3 seconds later

Grok says a short line before it uses a tool ("Let me check Wednesday for you."), which keeps the caller from listening to silence. The line "I'll hang up for you." is one I did not want: Grok announced the hang-up and then said goodbye. That call ran on a build from the morning of the release day. Before the release, DotSIP's Grok connection was changed so that at a goodbye Grok calls end_call without a word and says one farewell after it. The last call on the final build was with a Slovak Grok agent, and its ending was the caller's "Nie, nie, vďaka, to je všetko." and one agent line, "Dovidenia.". I have not called the English agent again since.

The xAI language list does not include Slovak, so DotSIP passes the language only as a hint. It worked on my calls; test your own language on a real call before you rely on it.

So the number, the tool, the opening hours, the prompt and the history stayed where they were through four providers. A different company's model was talking each time, and the only thing I touched between calls was one constant.

Because that choice is made in your code for every call, it does not have to be a constant. The same line can pick the agent by the caller's number, by the hour, or by a flag in your database, which is a cheap way to compare providers on real calls.

The first version of this article had a long chapter about prompts that end a call, with four that failed. 0.2.0 made most of it unnecessary. What is still true:

end_call does. If you point {"ok": true} for it, or the line stays open after the farewell.day parameter said "The weekday the caller asks about". The ElevenLabs agent read "weekday" as Monday to Friday, and this is from that call's history, unchanged:

  Caller: And how about Saturday?
  Agent: I am sorry, I cannot help with that on this line.
  Caller: What?
  Agent: I can only provide information about our opening hours for weekdays. If you have any other questions, feel free to ask!

Gemini and Grok called the tool for Saturday with the same text. With "one day of the week, Monday to Sunday" in the description and every day listed in the parameter, the next ElevenLabs call answered "On Saturday, we are closed." Write the full range of values, and avoid words with a narrower everyday meaning.

What the history or the phone shows What happened What to change
"result": "failed" , start and end in the same second; the call rings and drops The voice session did not start The provider's key, in the place the table above names: has_api_key on the OpenAI models,has_voice_api_key on the other agents
No new call in the history at all The call did not reach DotSIP or the route The registration test from Step 3; inbound_route andincoming_account_ids
The caller asked and there is no check_opening_hours step The tool was not offered The tool's rights must contain the rightroute.php sends (right-1 ), and the agent'stools must list the tool
The agent answers with "I am sorry, I cannot help with that on this line." for a question the tool covers The model read the tool's description as not covering it The description and the parameter, word by word
"result": "ended" , noend_call step The caller had to hang up Your prompt: remove any sentence about goodbyes. If end_call points at your own endpoint and is in the agent'stools , that endpoint must answerok true
"result": "hangup" ,end_call right after the first answer The agent ended the call too early A sentence in the prompt puts a goodbye next to an answer; remove it
The agent talks about the tool instead of using it The parameters or the endpoint address ended up in the prompt They belong to the tool

DotSIP's download contains a folder of rules written for AI coding assistants: the request and answer formats, the order of work, a worked example of this very line, and a page of pitfalls written from real mistakes, mine included. An assistant that reads them can write the two endpoints and send the seven requests for you.

I tried both ways while writing the first version of this article. An assistant that skipped the rules put the OpenAI key in the wrong place, and wrote the goodbye-next-to-an-answer sentence above. Following the rules, the setup worked on the next call.

Both files and a short setup guide: EXAMPLES/ai-reception in the DotSIP examples. The full contract of both endpoints is in the documentation: Writing a route endpoint and Writing a tool endpoint.

The two videos above belong to a series that goes from installing DotSIP to AI voice agents: DotSIP: From Installation to AI Voice Agents.

── more in #ai-agents 4 stories · sorted by recency
── more on @dotsip 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/a-real-phone-number-…] indexed:0 read:20min 2026-12-01 · —