agent_id, branch_id, …) set by the step before — so copy them in order.
For an overview of the API families, see the API overview. This page uses the Agents API to build and ship, and the Debug Chat API to test — the same API key and host work for both.
What you’ll build
1. Create
Stand up a new agent with a greeting.
2. Configure
Branch, add a behavior and a knowledge base topic, then merge.
3. Test
Hold a live conversation with it in Sandbox.
4. Deploy
Promote through Pre-release into Live traffic.
5. Observe
Pull back the conversations it has.
Prerequisites
Get access to a PolyAI workspace
You build agents inside a PolyAI workspace, so you need access to one first.
- Enterprise customers — PolyAI provisions your workspace during onboarding; your PolyAI representative sets it up and grants you access. Enterprise workspaces are region-specific (US, UK, or EU).
- Getting started via the website — sign up at poly.ai to create a self-serve workspace, which lives in the Studio region.
Get an API key
Create a workspace-scoped API key from the API Keys tab on your workspace homepage in Agent Studio (see API keys). Copy the value when it’s shown — the full key only appears once. The same key authenticates the Agents API and the Data API’s debug chat — everything through step 4 of this guide.
- Step 5 (pulling call data back out) uses the Conversations v3 API, which needs a separate project-scoped key. The Chat API needs its own connector token too. Request either only once you’re integrating a real channel or data pipeline — you don’t need them for steps 1–4.
Find your account ID
Open Agent Studio. Your account ID is the first path segment in the URL:For example,
https://studio.uk.poly.ai/acme-uk/acme-team-4/agent → account_id=acme-uk.“Account ID” and “Workspace ID” are the same thing. Agent Studio’s UI calls this the Workspace ID and shows it in a prefixed form (
ws-xxxxxxxx). The API parameter is named accountId (Agents and Data APIs) or account_id (Conversations, Chat, Webhooks, and most other APIs) — same value, different casing convention depending on which API family you’re calling. Both the slug form from the URL (acme-uk) and the prefixed form (ws-xxxxxxxx) work in API calls.Pick the right base URL
The Agents and Data APIs — everything in steps 1–4 of this guide — share one regional host family:
| Region | Base URL |
|---|---|
| US | https://api.us.poly.ai |
| UK | https://api.uk.poly.ai |
| EU | https://api.eu.poly.ai |
| Studio | https://api.studio.poly.ai |
Step 1: Create an agent
agentId — every remaining call in this guide uses it. The agent starts with one branch, main.
Step 2: Configure it
You can’t editmain directly — the API rejects writes to it with 422 Cannot directly update main branch. Instead, create a working branch, make your edits there, then merge it back into main. This is the same branch-and-merge model Agent Studio and Studio Assistant use.
Create a working branch:
Set the behavior
The behavior is the system prompt that governs how the agent responds.Add a knowledge base topic
Topics are what the agent draws on to answer questions — each one pairs content with example queries that should trigger it.actions and isActive.
Merge the branch into main
Merging applies the branch’s edits to main and publishes them to Sandbox in one step — there’s no separate publish call.
Step 3: Test it
Your merge in step 2 already published to Sandbox, so the agent is live there and ready to talk. Hold a test conversation using the Debug Chat API — it authenticates with the same key and host as the Agents API, so there’s no extra credential to request.Edits reach an environment only when you merge or promote into it. If debug chat replies with stale behavior, you edited the branch but haven’t merged it to
main. Merge again to push the change into Sandbox.metadata has more fields than shown — trimmed here for readability. The conversationId is an AS_CHAT_… string; the curl examples below hard-code the one from this response — swap in your own.)
Send a message — try the knowledge base topic you just added:
metadata.retrievedTopics — it lists the knowledge base topics the agent pulled in (["Password reset"] here), a more reliable signal than scanning the reply text for acme.com/reset. Keep sending messages against the same conversationId to continue the conversation, matching clientEnv to whichever environment you’re checking.
Building a real webchat, SMS, or in-app integration instead of a one-off test? Use the Chat API — it’s built for driving conversations from an end-user-facing client and requires its own connector token.
Step 4: Deploy it
Sandbox is for testing, not customer traffic. Promote the Sandbox deployment through Pre-release and into Live — that’s what real callers hit. See Environments for the full model. Promotion works on a deployment ID, and the merge in step 2 didn’t return one — so fetch the active Sandbox deployment first:deployment.id for the target environment — feed that into the next call:
targetEnvironment and the promote defaults to the next stage in sequence (sandbox → pre-release → live). A Sandbox deployment can also promote straight to live — going through Pre-release first is a safety choice, not an API requirement.
Made a mistake? Roll back to the previous deployment in any environment.
Step 5: Work with the calls it takes
Once your agent is live (or you’ve made test calls), pull the data back with the Conversations API. This uses a different host and a project-scoped key — see prerequisites above.The
project_id this API expects is the same value as the agentId you’ve used throughout this guide — “Agent” and “Project” are the current and legacy names for the same resource.-1.platform.polyai.app host with its own project-scoped key, so set that key first:
conversations array and a cursor for pagination. Fetch one by ID to get its full turn-by-turn transcript:
Download call audio
Voice calls have a recording available on a separate binary endpoint.
Subscribe to webhooks
Get a signed POST when a call completes instead of polling for it.
Clean up
Built this agent just to try the API? Delete it when you’re done — this removes the agent along with all its branches and deployments, and can’t be undone.204 No Content.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
401 Unauthorized | Missing or wrong x-api-key, or a key from the wrong region. | Confirm the key was issued for the region in your base URL — see region mismatches. |
403 Forbidden | Key lacks permission for this account or agent. | Confirm the key was provisioned for the account ID / agent ID you’re using. |
400 on create agent | Missing responseSettings.greeting, which is required. | Include a non-empty greeting — it’s the agent’s opening line. |
422 Cannot directly update main branch | You sent a behavior or knowledge base write to branches/main. | Create a working branch, make edits on it, then merge to main — see step 2. main is read-only. |
| Debug chat replies with the old behavior/topic | You edited a branch but haven’t merged it into main yet. | Merge the branch again — edits reach Sandbox only once they’re merged into main. |
404 on debug-chat message | Wrong or expired conversationId. | Start a new session with POST /debug-chat and use the returned conversationId. |
409 Deployments already published | You called publish after a merge, which already deployed to Sandbox. | Skip the explicit publish — merging a branch publishes to Sandbox for you. Move on to promote. |
404 on promote | Wrong deploymentId. | Use the deployment.id from the most recent publish/promote response, not an old one. |
400 on promote | targetEnvironment isn’t a later stage than the deployment’s current one. | Sandbox can promote to pre-release or live; pre-release can only promote to live. |
404 on Conversations endpoint (step 5) | Wrong base URL — usually the build host (api.us.poly.ai) instead of the platform host. | Conversations v3 uses api.{region}-1.platform.polyai.app, with the -1 suffix. |
Empty conversations array | No calls yet in the time window, or wrong client_env. | Place a test call via debug chat, widen the window, or try client_env=sandbox. |
429 Too Many Requests | Rate limit hit. | Back off per the Retry-After header; use cursor pagination for large pulls. |
Next steps
Agents API
Branches, telephony, real-time configs, and variants for multi-site agents.
Chat API
Wire a real webchat, web SDK, or SMS integration into a live conversation.
Conversations API
Full schema, pagination, and retrieval modes for call data.
Webhooks API
Event types, retries, and signature verification.
Outbound Calling API
Have your new agent place a real call out — needs outbound enabled on the project first.
WebRTC Gateway
Talk to your agent by voice from a browser tab instead of typing.

