# Agents reference

> Every Agents endpoint with parameters, request and response fields, required scope and a curl example.

Every Agents endpoint. Base URL `https://api.pingx.ai`; send `Authorization: Bearer <API key>`. Read endpoints need `agents:read` (or `:write`), write endpoints need `agents:write`; the bare `agents` scope grants both. See [Authentication and conventions](https://docs.pingx.ai/authentication.md). Machine-readable: [openapi.json](/openapi.json).

**26 endpoints**

| Method | Path | Operation | Scope |
|---|---|---|---|
| `GET` | `/agents/v1/agents` | ListAgents | read |
| `POST` | `/agents/v1/agents` | CreateAgent | write |
| `DELETE` | `/agents/v1/agents/{agentId}` | DeleteAgent | write |
| `GET` | `/agents/v1/agents/{agentId}` | GetAgent | read |
| `PATCH` | `/agents/v1/agents/{agentId}` | UpdateAgent | write |
| `GET` | `/agents/v1/agents/{agentId}/web-chat` | GetWebChatLink | read |
| `POST` | `/agents/v1/agents/{agentId}/web-chat:disable` | DisableWebChat | write |
| `POST` | `/agents/v1/agents/{agentId}/web-chat:enable` | EnableWebChat | write |
| `POST` | `/agents/v1/chat/conversations` | StartChatConversation | write |
| `POST` | `/agents/v1/chat/conversations/{conversationId}/messages` | SendChatMessage | write |
| `GET` | `/agents/v1/custom-fields` | ListCustomFields | read |
| `POST` | `/agents/v1/custom-fields` | CreateCustomField | write |
| `DELETE` | `/agents/v1/custom-fields/{customFieldId}` | DeleteCustomField | write |
| `PATCH` | `/agents/v1/custom-fields/{customFieldId}` | UpdateCustomField | write |
| `GET` | `/agents/v1/knowledge-bases` | ListKnowledgeBases | read |
| `POST` | `/agents/v1/knowledge-bases` | CreateKnowledgeBase | write |
| `DELETE` | `/agents/v1/knowledge-bases/{knowledgeBaseId}` | DeleteKnowledgeBase | write |
| `GET` | `/agents/v1/knowledge-bases/{knowledgeBaseId}` | GetKnowledgeBase | read |
| `PATCH` | `/agents/v1/knowledge-bases/{knowledgeBaseId}` | UpdateKnowledgeBase | write |
| `GET` | `/agents/v1/knowledge-bases/{knowledgeBaseId}/sources` | ListKnowledgeSources | read |
| `POST` | `/agents/v1/knowledge-bases/{knowledgeBaseId}/sources` | AddKnowledgeSource | write |
| `DELETE` | `/agents/v1/knowledge-sources/{sourceId}` | DeleteKnowledgeSource | write |
| `GET` | `/agents/v1/knowledge-sources/{sourceId}` | GetKnowledgeSource | read |
| `PATCH` | `/agents/v1/knowledge-sources/{sourceId}` | UpdateKnowledgeSource | write |
| `POST` | `/agents/v1/knowledge-sources/{sourceId}:recrawl` | RecrawlKnowledgeSource | write |
| `POST` | `/agents/v1/system-prompts:generate` | GenerateSystemPrompt | write |

## GET /agents/v1/agents

**ListAgents** · needs `agents:read` (or write)

Lists the organization's agents (personas), ordered by id.

**Query parameters**

| Name | Type | Description |
|---|---|---|
| `pageSize` | integer | Maximum agents to return (default 50, max 200). |
| `pageToken` | string | nextPageToken from the previous response; empty for the first page. |

**Response** `ListAgentsResponse`

| Field | Type | Description |
|---|---|---|
| `agents` | Agent[] |  |
| `agents[].id` | string (int64) | Agent id, unique within the platform. |
| `agents[].name` | string | Display name. |
| `agents[].systemPrompt` | string | Identity and context of the agent (who it is, what it represents), shared by chat and calls. Hard compliance rules and retrieved knowledge are added by the platform on top of this and are not part of it. |
| `agents[].knowledgeBaseIds` | string (int64)[] | Ids of the knowledge bases attached to this agent, in prompt order. |
| `agents[].chatInstructions` | string | Behaviour playbook for the text-chat channel (appended after systemPrompt). |
| `agents[].callInstructions` | string | Behaviour playbook for voice calls (appended after systemPrompt). Ignored for calls when script is set. |
| `agents[].script` | string | The organization's own call script (plain text, up to 20,000 characters), used instead of callInstructions on voice calls. Empty when unset. |
| `agents[].fillerWordsEnabled` | boolean | Voice calls only: speak with human-like filler words and self-corrections. |
| `agents[].voiceGender` | string | Voice for calls: "male" or "female". |
| `agents[].supportEscalationEnabled` | boolean | WhatsApp only: gives the agent support-escalation tools. Requires JIRA and Google Chat to be connected in the app. |
| `agents[].backgroundAudioEnabled` | boolean | Voice calls only: play a looped room-ambience bed under the agent's speech. |
| `agents[].backgroundAudioVolume` | string (int64) | Level of that bed as an integer percent, 0-100. |
| `nextPageToken` | string | Pass as pageToken to get the next page; empty on the last page. |

```bash
curl "https://api.pingx.ai/agents/v1/agents" \
  -H "Authorization: Bearer $PINGX_API_KEY"
```

## POST /agents/v1/agents

**CreateAgent** · needs `agents:write`

Creates an agent. Only name, systemPrompt and knowledgeBaseIds can be
set at creation; the other settings start at their defaults (generic chat
and call playbooks, female voice, filler words and background audio off)
and are changed afterwards with UpdateAgent. Not idempotent: each call
creates a new agent. INVALID_ARGUMENT if name is empty or a knowledge base
id is not in the organization.

**Request body** (JSON)

| Field | Type | Description |
|---|---|---|
| `name` | string | Display name (required, non-empty after trimming). |
| `systemPrompt` | string | Identity and context of the agent; may be empty and set later. |
| `knowledgeBaseIds` | string (int64)[] | Knowledge bases to attach, in prompt order; each must exist in the organization. |

**Response** `CreateAgentResponse`

| Field | Type | Description |
|---|---|---|
| `agent` | Agent | The created agent, with defaults filled in. |
| `agent.id` | string (int64) | Agent id, unique within the platform. |
| `agent.name` | string | Display name. |
| `agent.systemPrompt` | string | Identity and context of the agent (who it is, what it represents), shared by chat and calls. Hard compliance rules and retrieved knowledge are added by the platform on top of this and are not part of it. |
| `agent.knowledgeBaseIds` | string (int64)[] | Ids of the knowledge bases attached to this agent, in prompt order. |
| `agent.chatInstructions` | string | Behaviour playbook for the text-chat channel (appended after systemPrompt). |
| `agent.callInstructions` | string | Behaviour playbook for voice calls (appended after systemPrompt). Ignored for calls when script is set. |
| `agent.script` | string | The organization's own call script (plain text, up to 20,000 characters), used instead of callInstructions on voice calls. Empty when unset. |
| `agent.fillerWordsEnabled` | boolean | Voice calls only: speak with human-like filler words and self-corrections. |
| `agent.voiceGender` | string | Voice for calls: "male" or "female". |
| `agent.supportEscalationEnabled` | boolean | WhatsApp only: gives the agent support-escalation tools. Requires JIRA and Google Chat to be connected in the app. |
| `agent.backgroundAudioEnabled` | boolean | Voice calls only: play a looped room-ambience bed under the agent's speech. |
| `agent.backgroundAudioVolume` | string (int64) | Level of that bed as an integer percent, 0-100. |

```bash
curl -X POST "https://api.pingx.ai/agents/v1/agents" \
  -H "Authorization: Bearer $PINGX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name":"…","systemPrompt":"…","knowledgeBaseIds":[]}'
```

## DELETE /agents/v1/agents/{agentId}

**DeleteAgent** · needs `agents:write`

Permanently deletes an agent (any agent, including the organization's last
one). Its web-chat link stops working. Not reversible. NOT_FOUND if the
agent does not exist (so a repeated delete returns NOT_FOUND).

**Path parameters**

| Name | Type | Description |
|---|---|---|
| `agentId` | string (int64) | Id of the agent to delete. |

**Response** `DeleteAgentResponse`

```bash
curl -X DELETE "https://api.pingx.ai/agents/v1/agents/AGENTID" \
  -H "Authorization: Bearer $PINGX_API_KEY"
```

## GET /agents/v1/agents/{agentId}

**GetAgent** · needs `agents:read` (or write)

Returns one agent with its full configuration. NOT_FOUND if the agent does
not exist in the organization.

**Path parameters**

| Name | Type | Description |
|---|---|---|
| `agentId` | string (int64) | Id of the agent to read. |

**Response** `GetAgentResponse`

| Field | Type | Description |
|---|---|---|
| `agent` | Agent | Agent is one saved persona. |
| `agent.id` | string (int64) | Agent id, unique within the platform. |
| `agent.name` | string | Display name. |
| `agent.systemPrompt` | string | Identity and context of the agent (who it is, what it represents), shared by chat and calls. Hard compliance rules and retrieved knowledge are added by the platform on top of this and are not part of it. |
| `agent.knowledgeBaseIds` | string (int64)[] | Ids of the knowledge bases attached to this agent, in prompt order. |
| `agent.chatInstructions` | string | Behaviour playbook for the text-chat channel (appended after systemPrompt). |
| `agent.callInstructions` | string | Behaviour playbook for voice calls (appended after systemPrompt). Ignored for calls when script is set. |
| `agent.script` | string | The organization's own call script (plain text, up to 20,000 characters), used instead of callInstructions on voice calls. Empty when unset. |
| `agent.fillerWordsEnabled` | boolean | Voice calls only: speak with human-like filler words and self-corrections. |
| `agent.voiceGender` | string | Voice for calls: "male" or "female". |
| `agent.supportEscalationEnabled` | boolean | WhatsApp only: gives the agent support-escalation tools. Requires JIRA and Google Chat to be connected in the app. |
| `agent.backgroundAudioEnabled` | boolean | Voice calls only: play a looped room-ambience bed under the agent's speech. |
| `agent.backgroundAudioVolume` | string (int64) | Level of that bed as an integer percent, 0-100. |

```bash
curl "https://api.pingx.ai/agents/v1/agents/AGENTID" \
  -H "Authorization: Bearer $PINGX_API_KEY"
```

## PATCH /agents/v1/agents/{agentId}

**UpdateAgent** · needs `agents:write`

Partially updates an agent: only the fields present in the request change;
omitted fields keep their stored value. Idempotent. The script, when
changed, is normalized by an AI pass before saving (can take up to a few
minutes) and the processed text is what is stored. ABORTED if the script
was changed by another save while this one was being processed (re-read
and retry). FAILED_PRECONDITION when enabling supportEscalationEnabled
without JIRA and Google Chat connected in the app. NOT_FOUND for an
unknown agent.

**Path parameters**

| Name | Type | Description |
|---|---|---|
| `agentId` | string (int64) | Id of the agent to update. |

**Request body** (JSON)

| Field | Type | Description |
|---|---|---|
| `name` | string | New display name; must be non-empty when provided. |
| `systemPrompt` | string | New system prompt. |
| `chatInstructions` | string | New chat playbook. |
| `callInstructions` | string | New call playbook. |
| `script` | string | New call script, up to 20,000 characters (an empty string clears it). Processed by an AI normalization pass before saving. |
| `fillerWordsEnabled` | boolean | Toggle filler words on voice calls. |
| `voiceGender` | string | "male" or "female"; any other value is stored as "female". |
| `supportEscalationEnabled` | boolean | Toggle support escalation (see Agent.supportEscalationEnabled). |
| `backgroundAudioEnabled` | boolean | Toggle the call background-audio bed. |
| `backgroundAudioVolume` | string (int64) | Background-audio level percent, 0-100 (INVALID_ARGUMENT above 100). |
| `knowledgeBaseIds` | KnowledgeBaseIds | When provided, REPLACES the attached knowledge bases with this ordered list (an empty list detaches all). Omit to keep the current attachments. |
| `knowledgeBaseIds.ids` | string (int64)[] |  |

**Response** `UpdateAgentResponse`

| Field | Type | Description |
|---|---|---|
| `agent` | Agent | The agent after the update. |
| `agent.id` | string (int64) | Agent id, unique within the platform. |
| `agent.name` | string | Display name. |
| `agent.systemPrompt` | string | Identity and context of the agent (who it is, what it represents), shared by chat and calls. Hard compliance rules and retrieved knowledge are added by the platform on top of this and are not part of it. |
| `agent.knowledgeBaseIds` | string (int64)[] | Ids of the knowledge bases attached to this agent, in prompt order. |
| `agent.chatInstructions` | string | Behaviour playbook for the text-chat channel (appended after systemPrompt). |
| `agent.callInstructions` | string | Behaviour playbook for voice calls (appended after systemPrompt). Ignored for calls when script is set. |
| `agent.script` | string | The organization's own call script (plain text, up to 20,000 characters), used instead of callInstructions on voice calls. Empty when unset. |
| `agent.fillerWordsEnabled` | boolean | Voice calls only: speak with human-like filler words and self-corrections. |
| `agent.voiceGender` | string | Voice for calls: "male" or "female". |
| `agent.supportEscalationEnabled` | boolean | WhatsApp only: gives the agent support-escalation tools. Requires JIRA and Google Chat to be connected in the app. |
| `agent.backgroundAudioEnabled` | boolean | Voice calls only: play a looped room-ambience bed under the agent's speech. |
| `agent.backgroundAudioVolume` | string (int64) | Level of that bed as an integer percent, 0-100. |

```bash
curl -X PATCH "https://api.pingx.ai/agents/v1/agents/AGENTID" \
  -H "Authorization: Bearer $PINGX_API_KEY" \
  -H "Content-Type: application/json" \
  -d @body.json
```

## GET /agents/v1/agents/{agentId}/web-chat

**GetWebChatLink** · needs `agents:read` (or write)

Returns whether the agent's web-chat link is enabled and its token. The
token is a bearer capability to chat with the agent publicly: treat it as
sensitive. NOT_FOUND for an unknown agent.

**Path parameters**

| Name | Type | Description |
|---|---|---|
| `agentId` | string (int64) | Id of the agent. |

**Response** `GetWebChatLinkResponse`

| Field | Type | Description |
|---|---|---|
| `link` | WebChatLink | WebChatLink is the web-chat share-link state of one agent. |
| `link.agentId` | string (int64) | The agent the link belongs to. |
| `link.enabled` | boolean | Whether the public chat page is currently enabled. |
| `link.token` | string | Opaque link token addressing the public chat page; empty when disabled. |

```bash
curl "https://api.pingx.ai/agents/v1/agents/AGENTID/web-chat" \
  -H "Authorization: Bearer $PINGX_API_KEY"
```

## POST /agents/v1/agents/{agentId}/web-chat:disable

**DisableWebChat** · needs `agents:write`

Revokes the agent's web-chat link immediately; the old token never works
again (re-enabling mints a new one). Idempotent: succeeds when no link is
active. NOT_FOUND for an unknown agent.

**Path parameters**

| Name | Type | Description |
|---|---|---|
| `agentId` | string (int64) | Id of the agent. |

**Response** `DisableWebChatResponse`

```bash
curl -X POST "https://api.pingx.ai/agents/v1/agents/AGENTID/web-chat:disable" \
  -H "Authorization: Bearer $PINGX_API_KEY"
```

## POST /agents/v1/agents/{agentId}/web-chat:enable

**EnableWebChat** · needs `agents:write`

Enables the agent's public web-chat page and returns its link token.
Idempotent: while a link is active the same token is returned; a new token
is minted only after DisableWebChat. NOT_FOUND for an unknown agent.

**Path parameters**

| Name | Type | Description |
|---|---|---|
| `agentId` | string (int64) | Id of the agent. |

**Response** `EnableWebChatResponse`

| Field | Type | Description |
|---|---|---|
| `link` | WebChatLink | WebChatLink is the web-chat share-link state of one agent. |
| `link.agentId` | string (int64) | The agent the link belongs to. |
| `link.enabled` | boolean | Whether the public chat page is currently enabled. |
| `link.token` | string | Opaque link token addressing the public chat page; empty when disabled. |

```bash
curl -X POST "https://api.pingx.ai/agents/v1/agents/AGENTID/web-chat:enable" \
  -H "Authorization: Bearer $PINGX_API_KEY"
```

## POST /agents/v1/chat/conversations

**StartChatConversation** · needs `agents:write`

Starts a text conversation with an agent and returns its id; send turns
with SendChatMessage. The server keeps the history. Not idempotent.
NOT_FOUND for an unknown agent.

**Request body** (JSON)

| Field | Type | Description |
|---|---|---|
| `agentId` | string (int64) | Id of the agent to talk to. |

**Response** `StartChatConversationResponse`

| Field | Type | Description |
|---|---|---|
| `conversationId` | string (int64) | Id to pass to SendChatMessage. |

```bash
curl -X POST "https://api.pingx.ai/agents/v1/chat/conversations" \
  -H "Authorization: Bearer $PINGX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"agentId":"…"}'
```

## POST /agents/v1/chat/conversations/{conversationId}/messages

**SendChatMessage** · needs `agents:write`

Sends one user message and returns the agent's complete reply (the
request/response form of the streaming the app chat; the reply is
assembled server-side). Can take tens of seconds. Not idempotent: each
call appends a turn. NOT_FOUND if the conversation does not belong to the
organization; UNAVAILABLE if the assistant is temporarily unavailable.

