Authenticating a voice agent's tool calls in a multi-tenant app
in LLM security
Once your voice agent acts on your app's data, you have to decide who is calling, which team's data they may touch and what the model gets to see.
- What are we wiring together?
- Which tools does the agent get, and what do they return?
- Why does every tool call carry two credentials?
- How does the app keep each team's plays apart?
- What did only a live call turn up?
- What is still open?
- Summary
A voice agent that only talks is easy; the trouble starts when it acts on your data. Your app now takes calls from a vendor's servers, through a public URL, on behalf of a person who never logged in to that URL. The model in the middle reads every tool result and can be talked into things. The running example: a football coach says "draw spread right hash, field mills, boundary smash".
The build process (six agent lanes, review gates, cost) has its own post: End-to-end testing a multi-agent build. This one is about the wiring.
What are we wiring together?
A coaching app's playbook, and an ElevenAgents voice agent that can search it and draw new plays. ElevenAgents is
ElevenLabs' agent product; its API paths still start with /v1/convai.
The accent arrow is the drawing, which the browser fetches itself.
The app is FastAPI and Next.js, with Postgres and Redis. Plays are structured data, and a deterministic drawer turns a
spoken play call into an SVG. The agent runs claude-haiku-4-5 at temperature 0, picked for turn
speed. Its speech recognition gets 19 football terms as keywords, and a call is capped at 600 seconds.
ElevenLabs reaches the app's tools through an ngrok tunnel. The tool URL holds an environment variable,
https://{{system_, so no host is committed.
The agent's config lives in the repo as files (elevenlabs/agent_, tool_, test_), pushed
with the ElevenLabs CLI and pinned by tests that need no network.
You need an ElevenLabs account with ElevenAgents, an app with a login, and a public URL for it. The app's own header, variable and audience names are shortened here.
Which tools does the agent get, and what do they return?
Five tools: three server tools that call the app, and two client tools that run in the coach's browser. The model gets ids and short text. It never gets a drawing.
| Tool | Kind | Takes | Returns |
|---|---|---|---|
search_ |
server, GET | q, 1 to 100 characters |
up to 20 plays: id, name, formation, up to 5 variants |
get_ |
server, GET | play id | the same fields for one play |
draw_ |
server, POST | call, up to 500 characters |
status and a draw_, or notes |
show_ |
client | play id, optional hash |
the browser draws the saved play |
show_ |
client | draw_ |
the browser draws the new play |
The model gets no SVG: kilobytes of path data would slow every turn, cost tokens, and let the model change what the
drawer drew. So draw_ puts its result in Redis under voice:draw:{team_
for 900 seconds and returns only the id. The agent then calls show_, and the browser fetches the drawing from
GET /api/v1/voice/draws/{draw_ with the coach's normal session. A test helper, assert_, runs on every
/voice-tools response in the suite.
Each text field is capped at 200 characters. Drawer notes and saved play text are filtered before the agent sees them:
anything that reads like an instruction becomes [withheld]. A play name is team data, and team data can hold a prompt
injection.
draw_ returns one of five statuses, and the prompt says what to say for each:
drawn: callshow_with the id.draw unresolved: turn the drawer's question into one short question to the coach. "Never repeat a note verbatim."rate_,limited timeout,unavailable: say so plainly.
Two timeouts matter. The drawer's server deadline is 35 seconds, so the draw_ tool waits 40. The prompt has the
agent say "Drawing that now" before it calls the tool, so the coach hears something during the draw. In the rehearsal
the draw took 2.5 seconds at the median, so the tool stayed synchronous rather than async.
My judgement: start every voice tool from "what is the smallest thing the model needs to say the next sentence?" For a drawing, that is an id.
Why does every tool call carry two credentials?
Because a server-tool call from ElevenLabs carries no signature we could find in the docs or the SDK types, so anyone with the tunnel URL can call it. So each call must prove two things: it comes from our ElevenLabs workspace, and it acts for one coach's session.
- The workspace secret proves the first. It is a random 32-byte hex string stored as an ElevenLabs workspace secret
and sent as
X-Tool-Secret. The app compares it in constant time. - The voice token proves the second. When the coach presses "Start call", the browser calls
POST /api/v1/voice/sessionwith its normal login. The app mints a JWT (HS256, audiencevoice-tools, subject the team id, scopesplays:readandplays:draw) that lives at most 900 seconds. It also mints the ElevenLabs conversation token and binds that conversation to the team in Redis.
The model sees neither. The browser hands the voice token to ElevenLabs as a dynamic variable named
secret_. ElevenLabs' docs say secret_ variables go only into tool headers, are never sent to the
LLM, and are redacted in webhooks. The workspace secret is referenced by id. Here is the header block every server
tool carries:
"request_headers": {
"Authorization": { "variable_name": "secret__voice_token" },
"X-Tool-Secret": { "secret_id": "<workspace secret id>" }
}
- The coach starts a call. The app checks their normal login and mints a voice token (at most 900 s) and an ElevenLabs conversation token.
- The browser starts the session and passes the voice token as a
secret__variable. - The agent calls
draw_play. ElevenLabs fills in two headers: the workspace secret and the voice token. - The app checks both. If either fails, it answers 401 before any SQL runs.
- If both pass,
draw_playruns as the token's team under row-level security and returns a draw id, never SVG. - The agent calls
show_draw, a client tool, and the browser fetches the drawing with the coach's own session.
Dashed arrows are messages. The search tools follow the same path.
On the app side, one FastAPI dependency, require_, checks the secret, then the Bearer token. Any
failure is a bare 401 before any SQL runs. A valid token without the route's scope gets 403. The suite tries eight ways
in:
tampered_sub minted_16_min_ago missing_tool_secret wrong_tool_secret
aud_other alg_none missing_bearer not_bearer_scheme
Only after both checks pass does the per-team limit run: 60 tool calls a minute, refusing with 503 when Redis is down. So a forged call is refused before it can spend a real team's budget.
Warning: the weak spot is the config file. A header written as a plain string is sent literally, and a
secret written as a name never resolves. Two static tests read every tool config and fail on either:
test_ and test_. A third
fails if anything shaped like a secret, or the tunnel host, appears in a config file.
The post-call webhook, which meters minutes, is the one ElevenLabs does sign: elevenlabs-signature: t=<unix>,v0=<hex>,
an HMAC-SHA256 of {t}.{raw_. The app takes the team from the conversation it bound at session start, never from
the payload.
How does the app keep each team's plays apart?
With Postgres row-level security (RLS), where the database decides which rows a request sees. The tool code sets the team from the token and then runs queries that name no team at all.
The last line of require_ is await set_. That runs:
SELECT set_config('app.tenant_id', :team_id, true);
The true makes the setting last only to the end of the transaction, like SET LOCAL, but it takes a bound parameter.
Every team table has the same policy:
CREATE POLICY tenant_isolation ON saved_plays
USING (team_id::text = current_setting('app.tenant_id', true))
WITH CHECK (team_id::text = current_setting('app.tenant_id', true));
(The real policy also checks an audited bypass switch; it is left out here.)
Two settings make this hold. The tables use FORCE ROW LEVEL SECURITY, so the owner is bound too. The app connects as
playbook_, a role with NOSUPERUSER NOBYPASSRLS, because a superuser skips RLS whatever FORCE says. Migrations
run as a separate superuser.
get_ has no team_ filter, on purpose. If RLS breaks, the tests see it instead of a filter hiding it. Three
tests pin the boundary:
test_: team B's play id looks exactly like a made-up one.get_ play_ of_ another_ team_ is_ the_ same_ 404_ as_ an_ unknown_ id test_.search_ never_ returns_ another_ teams_ play test_: the team comes from the token only.team_ id_ query_ param_ cannot_ choose_ the_ tenant
What did only a live call turn up?
Six facts about the platform and two bugs of ours, none of which a test could have caught. Every test was green
before the first live call on 2026-10-13: a 175-second session, search_ answering in 0.28 seconds on average.
| Symptom | Cause | Fix |
|---|---|---|
| The token header arrived as literal text | {{var}} isn't filled in inside a plain-string header |
the typed form {"variable_, whose value is the whole header; the browser passes Bearer <token> |
| The secret header never resolved | a workspace secret resolves by id; the name is stored but never resolves | reference it by secret_ |
CLI tools push (v1.4.0) crashed after creating the tools, before writing their ids back |
a CLI bug; a second push makes duplicates | update tools with PATCH /v1/convai/tools/{id} |
| Updating the agent failed with 400 | "Reasoning effort is not supported for this LLM" on Haiku | drop reasoning_ |
| The search test could not check the query | the agent-test grader can't address a GET tool's query parameter; body.<field> works |
assert the call, test q in the app's own tests |
| Every tool call returned 404 | ngrok had stopped (ERR_) |
keep the tunnel up; the runbook says so |
| "mills boundary smash" found nothing | ours: search matched the query as one string | every non-filler word must appear, in any order |
| A play asked for on one hash showed the default | ours: show_ ignored the hash |
an optional hash argument |
The first run of the four agent tests went 1 passed, 3 failed. The agent was right each time. The test configs were wrong: the query-parameter paths above, and a grader that held the scripted "Drawing that now." in the chat history against the agent. All four passed after the fix.
The rehearsal that evening gave the numbers. Of 12 draw_ calls, 7 drew. The other 5 used names the team has no
plays for, like Trips, and came back unresolved. The second call was cut at 211 seconds by the account's quota
("This request exceeds your quota limit", code 1002). Server-side tool time:
| Tool | p50 | max | Calls |
|---|---|---|---|
draw_ |
2.5 s | 4.9 s | 12 |
search_ |
0.37 s | 0.54 s | 3 |
show_ / show_ |
0.2 s | 0.22 s | 6 |
The webhook metered 354 seconds for the three calls (13, 130 and 211).
My judgement: make the first live call before building anything deep. Four of the six platform facts sat in config files, and no amount of local testing would have shown them.
What is still open?
- No tool lists formations, so "which formations do we have?" has no answer. It is on the board.
- The live agent test doesn't check the search query, only that the search ran. The app's tests cover
q. draw_calls the app's existing draw handler as a function rather than a shared service. It is marked as debt.play - The public repo is an excerpt. The tool routes, the search and draw queries and the app core stay private.
Summary
- Server tools return ids and short text, and the browser fetches anything heavy with the user's own session.
- Each tool call carries two credentials the model never sees: a workspace secret for "this is our agent" and a short-lived token for "this is that team".
- The team is set once per transaction and Postgres enforces it, so the tool queries name no team.
- Then a live call finds what the config gets wrong.
- Make one live tool call with both headers before writing a second tool. I'd do this first.
- Add the two static header tests to your agent config's test suite.
- Run the app as a role without
BYPASSRLS, and test that another team's id gets the same 404 as a made-up one.