Overview
Register agents, write their prompt files, and let a running deployment read them back on every call.
Set up an agent with an AI coding tool
Paste this prompt into Claude Code, Cursor, ChatGPT or another AI coding tool. It writes the setup below for your project, in the order the API needs, and asks before it changes anything.
Read the prompt
Help me set up an agent on Subcore through its Agents API, in this project.
The code should register the agent, store its prompt files, switch it to them, and run a test turn before a real call reaches it. The full reference is at https://subcore.ai/docs/agents if you can read web pages.
## Start by asking
Look at the project first and match it: its language, HTTP client, secrets and scripts. If there is no project here, ask me which language to use.
Then ask me for anything you cannot find; never invent it:
- the agent's slug, display name, timezone and phone numbers
- any prompt variables it should carry
- where its prompt files are, or what they should say
- where my deployment is hosted and its chat credential, if it has one, for the test turn
- whether this is a one-off setup or something the project should do for every new agent
Show me your plan and wait for my go-ahead before any request. Every write changes my live organization.
## The API
The base URL is `https://api.subcore.ai`. Send `Authorization: Bearer <key>` with the key read from the `SUBCORE_API_KEY` environment variable, and `Content-Type: application/json` on writes. Never hard-code, log or commit the key, and treat the deployment's credential the same way.
The key needs the manage-agents permission. An organization admin ticks Manage agents on the key in the Subcore console, under Settings → API keys. A key without it gets `403 FORBIDDEN` on every route here.
- `GET /agents/{slug}` reads one agent. Its `deployment` names the deployment serving it, or is `null`.
- `PUT /agents/{slug}` creates an agent (`201`) or updates it (`200`) and answers `{ "agent": … }`. The body takes only `name`, `instructionSource`, `timezone`, `phoneNumber`, `transferNumber`, `variables`, `deployment`, `model`, `channelOverrides`, `toolsOptIn` and `recordCalls`. Leave the last four out unless I ask.
- `PUT /agents/{slug}/instructions/{path}` writes one prompt file from `{ "content": "…" }`, answering `201` for a new file and `200` for a replaced one. `{path}` is the file's path as the deployment knows it, such as `instructions.md` or `kit/identity.md`.
- `DELETE /agents/{slug}/instructions/{path}` removes a file, and `DELETE /agents/{slug}` removes the agent.
A refusal looks like `{ "error": "…", "code": "…", "timestamp": … }`. Branch on `code`, never on the `error` sentence. The limit is 120 requests a minute per agent and 600 per key.
## Steps, in this order
1. `GET /agents/{slug}`. A `404` means a new agent, or a retired one named after a deployment. Ask me if the slug is a deployment name: a `PUT` revives it.
2. `PUT /agents/{slug}` with the agent's settings, plus `deployment` if I name the deployment serving it. Leave `instructionSource` out, so running the setup again never moves a live agent back. A new agent starts on `repo`, which answers with the deployment's own files. On kit 0.33.0 it has only its locked tools: ask me which others to turn on with `enabledTools` in `channelOverrides`, read only while `toolsOptIn` is `true`. Keep the `routingKey` and `tenantPath` from the answer. A `200` instead of `201` is fine: the deployment may have registered it.
3. `PUT` each prompt file.
4. `PUT /agents/{slug}` with `{ "instructionSource": "database" }`. From the next call on, the stored files are laid over the deployment's own, matched by path. Switching before any file is stored fails with `409 NO_INSTRUCTIONS`.
5. Run the test turn below. Nothing compiles a stored file, so a `201` means it was saved, not that it works.
6. Tell me to point its number at `https://{HOSTNAME}{tenantPath}/incoming-call`, my deployment's `HOSTNAME`. With its own Twilio account, `PUT /agents/{slug}/twilio/webhooks` can do it; ask me first.
Send every request through one helper. On a `429` it waits `Retry-After` seconds, on a `500` a moment, and it retries a few times at most. On any other refusal it stops the setup and shows me the `code`, because the request itself has to change. Every write is a `PUT` keyed by slug and path, so make the setup safe to run twice. Send one agent's writes one at a time.
## Details that are easy to get wrong
- `PUT /agents/{slug}` merges. A field you leave out keeps its value, and `null` clears it, except `instructionSource`, `toolsOptIn` and `recordCalls`, which refuse it. `variables` and `channelOverrides` replace the whole stored map, so always send everything the agent should keep.
- Any other body field is refused with `400 UNKNOWN_FIELD`. That includes `slug`, `routingKey` and snake_case names such as `phone_number`.
- A slug is lowercase letters, digits and hyphens, at most 100 characters. A timezone is an IANA name such as `America/New_York`, never `EST`. Phone numbers are E.164, such as `+15035550142`.
- `409 NUMBER_FROM_TWILIO` means the number comes from the agent's Twilio account. Ask me to keep it or pick one `GET /agents/{slug}/twilio/numbers` lists, set as `phoneNumber` via `PUT /agents/{slug}/twilio/number`. Then resend without it.
- Variables are a flat map of name to string. Names match `[A-Za-z_][A-Za-z0-9_]*` and are at most 64 characters, and the whole map stays within 64 KiB.
- A file path is lowercase letters, digits, `.`, `_`, `/` and `-`, starts with a letter or digit, ends in `.md`, never contains `..`, and is at most 200 characters. The one other name allowed is `entries.json`. A stored one replaces the deployment's whole entry map, so leave it out unless I ask for it.
- Files are stored under the directory `main`. Send another as the `?directory=` query parameter, never in the path, and only if I tell you the deployment defines one.
- Content is at most 256 KiB, stored byte for byte, so do not reformat it.
- Deleting the last file of an agent on `database` is refused with `409 LAST_INSTRUCTION_FILE`. Switch the agent back to `repo` first.
- Never delete anything unless I ask. Deleting an agent also deletes its files, history, telemetry and eval runs, with no undo.
- A `404 NOT_FOUND` for an agent you expected usually means a key from another organization.
## Writing prompt files
A prompt file is markdown, and the model gets the text as written, apart from two things.
- A line holding only `[[path]]` is replaced by that file. The `.md` is optional and paths are lowercase. Write `\[[` to show the brackets.
- A `{{name}}` token has to be declared in the frontmatter of the same file, as `name: resolver.key`. Names are letters, digits and underscores, so `{{a-b}}` is not a token and reaches the model as typed. Write `\{{` to show the braces.
A key starting `tenant.` reads the agent's own variable of that name. The Subcore kit in the deployment also provides `agent.name`, `agent.nameIntro`, `date.today` and `date.now`. Any other key has to exist in the deployment's code, so ask me before using one. Store a variable before the file that binds it. More at https://subcore.ai/docs/agents/prompt-files
## The test turn
`POST {deployment}{tenantPath}/chat/message` with the body `{ "message": "Hi, are you open on Saturday?", "sessionId": null }`, unless the deployment defines its own body. `{deployment}` is the origin I host it at. Send `Authorization: Bearer <credential>` with the deployment's own credential, never `SUBCORE_API_KEY`: its `CHAT_API_SECRET`, or the key starting `sk_dep_` that the Subcore console shows on the deployment's page. For a deployment with neither, leave the header out.
A turn that runs answers `200` and streams one JSON object per line, each with a `type`: `session` first, then `token` lines whose `token` is the next piece of the reply, and one last line that is `finalize`, or `error` with a `message` and `code` if the turn failed partway. A `200` alone does not mean it worked: read to the last line, and treat a stream that ends without either as a failure. Skip any type you do not know, such as `keepalive`.
A turn refused before the stream opens answers with a status and a JSON `error`: `401` for the wrong credential, `404` for an unknown key or a kit before 0.31.0, `503` when the deployment cannot reach Subcore, `409` when the agent lacks a required variable (`required_variables`; `500` on kits 0.24.0 through 0.28.2), and `500` with a `code` naming what failed: `compile` for a file that does not build, `merge`, or `agent_missing`.
## When you are done
Tell me where the code is and how to run it, which environment variables it reads, what you changed in Subcore, including the agent's `routingKey` and `tenantPath`, and anything you could not check.One deployment can answer calls for many agents from a single codebase. This API is how a partner registers each of those agents with Subcore and stores the prompt files it should answer with. The deployment reads that configuration back on every call, so a prompt edit is live on the next one.
There are two surfaces:
| Surface | Who calls it | What it does |
|---|---|---|
/agents | You, from your own tooling | Create or update an agent, list, write or remove its prompt files, connect its own Twilio account, set the outcomes its sessions are named by, and write its eval cases and run them |
/agent-config/{routingKey} | Your deployment, on every call | Returns one agent's settings and files. Authenticated with the deployment's own key |
Base URL: https://api.subcore.ai
Authentication
Every request carries a Subcore API key as a bearer token, the same way the telemetry read API does:
Authorization: Bearer sk_live_...
Content-Type: application/jsonThe key resolves to one organization, and every query is scoped to it. An agent that belongs to another organization gets the same answer as one that does not exist.
The manage-agents permission
The /agents routes need a key whose permissions.manageAgents is exactly
true. You grant it yourself: an organization admin ticks Manage agents on
the key in the Subcore console, under Settings → API keys. No key has it by
default, and a key issued before the permission existed does not gain it, so an
existing key needs the box ticked rather than being replaced. A key without it
authenticates and is then refused:
{
"error": "This API key cannot manage agents: it lacks the manageAgents scope",
"code": "FORBIDDEN",
"timestamp": 1789569967913
}The key your deployment runs with is a different key. It is issued from the deployment's own page in the Subcore console, it reads configuration and sends telemetry, and it never carries the manage-agents permission. See connecting your deployment.
The run-evals permission
Starting and stopping an eval run also needs
permissions.runEvals, exactly true, beside the manage-agents permission. A
run spends your deployment and Subcore's models, so no key gains it by existing:
an organization admin ticks Run evals on the key in the console, in the same
place. Reading runs and writing cases need only the manage-agents permission. A
key without it is refused on a start or a stop:
{
"error": "This API key cannot start or stop eval runs: it lacks the runEvals scope",
"code": "FORBIDDEN",
"timestamp": 1789569967913
}Conventions
Every answer is Cache-Control: no-store. A response body here can be a
prompt, and an edit is live on the next call, so nothing between you and
Subcore may keep a copy.
Every refusal has the same shape, the envelope used across api.subcore.ai.
Switch on code; the sentence in error may change.
{ "error": "No agent with this slug", "code": "NOT_FOUND", "timestamp": 1789569967913 }The full list of codes is under errors.
An agent is a core. The slug here is the same slug the telemetry API
reports as core_slug and filters by as coreSlug, and the same one a key's
permissions.cores names. It is the name you choose, and it appears in every
/agents URL. The routing key is 7 lowercase letters and digits, minted by
Subcore when the agent is created. It is the agent's address on your deployment.
An agent created before 16 October 2026 was given one then, and still answers on
the 32-character key it had before, so nothing that already uses that key has to
change. A deployment needs kit 0.31.0 or later to answer a 7-character key. An
older kit refuses it: a text door answers 404, and a call fails over to the
number's fallback.
What makes a deployment answer for an agent
Which deployment answers a call is decided by two things and no third: the organization the agent was created in, and the address the call arrives on.
From kit 0.31.0, your deployment answers {tenantPath}/… for any routing key it
is given, reads that agent's configuration with its
own deployment key, and serves the call with what comes back. So it answers for
every agent in its own organization whose configuration that key can read.
Creating the agent with the right key is the whole binding, and there is nothing
to switch on afterwards.
A deployment key issued in the console reads all of them. Its cores permission
decides whether it may read agents at all, and reading is on unless someone
turns it off; there is no setting that leaves it some agents and not others.
Turn it off and the config read answers 403 FORBIDDEN for every agent, which
is why a key that reads one agent reads the rest.
An agent can also name one deployment, its
deployment, which is null until
something sets it. That routes nothing. It is the deployment Subcore dials for
the agent: to point its number, to
read what the deployment declares and loaded,
and to run the MCP server's test turns. A new model or voice for the agent has
to be one that deployment
offers. The
agent's Connection tab in the console draws that deployment's doors. Set it
with PUT /agents/{slug}, or let the agent's own traffic set it, from its first
event carrying a build that only one of your deployments ran.
A deployment is not an agent and never appears in /agents. Until now a
deployment's first announcement also created an agent named after it, which answered
the deployment's own bare doors. That agent is now
retired.
An agent still on repo is answered with the deployment's own files, so it
works from the moment it exists, as long as it carries every
variable the deployment requires.
From kit 0.24.0, a deployment refuses an agent that is missing one. Once you
move an agent to database, one more thing has to line up, and it is not a
binding either: the files have to sit under a
directory the deployment serves, or the
call fails at the deployment rather than falling back.
Rate limits
The /agents routes allow 120 requests per minute for each agent, and
600 per minute for the key across all of them. Everything under
/agents/{slug} counts against that agent, its instruction, Twilio, outcome
and eval routes included. Starting an eval run has a budget of its own on top,
10 a minute for each agent per key: see
eval runs. Requests that name no agent, such as GET /agents, share a
budget of 120 of their own. A request refused by one of those budgets is not
counted against the key, so one agent in a retry loop runs out of its own budget
and the key's other agents keep answering. Before a key has authenticated, requests
are counted per client address, at 120 a minute.
Every answer carries the count for whichever budget will run out first:
| Header | Meaning |
|---|---|
X-RateLimit-Limit | Requests allowed in the window |
X-RateLimit-Remaining | Requests left in this window |
Retry-After | Seconds until the window resets. Sent on a 429 only |
Over budget, you get a 429 with code: "RATE_LIMITED" and a scope saying
which budget ran out: agent, other for requests that name no agent, key,
or address. The
config read your deployment makes is not rate
limited, because a refusal there would fail a live call.
Setting up an agent
The order matters. Two guards stop an agent from reading its prompts from the database while it has none stored, so the files go in before the switch.
Create the agent
PUT /agents/{slug} with its name, timezone and phone numbers. A new agent
starts on instructionSource: "repo" and answers with the shared files in
your deployment. If the deployment
requires variables, send
them in this request too, because from kit 0.24.0 it refuses an agent that is
missing one. The answer carries its routingKey and tenantPath. See
agents.
On kit 0.33.0, a new agent has only its locked tools. Turn on the tools it needs
with enabledTools in channelOverrides, or in the console. See
models and tools per agent.
Write its files
PUT /agents/{slug}/instructions/{path} for each prompt file. See
instructions.
Switch it to the database
PUT /agents/{slug} with { "instructionSource": "database" }. From the next
call on, the files you stored are laid over the deployment's own by path: one
you also store replaces it, one it has and you do not is inherited, and one it
has never had is added. Switching before any file is written is refused with
409 NO_INSTRUCTIONS.
In the console, this is Prompt source, set to Stored in Subcore, in the Required card on the Instructions tab.
Test it
Run a text turn through the agent with the files you stored. Nothing on this API
compiles what it stores, so this is where a [[partial]] your deployment does
not have shows up.
POST {deployment}{tenantPath}/chat/message
Authorization: Bearer <your deployment's chat credential>
Content-Type: application/json
{ "message": "Hi, are you open on Saturday?", "sessionId": null }{deployment} is the origin your deployment answers on, scheme included, such
as http://localhost:3000 while it runs locally. The credential is the deployment's own, not the key you called
/agents with: either the CHAT_API_SECRET in its environment, or the key it
minted for itself, which the console shows in the Deployment API key card
on its page and which starts sk_dep_. A deployment with neither answers without a credential.
sessionId: null asks for a new conversation, and the reply names it so you can
send the next turn into the same one. A turn that runs answers 200 and streams
back one JSON object per line, each with a type: a session line first, then
token lines carrying the reply a piece at a time in token, and a last line
that is finalize, or error with a message and a code when the turn fails
partway. So a 200 alone does not mean the turn worked. Read to the last line,
and treat a stream that ends without either as a failure. Skip any other type,
such as the keepalive a quiet turn sends to hold the connection open.
A turn refused before that stream opens answers with a status and a plain
{ "error": …, "code": … } instead, and this is where a file that does not
compile shows up. 401 is the wrong credential. 404 means no agent answers on
that routing key, or the deployment runs a kit before 0.31.0, which refuses a
7-character key, and 404 with code: "routing_key_required" means the
request carried none: from kit 0.31.0 a deployment answers only
{tenantPath}/…, never the bare path. 409 with
code: "required_variables" means the agent is missing a
variable the deployment requires.
A deployment on kit 0.24.0 through 0.28.2 answers that refusal with 500 and
the same code. 500 carries a
code naming what failed, such as compile for a file the deployment could not
build, merge for one it refused, or agent_missing for files stored under a
directory it does not serve. 503 means it could not reach Subcore to read the
configuration at all.
The body above is what the kit accepts unless your deployment defines its own shape, in which case send that one.
Point the number at it
Route the agent's phone number to https://{HOSTNAME}{tenantPath}/incoming-call,
with the deployment's exact HOSTNAME. On any other host, from kit 0.42.0,
every call the deployment checks fails Twilio's signature check.
For an agent with its own Twilio account connected,
PUT /agents/{slug}/twilio/webhooks does this for you.
What is not here
This site documents api.subcore.ai. Your deployment's own doors, such as
{tenantPath}/chat/message and {tenantPath}/incoming-call, belong to the
Subcore kit and are documented with it. The one above is set out here only
because testing an agent you just stored files for needs it. The console's
eval door is set out too, because your project decides
which tools an eval may run for real.
The same goes for the deployment's own code: which resolver keys a
{{variable}} may name, and how to add one, are decisions made there rather
than here. What a stored file may contain is set out on
prompt files.