Agent Provisioning API
Overview
Section titled “Overview”The Agent Provisioning API is a programmatic, non-browser way to create, list, get, and delete agents. It’s a separate surface from the rest of Pinchy’s REST API: instead of a session cookie, every request is authenticated with an API key.
It’s built for scripts, CI/CD pipelines, and infrastructure-as-code — not for the browser. The motivating use case is resetting a demo or staging instance to a known state on every release, without depending on database snapshots that break across schema migrations. The same foundation works for provisioning agents per team or organization as part of a deployment pipeline.
| Session API | Agent Provisioning API | |
|---|---|---|
| Auth | Session cookie, set by logging in through the web UI | API key, sent in a header on every request |
| URL prefix | /api/* |
/api/v1/* |
| Agent visibility | Per-user — GET /api/agents returns what the signed-in user can see |
Org-wide for shared agents — GET /api/v1/agents returns every shared agent; personal agents are always excluded |
| Typical caller | The Pinchy web UI | Scripts, CI/CD, infrastructure-as-code |
Only agent create/list/get/delete are covered by API keys today. Updating an agent and listing templates remain session-only — see the POST /api/v1/agents notes below.
Authentication
Section titled “Authentication”Every request must carry an API key, in either header:
Authorization: Bearer pinchy_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-api-key: pinchy_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxIf both are present, Authorization: Bearer is used. Keys are always prefixed pinchy_, so they’re easy to recognize in logs, shell history, and secret scanners.
A missing key, an unrecognized key, or a key that’s expired, disabled, or revoked all get the same response — 401 Unauthorized. The error never reveals which of those it was:
{ "error": "Unauthorized" }Scopes
Section titled “Scopes”A key can only do what it’s explicitly scoped for — default-deny, the same allow-list principle Pinchy applies everywhere else (see Agent Permissions).
| Scope | Grants |
|---|---|
agents:read |
List agents, get a single agent |
agents:write |
Create agents |
agents:delete |
Delete agents |
agents:delete is deliberately its own scope, separate from agents:write — deletion is irreversible and the highest-impact thing a leaked key could do. A key that only needs to provision agents doesn’t have to also be able to remove them.
A request whose key is missing a required scope gets 403 Forbidden:
{ "error": "Forbidden" }Agents
Section titled “Agents”GET /api/v1/agents
Section titled “GET /api/v1/agents”List the organization’s shared agents. Requires agents:read.
curl https://pinchy.example.com/api/v1/agents \ -H "Authorization: Bearer pinchy_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"Response: 200 OK
{ "agents": [ { "id": "uuid", "name": "HR Policy Assistant", "model": "anthropic/claude-haiku-4-5-20251001", "templateId": "knowledge-base", "allowedTools": ["pinchy_ls", "pinchy_read"], "pluginConfig": { "pinchy-files": { "allowed_paths": ["/data/hr-policies"] } }, "isPersonal": false, "ownerId": null, "createdAt": "2025-01-15T10:00:00.000Z" } ]}The example is abridged — an agent object carries every column the web UI reads, including skills, starterPrompts, tagline, greetingMessage, and visibility. Treat it as the shape, not the field list.
ownerId is null for agents created through this API: a key acts for the organization, so there’s no person to name as the owner. Agents created by an admin in the web UI carry that admin’s id instead.
Unlike the session GET /api/agents, there’s no per-user filtering: restricted agents are returned whether or not the key’s creator shares a group with them. An API key acts for the organization, not for a person, so per-person visibility doesn’t apply to it.
Personal agents are the exception, and they’re never returned. They belong to the individual who owns them, which is a boundary Pinchy holds against everyone — admins included — so a machine credential doesn’t get to cross it either. The same applies to the single-agent and delete endpoints below: a personal agent’s id answers 404, exactly as an unknown id does. If it answered differently, you could probe ids to find out who has a personal agent.
Read-only, so this call is not audited.
POST /api/v1/agents
Section titled “POST /api/v1/agents”Create a new agent from a template. Requires agents:write. The agent inherits its tool permissions from the template; changing them afterward is session-only (PATCH /api/agents/:id in the API Reference) — there’s no key-authenticated update endpoint.
Request body:
| Field | Type | Required | Description |
|---|---|---|---|
name |
string | Yes | Display name for the agent (30 characters max) |
templateId |
string | Yes | Template to use. There’s no key-authenticated template listing yet — discover IDs via the session GET /api/templates. |
tagline |
string | No | Short subtitle shown under the agent name |
pluginConfig |
object | No | Plugin configuration keyed by plugin id, e.g. { "pinchy-files": { "allowed_paths": ["/data/hr"] } }. Required for file-access templates. |
connectionId |
string | No | Integration connection to attach. Required for Odoo and email templates. |
defaultAllowedTools |
string[] | No | Extra tool IDs to allow on creation, merged with the template’s defaults |
curl -X POST https://pinchy.example.com/api/v1/agents \ -H "Authorization: Bearer pinchy_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \ -H "Content-Type: application/json" \ -d '{ "name": "Demo Sales Assistant", "templateId": "custom" }'Response: 201 Created with the created agent — the same object shape as the list above, returned bare (not wrapped in an envelope).
One field can join it. Two things can go wrong after the agent row is committed, and neither of them turns the response into an error — the agent exists either way, so a 4xx would be a lie. Both are reported through the same warning string:
- The runtime apply failed. Pinchy pushes the new configuration to the OpenClaw runtime after committing the row, best-effort.
- The connection could not grant everything the template needs. An Odoo template names the models it requires; the connection’s model catalogue is a snapshot from the last Sync Schema, and its Odoo user has its own access rights. A model the catalogue has never been probed for — or one it has, but may not write — is not granted, and the agent comes out unable to do part of what its template describes.
When both happen, both sentences appear in the one field.
{ "id": "uuid", "name": "Demo Sales Assistant", "warning": "Agent created. Applying it to the runtime failed — check the server logs; it will retry on the next restart or config change."}The field is absent on a clean create, so warning is the whole check. It matters most for the use case this API exists for: a provisioning script that treats 201 as done would create an agent that can’t be chatted with yet, or one that will fail its first Odoo call. Neither is worth retrying the create over — that would give you a second agent. For a runtime-apply failure, log it and re-check; OpenClaw reconciles on its next restart or config change. For an incomplete grant, re-sync the connection’s schema in Settings → Integrations and grant the rest in the agent’s Permissions tab. Both are also recorded in the audit trail as config.changed entries, with action: "runtime_apply_failed" and action: "agent_integration_permissions_incomplete" respectively.
Errors:
-
400— the request body fails schema validation:{"error": "Validation failed","details": {"formErrors": [],"fieldErrors": {"name": ["Invalid input: expected string, received undefined"],"templateId": ["Invalid input: expected string, received undefined"]}}} -
400— the body is well-formed but a template requirement isn’t met (an unknowntemplateId, a file-access template with no directory selected, or an Odoo/email template with noconnectionId):{ "error": "An Odoo connection is required for this template" } -
401— missing or invalid key -
403— key is missing theagents:writescope -
422—template_capability_unavailable: the default provider has no model with the capabilities the template requires:{"error": "template_capability_unavailable","message": "Template requires vision but provider ollama-local has no matching model.","missingCapabilities": ["vision"],"docsUrl": "https://docs.heypinchy.com/guides/ollama-setup#models-for-agent-templates"}
GET /api/v1/agents/:agentId
Section titled “GET /api/v1/agents/:agentId”Get a single agent by ID. Requires agents:read.
curl https://pinchy.example.com/api/v1/agents/<agentId> \ -H "Authorization: Bearer pinchy_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"Response: 200 OK with the agent object, or 404:
{ "error": "Agent not found" }A personal agent’s id also answers 404 here — see GET /api/v1/agents. Read-only, so this call is not audited.
DELETE /api/v1/agents/:agentId
Section titled “DELETE /api/v1/agents/:agentId”Delete a shared agent. Requires agents:delete. Personal agents (auto-created Smithers instances) aren’t reachable through this API at all, so deleting one isn’t possible — the id answers 404, the same as an unknown id.
curl -X DELETE https://pinchy.example.com/api/v1/agents/<agentId> \ -H "Authorization: Bearer pinchy_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"Response: 200 OK
{ "success": true }Errors:
-
401— missing or invalid key -
403— key is missing theagents:deletescope -
404— no such shared agent. Returned both for an id that doesn’t exist and for a personal agent — deliberately indistinguishable, so the response can’t be used to find out which ids are personal agents:{ "error": "Agent not found" }
Managing Keys
Section titled “Managing Keys”Keys are issued and revoked by an admin in Settings → API Keys, in the web UI — there’s no way to manage keys through the Agent Provisioning API itself. A key can provision agents, but it can’t create or revoke other keys, so a leaked key can never be used to escalate itself.
To create a key:
- Open Settings → API Keys and click New API Key.
- Give it a name (up to 32 characters) and pick one or more scopes.
- Optionally set an expiry in days (up to 365) — leave it blank for a key that never expires.
- Click Create.
Afterward, the key list shows its name, first few characters, scopes, who created it, and its dates — never the secret itself.
To revoke a key, click Revoke next to it in the list and confirm. Revocation is immediate: any client still using that key gets 401 Unauthorized on its very next request.
Who owns a key
Section titled “Who owns a key”A key belongs to the organization, not to the admin who created it. Its permissions are the scopes it was issued with, and nothing else — it doesn’t inherit its creator’s admin rights, and it doesn’t lose anything when they change roles.
Concretely: if the admin who created a key leaves, the key keeps working. That’s deliberate. A key exists so automation can run — resetting a staging instance on every release, provisioning agents from a script — and automation shouldn’t break because somebody changed jobs. Any admin can see and revoke any key, so a key is never stranded with a departed colleague either.
This is the same model as a GCP service account key or a Datadog org API key, and it comes with the same catch, which is worth being blunt about.
Offboarding: what to rotate
Section titled “Offboarding: what to rotate”The plaintext key was shown exactly once, to the person who created it. Pinchy has no copy and can’t tell you where theirs ended up — a password manager, a CI secret store, a text file, all three. So when someone leaves, assume they still have every key they created, and decide what that’s worth to you.
The key list has a Created by column for exactly this. It shows who created each key and flags the ones whose creator is no longer active — deactivated, deleted, or demoted from admin:
- Open Settings → API Keys and look for keys flagged No longer active.
- For each one, issue a replacement key with the same scopes, update whatever consumes it, then revoke the old one — in that order, so nothing goes dark in between.
- Keys with no flag are fine. Nothing expires or breaks on its own.
The flag is a prompt, not an alarm: the key is still valid and still doing its job. Only you can judge whether a specific departure warrants a rotation.
Setting an expiry when you create a key puts a ceiling on all of this: an expired key stops working regardless of who is holding it.
Rate limiting
Section titled “Rate limiting”Better Auth’s API key plugin ships a per-key limiter, but its default — 10 requests per 24 hours — would throttle a legitimately busy CI pipeline or provisioning script, so Pinchy turns it off. Better Auth’s own general-purpose rate limiter doesn’t step in either: it guards Better Auth’s router, and /api/v1/* never passes through it — key verification happens through a direct server-side call instead.
Pinchy applies its own limits instead, in-process, per running container:
| Limiter | Bucket | Limit | Response when exceeded |
|---|---|---|---|
| Verified key | the key’s own id | 300 requests / minute | 429 Too Many Requests with Retry-After: 60 |
| Invalid-key attempt | the caller’s IP | 20 attempts / minute | 429 Too Many Requests with Retry-After: 60 |
The per-key limit is deliberately generous — it exists to bound a compromised or malfunctioning key, not to throttle normal automation traffic. The invalid-key limit is deliberately strict: it only ever counts requests that never verified (missing key, malformed key, unknown key, expired/disabled/revoked key), which is the shape of a brute-force or key-guessing attempt, not of legitimate use.
A malformed key — anything not starting with pinchy_, which is every key Pinchy has ever issued — is rejected on the spot, before the hash and database lookup a real verification costs. It still counts against the limit above; it just doesn’t cost us anything to say no. That covers the bulk of what a public endpoint actually receives: scanners spraying other products’ token formats.
{ "error": "Too many requests" }Both limiters are per-container and reset on restart — the same trade-off Pinchy makes everywhere else it rate-limits in-process (see Auditing below for how throttled bursts are recorded). If you run multiple replicas, or want a lower bound before traffic reaches Pinchy at all, put a limiter in front of this API too — a reverse proxy is still the usual place for that.
What the invalid-key limiter assumes
Section titled “What the invalid-key limiter assumes”It reads the caller’s address from the last hop of X-Forwarded-For — the one the proxy directly in front of Pinchy appended, rather than the first, which a client can prefix with any value it likes. That is exactly right for the deployments Pinchy ships, where Caddy terminates the connection and observes the peer itself.
Two consequences worth knowing before you rely on it:
- Expose Pinchy’s port directly and the bucket is caller-chosen. With no proxy in front,
X-Forwarded-Foris whatever the caller wrote, so a determined client picks a fresh bucket per request. Run Pinchy behind the reverse proxy it ships with — the limiter is defense in depth, not a substitute for one at the edge. - Put another proxy in front of Caddy and the bucket collapses. Behind a CDN, the address Caddy observes is the CDN’s, so invalid-key attempts from every client share one budget. Only the invalid-key path is affected — verified keys are bucketed by key id and never touch it.
Pinchy tracks at most 50,000 addresses at a time and reclaims a bucket once its window has elapsed. If a flood ever fills that table, a not-yet-seen address is refused rather than waved through, and already-tracked addresses keep their own budget.
Auditing
Section titled “Auditing”Every provisioning action taken with a key is written to the audit trail. So is key lifecycle when an admin drives it — issuing and revoking a key through Settings → API Keys.
| Event | Actor | When |
|---|---|---|
agent.created |
the API key | POST /api/v1/agents succeeds, or fails with 422 |
agent.deleted |
the API key | DELETE /api/v1/agents/:agentId succeeds |
config.changed |
the API key | POST /api/v1/agents auto-configures an integration connection’s permissions for the agent (action: "agent_integration_permissions_auto_configured"), the connection could not grant everything the template requires (action: "agent_integration_permissions_incomplete", outcome: failure, with missingModels and deniedOperations — the agent is still created, just not fully capable, and the same summary rides on the response’s warning), or the agent was created but couldn’t be applied to the runtime (action: "runtime_apply_failed", outcome: failure — the same condition the warning field reports) |
auth.scope_denied |
the API key | A verified key is missing a required scope (403) — throttled to one row per key per minute |
auth.rate_limited |
the API key, or system for an invalid-key attempt |
A rate limit (429) is hit — the key’s own request budget, or an IP’s invalid-key-attempt budget. detail.reason distinguishes "api_key" from "invalid_api_key". Throttled to one row per key per minute for the former; for the latter, one row per minute in total (see below). |
api_key.created |
the admin | A key is issued in Settings → API Keys |
api_key.deleted |
the admin | A key is revoked in Settings → API Keys |
A denial that lands inside an open one-minute window isn’t dropped, either — the next auth.scope_denied or auth.rate_limited row that does get written carries a suppressedSinceLastEntry count of how many were folded into it, so the trail still shows the volume even though it isn’t writing a row per attempt.
An ordinary invalid-key attempt that never crosses the rate limit stays unaudited — same reasoning as a plain 401: anyone on the internet can present a garbage key, so auditing every one would hand an unauthenticated caller an unbounded write into the audit table. What makes it safe to record a throttled one is the bound, and for this event the bound is one row per minute across the whole endpoint, not one per address. The address is chosen by the caller, so a window keyed on it would grow with every new source and stop bounding anything — the same rule the domain lock’s auth.host_blocked follows. The row that does get written still names the remoteAddress it saw, and suppressedSinceLastEntry reports how many attempts it stands for. The cost is stated plainly: within a minute, a flood from one source can mask a throttle from another.
Actions taken with a key are logged with actorType: "api_key" and the key’s own id as actorId — the key is its own accountable actor, not a stand-in for a person. Each entry’s detail also carries an apiKey: { id, name } snapshot, so the trail still names the key in plain language after the key itself has been revoked and its row is gone.
There’s no delegation field pointing back at the admin who created the key, because the key doesn’t act on their behalf — it belongs to the organization. Attributing a machine’s 3am agent deletion to someone who issued its key eighteen months ago would put a name on an action they had nothing to do with. If you need to know who created the key, that’s recorded once — on the key, in Settings → API Keys, and in its api_key.created entry, which survives the key’s revocation.
Filtering the audit trail by a person, then, won’t surface actions taken by keys they created — correctly, since they didn’t take them. To follow a key’s own trail, filter by its id.
Issuing and revoking keys, by contrast, are admin actions performed through the browser — they’re logged with actorType: "user", never "api_key".
Expiry isn’t one of these lifecycle events. When a key expires, Better Auth deletes its row itself — either the next time the key is used, or during a periodic sweep that runs whenever any key is created — and neither path writes an audit row. There’s nothing at risk in that: the key was already refusing every request from the moment it expired. But it does mean an expired key can disappear from Settings → API Keys with only its api_key.created entry in the trail — there’s no matching api_key.deleted unless an admin revoked it first.
GET requests are read-only and aren’t audited, same as the rest of Pinchy’s API.