**Path parameters**

| Name | Type | Description |
|---|---|---|
| `conversationId` | string (int64) | Conversation id from StartChatConversation. |

**Request body** (JSON)

| Field | Type | Description |
|---|---|---|
| `text` | string | The user's message (required, non-empty after trimming). |

**Response** `pingxAgentsV1SendChatMessageResponse`

| Field | Type | Description |
|---|---|---|
| `segments` | string[] | The reply as separate chat bubbles in order (a turn that searches the knowledge base mid-answer yields an acknowledgment bubble, then the grounded answer). |
| `text` | string | All segments joined with a blank line: the whole reply as one text. |
| `citations` | ChatCitation[] | Knowledge passages that grounded the reply, if any. |
| `citations[].knowledgeBaseName` | string | Knowledge base name. |
| `citations[].title` | string | Source title. |
| `citations[].url` | string | Source URL, when it has one. |
| `messageId` | string (int64) | Id of the stored assistant message. |

```bash
curl -X POST "https://api.pingx.ai/agents/v1/chat/conversations/CONVERSATIONID/messages" \
  -H "Authorization: Bearer $PINGX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text":"…"}'
```

## GET /agents/v1/custom-fields

**ListCustomFields** · needs `agents:read` (or write)

Lists custom fields visible for a scope (see ListCustomFieldsRequest),
default-scope fields first, then the scope's own, by position.

