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.

  1. What are we wiring together?
  2. Which tools does the agent get, and what do they return?
  3. Why does every tool call carry two credentials?
  4. How does the app keep each team's plays apart?
  5. What did only a live call turn up?
  6. What is still open?
  7. 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.

coachbrowser mic voice agentHaiku 4.5 client toolsrun in the browser server toolssecret + token drawingcoach's session playbook API/voice-tools PostgresRLS per team SVG skips the model
Figure 1. The coach, the voice agent and the playbook API, wired together.

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__env_tunnel_host}}/voice-tools/draw, so no host is committed.

The agent's config lives in the repo as files (elevenlabs/agent_configs/, tool_configs/, test_configs/), 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_plays server, GET q, 1 to 100 characters up to 20 plays: id, name, formation, up to 5 variants
get_play server, GET play id the same fields for one play
draw_play server, POST call, up to 500 characters status and a draw_id, or notes
show_play client play id, optional hash the browser draws the saved play
show_draw client draw_id 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_play puts its result in Redis under voice:draw:{team_id}:{draw_id} for 900 seconds and returns only the id. The agent then calls show_draw, and the browser fetches the drawing from GET /api/v1/voice/draws/{draw_id} with the coach's normal session. A test helper, assert_no_svg, 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_play returns one of five statuses, and the prompt says what to say for each:

  • drawn: call show_draw with the id.
  • 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_play 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/session with its normal login. The app mints a JWT (HS256, audience voice-tools, subject the team id, scopes plays:read and plays: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__voice_token. 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>" }
}
Browser Agent App start callcoach's own login startSessiontoken as secret__ var fetch drawingcoach's own session call draw_play2 headers filled in call show_drawa client tool mint tokensvoice JWT, ≤ 900 s ✕ both valid? 401, no SQL draw_playtoken's team, RLS yes no voice + call token dynamic variable secret + Bearer token draw_id, no SVG show_draw(id) GET draw by id 1 1 2 3 4 5 6 6
  1. 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.
  2. The browser starts the session and passes the voice token as a secret__ variable.
  3. The agent calls draw_play. ElevenLabs fills in two headers: the workspace secret and the voice token.
  4. The app checks both. If either fails, it answers 401 before any SQL runs.
  5. If both pass, draw_play runs as the token's team under row-level security and returns a draw id, never SVG.
  6. The agent calls show_draw, a client tool, and the browser fetches the drawing with the coach's own session.
Figure 2. How a draw_play call is checked, from start call to drawing.

Dashed arrows are messages. The search tools follow the same path.

On the app side, one FastAPI dependency, require_voice_tool_tenant, 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_server_tool_carries_both_auth_headers_in_typed_form and test_no_header_anywhere_is_a_plain_string. 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_body}. 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_voice_tool_tenant is await set_tenant(session, claims.team_id). 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_app, a role with NOSUPERUSER NOBYPASSRLS, because a superuser skips RLS whatever FORCE says. Migrations run as a separate superuser.

get_play has no team_id filter, on purpose. If RLS breaks, the tests see it instead of a filter hiding it. Three tests pin the boundary:

  • test_get_play_of_another_team_is_the_same_404_as_an_unknown_id: team B's play id looks exactly like a made-up one.
  • test_search_never_returns_another_teams_play.
  • test_team_id_query_param_cannot_choose_the_tenant: the team comes from the token only.

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_plays 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_name": ...}, 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_id
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_effort
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_NGROK_3200) 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_play 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_play 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_play 2.5 s 4.9 s 12
search_plays 0.37 s 0.54 s 3
show_play / show_draw 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_play calls the app's existing draw handler as a function rather than a shared service. It is marked as debt.
  • 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.
  1. Make one live tool call with both headers before writing a second tool. I'd do this first.
  2. Add the two static header tests to your agent config's test suite.
  3. Run the app as a role without BYPASSRLS, and test that another team's id gets the same 404 as a made-up one.