Agents API
Complete API reference for creating, listing, retrieving, updating, and deleting AI agents in Chatsby.
The Agents API lets you manage the full lifecycle of your AI agents. An agent is the core resource in Chatsby — it represents a configured chatbot with a specific model, personality, and knowledge base.
The Agent Object
Every agent returned by the API conforms to this schema:
| Field | Type | Required | Description |
|---|---|---|---|
id | string | — | Unique identifier (e.g., agent_1a2b3c4d5e). Read-only. |
name | string | Yes | Human-readable name. Max 100 characters. |
model | string | No | AI model: gpt-4-turbo, gpt-4o, gpt-3.5-turbo. Default: gpt-4o. |
system_prompt | string | No | Instructions defining the agent's behavior. Max 4,000 characters. |
temperature | number | No | Response randomness (0.0 - 2.0). Default: 0.7. |
max_tokens | integer | No | Maximum response length (1 - 4096). Default: 1024. |
status | string | — | Agent state: active, paused, or deleted. Read-only. |
created_at | string | — | ISO 8601 creation timestamp. Read-only. |
updated_at | string | — | ISO 8601 last-modified timestamp. Read-only. |
{
"id": "agent_1a2b3c4d5e",
"name": "Customer Support Bot",
"model": "gpt-4o",
"system_prompt": "You are a helpful customer support agent for Acme Corp.",
"temperature": 0.5,
"max_tokens": 1024,
"status": "active",
"created_at": "2025-03-10T08:00:00Z",
"updated_at": "2025-03-12T14:30:00Z"
}Create an Agent
Creates a new agent in your account. The agent is immediately set to active status and ready to receive conversations once you add sources.
POST /v1/agents
Request Body
| Parameter | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Agent display name. Max 100 characters. |
model | string | No | AI model to use. Default: gpt-4o. |
system_prompt | string | No | Behavioral instructions for the agent. |
temperature | number | No | Randomness control (0.0 - 2.0). Default: 0.7. |
max_tokens | integer | No | Max response tokens (1 - 4096). Default: 1024. |
cURL
curl -X POST https://api.chatsby.co/v1/agents \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Sales Assistant",
"model": "gpt-4o",
"system_prompt": "You are a knowledgeable sales assistant for Acme Corp. Help customers understand our products and pricing. Be friendly and professional.",
"temperature": 0.6,
"max_tokens": 1024
}'JavaScript
const response = await fetch('https://api.chatsby.co/v1/agents', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: 'Sales Assistant',
model: 'gpt-4o',
system_prompt: 'You are a knowledgeable sales assistant for Acme Corp.',
temperature: 0.6,
max_tokens: 1024,
}),
});
const agent = await response.json();
console.log(agent.id); // "agent_f7g8h9i0j1"Response 201 Created
{
"id": "agent_f7g8h9i0j1",
"name": "Sales Assistant",
"model": "gpt-4o",
"system_prompt": "You are a knowledgeable sales assistant for Acme Corp. Help customers understand our products and pricing. Be friendly and professional.",
"temperature": 0.6,
"max_tokens": 1024,
"status": "active",
"created_at": "2025-03-15T10:00:00Z",
"updated_at": "2025-03-15T10:00:00Z"
}Error Responses
| Status | Code | Description |
|---|---|---|
400 | missing_required_field | The name field is required. |
400 | invalid_parameter | A parameter value is out of the allowed range (e.g., temperature > 2.0). |
401 | invalid_api_key | Invalid or missing API key. |
422 | validation_error | Request body failed validation. Check the param field in the error. |
List Agents
Retrieves a paginated list of all agents in your account. Agents are returned in reverse chronological order (newest first).
GET /v1/agents
Query Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
page_size | integer | 20 | Number of agents per page (1 - 100). |
cursor | string | — | Pagination cursor from a previous response. |
status | string | — | Filter by status: active, paused. |
cURL
curl "https://api.chatsby.co/v1/agents?page_size=10&status=active" \
-H "Authorization: Bearer YOUR_API_KEY"JavaScript
const response = await fetch(
'https://api.chatsby.co/v1/agents?page_size=10&status=active',
{
headers: { 'Authorization': 'Bearer YOUR_API_KEY' },
}
);
const { data, has_more, next_cursor } = await response.json();Response 200 OK
{
"data": [
{
"id": "agent_f7g8h9i0j1",
"name": "Sales Assistant",
"model": "gpt-4o",
"system_prompt": "You are a knowledgeable sales assistant...",
"temperature": 0.6,
"max_tokens": 1024,
"status": "active",
"created_at": "2025-03-15T10:00:00Z",
"updated_at": "2025-03-15T10:00:00Z"
},
{
"id": "agent_1a2b3c4d5e",
"name": "Customer Support Bot",
"model": "gpt-4o",
"system_prompt": "You are a helpful customer support agent...",
"temperature": 0.5,
"max_tokens": 1024,
"status": "active",
"created_at": "2025-03-10T08:00:00Z",
"updated_at": "2025-03-12T14:30:00Z"
}
],
"has_more": false,
"next_cursor": null
}Retrieve an Agent
Retrieves the full details of a single agent by its ID.
GET /v1/agents/{agent_id}
Path Parameters
| Parameter | Type | Description |
|---|---|---|
agent_id | string | The unique identifier of the agent (e.g., agent_1a2b3c4d5e). |
cURL
curl https://api.chatsby.co/v1/agents/agent_1a2b3c4d5e \
-H "Authorization: Bearer YOUR_API_KEY"JavaScript
const response = await fetch(
'https://api.chatsby.co/v1/agents/agent_1a2b3c4d5e',
{
headers: { 'Authorization': 'Bearer YOUR_API_KEY' },
}
);
const agent = await response.json();Response 200 OK
Returns the full agent object (same schema as the Create response).
Error Responses
| Status | Code | Description |
|---|---|---|
401 | invalid_api_key | Invalid or missing API key. |
404 | resource_not_found | No agent exists with the given ID. |
Update an Agent
Updates one or more fields on an existing agent. Only the fields you include in the request body are modified — all other fields remain unchanged. This is a partial update (PATCH semantics).
PATCH /v1/agents/{agent_id}
Path Parameters
| Parameter | Type | Description |
|---|---|---|
agent_id | string | The unique identifier of the agent. |
Request Body
All fields are optional. Include only the fields you want to change.
| Parameter | Type | Description |
|---|---|---|
name | string | Updated display name. |
model | string | Updated AI model. |
system_prompt | string | Updated behavioral instructions. |
temperature | number | Updated randomness (0.0 - 2.0). |
max_tokens | integer | Updated max response tokens (1 - 4096). |
status | string | Set to active or paused. |
cURL
curl -X PATCH https://api.chatsby.co/v1/agents/agent_1a2b3c4d5e \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"system_prompt": "You are a senior support specialist for Acme Corp. Always greet users by name if available. Escalate billing issues to a human agent.",
"temperature": 0.3
}'JavaScript
const response = await fetch(
'https://api.chatsby.co/v1/agents/agent_1a2b3c4d5e',
{
method: 'PATCH',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
system_prompt: 'You are a senior support specialist for Acme Corp.',
temperature: 0.3,
}),
}
);
const agent = await response.json();Response 200 OK
Returns the full updated agent object with the updated_at timestamp refreshed.
Error Responses
| Status | Code | Description |
|---|---|---|
400 | invalid_parameter | A parameter value is out of range. |
401 | invalid_api_key | Invalid or missing API key. |
404 | resource_not_found | No agent exists with the given ID. |
422 | validation_error | Request body failed validation. |
Delete an Agent
Permanently deletes an agent and all of its associated sources and conversations. This action is irreversible.
DELETE /v1/agents/{agent_id}
Path Parameters
| Parameter | Type | Description |
|---|---|---|
agent_id | string | The unique identifier of the agent to delete. |
cURL
curl -X DELETE https://api.chatsby.co/v1/agents/agent_1a2b3c4d5e \
-H "Authorization: Bearer YOUR_API_KEY"JavaScript
const response = await fetch(
'https://api.chatsby.co/v1/agents/agent_1a2b3c4d5e',
{
method: 'DELETE',
headers: { 'Authorization': 'Bearer YOUR_API_KEY' },
}
);
// 204 No Content on successResponse 204 No Content
No response body. The agent and all associated data have been permanently deleted.
Error Responses
| Status | Code | Description |
|---|---|---|
401 | invalid_api_key | Invalid or missing API key. |
404 | resource_not_found | No agent exists with the given ID. |
Deleting an agent also deletes all of its sources and conversations. This action cannot be undone. If you want to temporarily disable an agent without destroying data, use the Update endpoint to set status to paused.
Example Workflows
Create and fully configure an agent
This example creates an agent, then adds sources to build its knowledge base.
import { Chatsby } from '@chatsby/sdk';
const chatsby = new Chatsby({ apiKey: process.env.CHATSBY_API_KEY });
// Step 1: Create the agent
const agent = await chatsby.agents.create({
name: 'Acme Support Bot',
model: 'gpt-4o',
system_prompt: `You are the Acme Corp support bot. Rules:
1. Always be polite and professional.
2. Only answer questions based on the provided sources.
3. If unsure, ask the user to contact [email protected].`,
temperature: 0.4,
max_tokens: 1024,
});
console.log(`Agent created: ${agent.id}`);
// Step 2: Add knowledge sources
await chatsby.sources.create(agent.id, {
type: 'website',
content: 'https://acme.com/help',
});
await chatsby.sources.create(agent.id, {
type: 'text',
content: 'Acme Corp was founded in 2020. Our headquarters are in San Francisco.',
});
console.log('Sources added — they will begin processing immediately.');Update a system prompt based on feedback
// Iterate on the agent's instructions without recreating it
await chatsby.agents.update('agent_1a2b3c4d5e', {
system_prompt: `You are the Acme Corp support bot. Updated rules:
1. Always be polite and professional.
2. Only answer questions based on the provided sources.
3. If unsure, ask the user to contact [email protected].
4. For billing questions, provide the billing portal link: https://acme.com/billing
5. Never share internal pricing formulas.`,
});List all active agents with pagination
let cursor = null;
const allAgents = [];
do {
const params = new URLSearchParams({
page_size: '50',
status: 'active',
});
if (cursor) params.set('cursor', cursor);
const response = await fetch(
`https://api.chatsby.co/v1/agents?${params}`,
{ headers: { 'Authorization': `Bearer ${process.env.CHATSBY_API_KEY}` } }
);
const page = await response.json();
allAgents.push(...page.data);
cursor = page.has_more ? page.next_cursor : null;
} while (cursor);
console.log(`Found ${allAgents.length} active agents.`);On this page
- The Agent Object
- Create an Agent
- Request Body
- cURL
- JavaScript
- Response `201 Created`
- Error Responses
- List Agents
- Query Parameters
- cURL
- JavaScript
- Response `200 OK`
- Retrieve an Agent
- Path Parameters
- cURL
- JavaScript
- Response `200 OK`
- Error Responses
- Update an Agent
- Path Parameters
- Request Body
- cURL
- JavaScript
- Response `200 OK`
- Error Responses
- Delete an Agent
- Path Parameters
- cURL
- JavaScript
- Response `204 No Content`
- Error Responses
- Example Workflows
- Create and fully configure an agent
- Update a system prompt based on feedback
- List all active agents with pagination