**Query parameters**

| Name | Type | Description |
|---|---|---|
| `scopeType` | string | "default" returns only the org-wide fields; "agent" (with agentId) returns org-wide plus that agent's own; "human_operators" returns org-wide plus the shared operator set. Required. |
| `agentId` | string (int64) | Required when scopeType is "agent". |
| `pageSize` | integer | Maximum fields to return (default 50, max 200). |
| `pageToken` | string | nextPageToken from the previous response; empty for the first page. |

**Response** `ListCustomFieldsResponse`

| Field | Type | Description |
|---|---|---|
| `fields` | CustomField[] | Org-wide fields first, then the scope's own, by position. |
| `fields[].id` | string (int64) | Custom field id. |
| `fields[].scopeType` | string | "default" (org-wide), "agent" (one agent, see agentId) or "human_operators" (shared by human operators). |
| `fields[].agentId` | string (int64) | The agent, for scopeType "agent"; 0 otherwise. |
| `fields[].key` | string | Stable machine key (immutable), unique across scopes. |
| `fields[].label` | string | Display label. |
| `fields[].description` | string | What to measure and how to score it; guides the AI extraction. |
| `fields[].minValue` | integer | Lowest score. |
| `fields[].maxValue` | integer | Highest score (greater than minValue). |
| `fields[].position` | integer | Display order within its scope. |
| `nextPageToken` | string | Pass as pageToken to get the next page; empty on the last page. |

```bash
curl "https://api.pingx.ai/agents/v1/custom-fields" \
  -H "Authorization: Bearer $PINGX_API_KEY"
```

## POST /agents/v1/custom-fields

**CreateCustomField** · needs `agents:write`

Creates a custom field. The key is immutable afterwards and must be unique
across scope classes. INVALID_ARGUMENT for a bad scope, empty
key/label/description, minValue >= maxValue, or a key already in use;
NOT_FOUND for an unknown agentId.

**Request body** (JSON)

| Field | Type | Description |
|---|---|---|
| `scopeType` | string | "default", "agent" or "human_operators". Required. |
| `agentId` | string (int64) | Required (and must belong to the organization) when scopeType is "agent". |
| `key` | string | Machine key, required, unique across the organization's scopes; immutable. |
| `label` | string | Display label, required. |
| `description` | string | What to measure and how to score it, required. |
| `minValue` | integer | Lowest score. |
| `maxValue` | integer | Highest score; must be greater than minValue. |
| `position` | integer | Display order within the scope. |

**Response** `CreateCustomFieldResponse`

| Field | Type | Description |
|---|---|---|
| `field` | CustomField | CustomField is a business-defined metric scored from each conversation (for example "Sentiment", 1-5). |
| `field.id` | string (int64) | Custom field id. |
| `field.scopeType` | string | "default" (org-wide), "agent" (one agent, see agentId) or "human_operators" (shared by human operators). |
| `field.agentId` | string (int64) | The agent, for scopeType "agent"; 0 otherwise. |
| `field.key` | string | Stable machine key (immutable), unique across scopes. |
| `field.label` | string | Display label. |
| `field.description` | string | What to measure and how to score it; guides the AI extraction. |
| `field.minValue` | integer | Lowest score. |
| `field.maxValue` | integer | Highest score (greater than minValue). |
| `field.position` | integer | Display order within its scope. |

```bash
curl -X POST "https://api.pingx.ai/agents/v1/custom-fields" \
  -H "Authorization: Bearer $PINGX_API_KEY" \
  -H "Content-Type: application/json" \
  -d @body.json
```

## DELETE /agents/v1/custom-fields/{customFieldId}

**DeleteCustomField** · needs `agents:write`

Deletes a custom field (stored historical values are left untouched).
NOT_FOUND if unknown.

**Path parameters**

| Name | Type | Description |
|---|---|---|
| `customFieldId` | string (int64) | Id of the custom field to delete. |

**Response** `DeleteCustomFieldResponse`

```bash
curl -X DELETE "https://api.pingx.ai/agents/v1/custom-fields/CUSTOMFIELDID" \
  -H "Authorization: Bearer $PINGX_API_KEY"
```

## PATCH /agents/v1/custom-fields/{customFieldId}

**UpdateCustomField** · needs `agents:write`

Partially updates a custom field's label, description, range or position;
omitted fields keep their value. scope, agent and key cannot change.
Idempotent. NOT_FOUND if unknown.

**Path parameters**

| Name | Type | Description |
|---|---|---|
| `customFieldId` | string (int64) | Id of the custom field to update. |

**Request body** (JSON)

| Field | Type | Description |
|---|---|---|
| `label` | string | New label (non-empty). |
| `description` | string | New description (non-empty). |
| `minValue` | integer | New lowest score. |
| `maxValue` | integer | New highest score; the resulting range must satisfy minValue < maxValue. |
| `position` | integer | New display order. |

**Response** `UpdateCustomFieldResponse`

| Field | Type | Description |
|---|---|---|
| `field` | CustomField | CustomField is a business-defined metric scored from each conversation (for example "Sentiment", 1-5). |
| `field.id` | string (int64) | Custom field id. |
| `field.scopeType` | string | "default" (org-wide), "agent" (one agent, see agentId) or "human_operators" (shared by human operators). |
| `field.agentId` | string (int64) | The agent, for scopeType "agent"; 0 otherwise. |
| `field.key` | string | Stable machine key (immutable), unique across scopes. |
| `field.label` | string | Display label. |
| `field.description` | string | What to measure and how to score it; guides the AI extraction. |
| `field.minValue` | integer | Lowest score. |
| `field.maxValue` | integer | Highest score (greater than minValue). |
| `field.position` | integer | Display order within its scope. |

```bash
curl -X PATCH "https://api.pingx.ai/agents/v1/custom-fields/CUSTOMFIELDID" \
  -H "Authorization: Bearer $PINGX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"label":"…","description":"…","minValue":0,"maxValue":0,"position":0}'
```

## GET /agents/v1/knowledge-bases

**ListKnowledgeBases** · needs `agents:read` (or write)

Lists the organization's knowledge bases (without their sources: use
GetKnowledgeBase or ListKnowledgeSources for those), ordered by id.

**Query parameters**

| Name | Type | Description |
|---|---|---|
| `pageSize` | integer | Maximum knowledge bases to return (default 50, max 200). |
| `pageToken` | string | nextPageToken from the previous response; empty for the first page. |

**Response** `ListKnowledgeBasesResponse`

| Field | Type | Description |
|---|---|---|
| `knowledgeBases` | KnowledgeBase[] | Knowledge bases without their sources. |
| `knowledgeBases[].id` | string (int64) | Knowledge base id. |
| `knowledgeBases[].name` | string | Display name. |
| `knowledgeBases[].sourceCount` | integer | Number of sources in the knowledge base. |
| `knowledgeBases[].sources` | KnowledgeSource[] | The sources. Populated only by GetKnowledgeBase and by the create/update RPCs' responses; empty in ListKnowledgeBases. |
| `nextPageToken` | string | Pass as pageToken to get the next page; empty on the last page. |

```bash
curl "https://api.pingx.ai/agents/v1/knowledge-bases" \
  -H "Authorization: Bearer $PINGX_API_KEY"
```

## POST /agents/v1/knowledge-bases

**CreateKnowledgeBase** · needs `agents:write`

Creates an empty knowledge base. Attach it to agents through
CreateAgent/UpdateAgent knowledgeBaseIds. Not idempotent.

**Request body** (JSON)

| Field | Type | Description |
|---|---|---|
| `name` | string | Display name (required, non-empty after trimming). |

**Response** `CreateKnowledgeBaseResponse`

| Field | Type | Description |
|---|---|---|
| `knowledgeBase` | KnowledgeBase | KnowledgeBase groups sources that agents search to ground their answers. |
| `knowledgeBase.id` | string (int64) | Knowledge base id. |
| `knowledgeBase.name` | string | Display name. |
| `knowledgeBase.sourceCount` | integer | Number of sources in the knowledge base. |
| `knowledgeBase.sources` | KnowledgeSource[] | The sources. Populated only by GetKnowledgeBase and by the create/update RPCs' responses; empty in ListKnowledgeBases. |

```bash
curl -X POST "https://api.pingx.ai/agents/v1/knowledge-bases" \
  -H "Authorization: Bearer $PINGX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name":"…"}'
```

## DELETE /agents/v1/knowledge-bases/{knowledgeBaseId}

**DeleteKnowledgeBase** · needs `agents:write`

Permanently deletes a knowledge base with all its sources and their
indexed content; agents lose the attachment. NOT_FOUND if unknown.

**Path parameters**

| Name | Type | Description |
|---|---|---|
| `knowledgeBaseId` | string (int64) | Id of the knowledge base to delete. |

**Response** `DeleteKnowledgeBaseResponse`

```bash
curl -X DELETE "https://api.pingx.ai/agents/v1/knowledge-bases/KNOWLEDGEBASEID" \
  -H "Authorization: Bearer $PINGX_API_KEY"
```

## GET /agents/v1/knowledge-bases/{knowledgeBaseId}

**GetKnowledgeBase** · needs `agents:read` (or write)

Returns one knowledge base including all its sources and their ingestion
status. NOT_FOUND if it does not exist in the organization.

**Path parameters**

| Name | Type | Description |
|---|---|---|
| `knowledgeBaseId` | string (int64) | Id of the knowledge base. |

**Response** `GetKnowledgeBaseResponse`

| Field | Type | Description |
|---|---|---|
| `knowledgeBase` | KnowledgeBase | The knowledge base with all its sources. |
| `knowledgeBase.id` | string (int64) | Knowledge base id. |
| `knowledgeBase.name` | string | Display name. |
| `knowledgeBase.sourceCount` | integer | Number of sources in the knowledge base. |
| `knowledgeBase.sources` | KnowledgeSource[] | The sources. Populated only by GetKnowledgeBase and by the create/update RPCs' responses; empty in ListKnowledgeBases. |

```bash
curl "https://api.pingx.ai/agents/v1/knowledge-bases/KNOWLEDGEBASEID" \
  -H "Authorization: Bearer $PINGX_API_KEY"
```

## PATCH /agents/v1/knowledge-bases/{knowledgeBaseId}

**UpdateKnowledgeBase** · needs `agents:write`

Renames a knowledge base. Idempotent. NOT_FOUND if unknown.

**Path parameters**

| Name | Type | Description |
|---|---|---|
| `knowledgeBaseId` | string (int64) | Id of the knowledge base to rename. |

**Request body** (JSON)

| Field | Type | Description |
|---|---|---|
| `name` | string | New display name (required, non-empty after trimming). |

**Response** `UpdateKnowledgeBaseResponse`

| Field | Type | Description |
|---|---|---|
| `knowledgeBase` | KnowledgeBase | KnowledgeBase groups sources that agents search to ground their answers. |
| `knowledgeBase.id` | string (int64) | Knowledge base id. |
| `knowledgeBase.name` | string | Display name. |
| `knowledgeBase.sourceCount` | integer | Number of sources in the knowledge base. |
| `knowledgeBase.sources` | KnowledgeSource[] | The sources. Populated only by GetKnowledgeBase and by the create/update RPCs' responses; empty in ListKnowledgeBases. |

```bash
curl -X PATCH "https://api.pingx.ai/agents/v1/knowledge-bases/KNOWLEDGEBASEID" \
  -H "Authorization: Bearer $PINGX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name":"…"}'
```

## GET /agents/v1/knowledge-bases/{knowledgeBaseId}/sources

**ListKnowledgeSources** · needs `agents:read` (or write)

Lists the sources of one knowledge base, ordered by id. Use this (or
GetKnowledgeSource) to poll ingestion status.

**Path parameters**

| Name | Type | Description |
|---|---|---|
| `knowledgeBaseId` | string (int64) | Id of the knowledge base whose sources to list. |

**Query parameters**

| Name | Type | Description |
|---|---|---|
| `pageSize` | integer | Maximum sources to return (default 50, max 200). |
| `pageToken` | string | nextPageToken from the previous response; empty for the first page. |

**Response** `ListKnowledgeSourcesResponse`

| Field | Type | Description |
|---|---|---|
| `sources` | KnowledgeSource[] |  |
| `sources[].id` | string (int64) | Source id. |
| `sources[].knowledgeBaseId` | string (int64) | Id of the knowledge base it belongs to. |
| `sources[].sourceType` | string | "text" (a note), "url" (one page), "file" (uploaded document) or "site" (whole-site crawl). |
| `sources[].title` | string | Display title (defaults to the URL or file name). |
| `sources[].sourceUri` | string | The URL for url/site sources, the original file name for files, empty for text. |
| `sources[].status` | string | Ingestion status: "pending" (queued), "crawling" (site crawl running), "ready" (fully ingested), "partial" (site crawl finished with some pages failed) or "failed" (see error). |
| `sources[].error` | string | Why ingestion failed; empty unless status is "failed". |
| `sources[].content` | string | The note text, for "text" sources only (empty for the other types). |
| `sources[].pagesDiscovered` | integer | Site crawls only: pages found so far. |
| `sources[].pagesIngested` | integer | Site crawls only: pages successfully ingested so far. |
| `sources[].pagesFailed` | integer | Site crawls only: pages that failed. |
| `sources[].ingestionFinished` | boolean | True once ingestion has reached a final state (status ready, partial or failed): stop polling. |
| `nextPageToken` | string | Pass as pageToken to get the next page; empty on the last page. |

```bash
curl "https://api.pingx.ai/agents/v1/knowledge-bases/KNOWLEDGEBASEID/sources" \
  -H "Authorization: Bearer $PINGX_API_KEY"
```

## POST /agents/v1/knowledge-bases/{knowledgeBaseId}/sources

**AddKnowledgeSource** · needs `agents:write`

Adds a source to a knowledge base and starts ingesting it (extract, chunk,
embed) in the background. Returns immediately with status "pending"; poll
GetKnowledgeSource until ingestionFinished. Exactly one payload (text,
url, file or site) must be set. Not idempotent: each call adds a source.
INVALID_ARGUMENT for a missing payload/url/filename or a file over 10 MB;
NOT_FOUND if the knowledge base is unknown.

**Path parameters**

| Name | Type | Description |
|---|---|---|
| `knowledgeBaseId` | string (int64) | Id of the knowledge base to add the source to. |

**Request body** (JSON)

| Field | Type | Description |
|---|---|---|
| `title` | string | Optional display title; defaults to "Note", the URL or the file name. |
| `text` | string | A text note (chunked and embedded like any source). |
| `url` | string | A single web page, fetched and extracted by the platform. |
| `file` | FileSource | An uploaded .txt, .md or .pdf file. |
| `file.filename` | string | File name; its extension picks the parser: .txt, .md or .pdf. |
| `file.data` | string (base64) | The raw file bytes (base64 in JSON), at most 10 MB. |
| `site` | SiteSource | A whole-site crawl. |
| `site.url` | string | Start URL of the crawl (required). |
| `site.maxPages` | integer | Maximum pages to crawl; 0 uses the server default. |

**Response** `AddKnowledgeSourceResponse`

| Field | Type | Description |
|---|---|---|
| `source` | KnowledgeSource | The new source, status "pending". Poll GetKnowledgeSource. |
| `source.id` | string (int64) | Source id. |
| `source.knowledgeBaseId` | string (int64) | Id of the knowledge base it belongs to. |
| `source.sourceType` | string | "text" (a note), "url" (one page), "file" (uploaded document) or "site" (whole-site crawl). |
| `source.title` | string | Display title (defaults to the URL or file name). |
| `source.sourceUri` | string | The URL for url/site sources, the original file name for files, empty for text. |
| `source.status` | string | Ingestion status: "pending" (queued), "crawling" (site crawl running), "ready" (fully ingested), "partial" (site crawl finished with some pages failed) or "failed" (see error). |
| `source.error` | string | Why ingestion failed; empty unless status is "failed". |
| `source.content` | string | The note text, for "text" sources only (empty for the other types). |
| `source.pagesDiscovered` | integer | Site crawls only: pages found so far. |
| `source.pagesIngested` | integer | Site crawls only: pages successfully ingested so far. |
| `source.pagesFailed` | integer | Site crawls only: pages that failed. |
| `source.ingestionFinished` | boolean | True once ingestion has reached a final state (status ready, partial or failed): stop polling. |

```bash
curl -X POST "https://api.pingx.ai/agents/v1/knowledge-bases/KNOWLEDGEBASEID/sources" \
  -H "Authorization: Bearer $PINGX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"title":"…","text":"…","url":"…","file":{},"site":{}}'
```

## DELETE /agents/v1/knowledge-sources/{sourceId}

**DeleteKnowledgeSource** · needs `agents:write`

Deletes one source and its indexed content. NOT_FOUND if unknown.

**Path parameters**

| Name | Type | Description |
|---|---|---|
| `sourceId` | string (int64) | Id of the source to delete. |

**Response** `DeleteKnowledgeSourceResponse`

```bash
curl -X DELETE "https://api.pingx.ai/agents/v1/knowledge-sources/SOURCEID" \
  -H "Authorization: Bearer $PINGX_API_KEY"
```

## GET /agents/v1/knowledge-sources/{sourceId}

**GetKnowledgeSource** · needs `agents:read` (or write)

Returns one source. This is the call to poll after AddKnowledgeSource,
UpdateKnowledgeSource or RecrawlKnowledgeSource: repeat it every few
seconds until ingestionFinished is true (status ready, partial or
failed). Sites can take minutes; check the pages_* counters for progress.

**Path parameters**

| Name | Type | Description |
|---|---|---|
| `sourceId` | string (int64) | Id of the source to read (and poll). |

**Response** `GetKnowledgeSourceResponse`

| Field | Type | Description |
|---|---|---|
| `source` | KnowledgeSource | KnowledgeSource is one piece of knowledge inside a knowledge base. Its content is extracted, chunked and embedded asynchronously after it is added. |
| `source.id` | string (int64) | Source id. |
| `source.knowledgeBaseId` | string (int64) | Id of the knowledge base it belongs to. |
| `source.sourceType` | string | "text" (a note), "url" (one page), "file" (uploaded document) or "site" (whole-site crawl). |
| `source.title` | string | Display title (defaults to the URL or file name). |
| `source.sourceUri` | string | The URL for url/site sources, the original file name for files, empty for text. |
| `source.status` | string | Ingestion status: "pending" (queued), "crawling" (site crawl running), "ready" (fully ingested), "partial" (site crawl finished with some pages failed) or "failed" (see error). |
| `source.error` | string | Why ingestion failed; empty unless status is "failed". |
| `source.content` | string | The note text, for "text" sources only (empty for the other types). |
| `source.pagesDiscovered` | integer | Site crawls only: pages found so far. |
| `source.pagesIngested` | integer | Site crawls only: pages successfully ingested so far. |
| `source.pagesFailed` | integer | Site crawls only: pages that failed. |
| `source.ingestionFinished` | boolean | True once ingestion has reached a final state (status ready, partial or failed): stop polling. |

```bash
curl "https://api.pingx.ai/agents/v1/knowledge-sources/SOURCEID" \
  -H "Authorization: Bearer $PINGX_API_KEY"
```

## PATCH /agents/v1/knowledge-sources/{sourceId}

**UpdateKnowledgeSource** · needs `agents:write`

Edits the title and content of a "text" source and re-ingests it (status
goes back to "pending"; poll GetKnowledgeSource). INVALID_ARGUMENT if the
source is not a text source; NOT_FOUND if unknown. Idempotent.

**Path parameters**

| Name | Type | Description |
|---|---|---|
| `sourceId` | string (int64) | Id of the text source to edit. |

**Request body** (JSON)

| Field | Type | Description |
|---|---|---|
| `title` | string | New title. |
| `content` | string | New note text. |

**Response** `UpdateKnowledgeSourceResponse`

| Field | Type | Description |
|---|---|---|
| `source` | KnowledgeSource | The source, status back to "pending". Poll GetKnowledgeSource. |
| `source.id` | string (int64) | Source id. |
| `source.knowledgeBaseId` | string (int64) | Id of the knowledge base it belongs to. |
| `source.sourceType` | string | "text" (a note), "url" (one page), "file" (uploaded document) or "site" (whole-site crawl). |
| `source.title` | string | Display title (defaults to the URL or file name). |
| `source.sourceUri` | string | The URL for url/site sources, the original file name for files, empty for text. |
| `source.status` | string | Ingestion status: "pending" (queued), "crawling" (site crawl running), "ready" (fully ingested), "partial" (site crawl finished with some pages failed) or "failed" (see error). |
| `source.error` | string | Why ingestion failed; empty unless status is "failed". |
| `source.content` | string | The note text, for "text" sources only (empty for the other types). |
| `source.pagesDiscovered` | integer | Site crawls only: pages found so far. |
| `source.pagesIngested` | integer | Site crawls only: pages successfully ingested so far. |
| `source.pagesFailed` | integer | Site crawls only: pages that failed. |
| `source.ingestionFinished` | boolean | True once ingestion has reached a final state (status ready, partial or failed): stop polling. |

```bash
curl -X PATCH "https://api.pingx.ai/agents/v1/knowledge-sources/SOURCEID" \
  -H "Authorization: Bearer $PINGX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"title":"…","content":"…"}'
```

## POST /agents/v1/knowledge-sources/{sourceId}:recrawl

**RecrawlKnowledgeSource** · needs `agents:write`

Re-crawls an existing "site" source from scratch (status back to
"pending", counters reset; poll GetKnowledgeSource). INVALID_ARGUMENT if
the source is not a site; FAILED_PRECONDITION if a crawl is already in
progress; NOT_FOUND if unknown.

**Path parameters**

| Name | Type | Description |
|---|---|---|
| `sourceId` | string (int64) | Id of the site source to re-crawl. |

**Response** `RecrawlKnowledgeSourceResponse`

| Field | Type | Description |
|---|---|---|
| `source` | KnowledgeSource | The source, status back to "pending". Poll GetKnowledgeSource. |
| `source.id` | string (int64) | Source id. |
| `source.knowledgeBaseId` | string (int64) | Id of the knowledge base it belongs to. |
| `source.sourceType` | string | "text" (a note), "url" (one page), "file" (uploaded document) or "site" (whole-site crawl). |
| `source.title` | string | Display title (defaults to the URL or file name). |
| `source.sourceUri` | string | The URL for url/site sources, the original file name for files, empty for text. |
| `source.status` | string | Ingestion status: "pending" (queued), "crawling" (site crawl running), "ready" (fully ingested), "partial" (site crawl finished with some pages failed) or "failed" (see error). |
| `source.error` | string | Why ingestion failed; empty unless status is "failed". |
| `source.content` | string | The note text, for "text" sources only (empty for the other types). |
| `source.pagesDiscovered` | integer | Site crawls only: pages found so far. |
| `source.pagesIngested` | integer | Site crawls only: pages successfully ingested so far. |
| `source.pagesFailed` | integer | Site crawls only: pages that failed. |
| `source.ingestionFinished` | boolean | True once ingestion has reached a final state (status ready, partial or failed): stop polling. |

```bash
curl -X POST "https://api.pingx.ai/agents/v1/knowledge-sources/SOURCEID:recrawl" \
  -H "Authorization: Bearer $PINGX_API_KEY"
```

## POST /agents/v1/system-prompts:generate

**GenerateSystemPrompt** · needs `agents:write`

Drafts an agent system prompt from a free-form brief, using Claude. Does
not create or modify any agent: copy the returned text into CreateAgent /
UpdateAgent. Can take up to a few minutes and is billed as AI usage; it is
named as a write RPC so read-only keys cannot trigger it. Not idempotent
(the wording differs between calls).

**Request body** (JSON)

| Field | Type | Description |
|---|---|---|
| `brief` | string | Free-form description of the agent to build: domain, audience, purpose, tone, anything relevant. Required. |

**Response** `GenerateSystemPromptResponse`

| Field | Type | Description |
|---|---|---|
| `systemPrompt` | string | The complete generated system prompt text. |

```bash
curl -X POST "https://api.pingx.ai/agents/v1/system-prompts:generate" \
  -H "Authorization: Bearer $PINGX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"brief":"…"}'
```


