API Reference

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:

FieldTypeRequiredDescription
idstringUnique identifier (e.g., agent_1a2b3c4d5e). Read-only.
namestringYesHuman-readable name. Max 100 characters.
modelstringNoAI model: gpt-4-turbo, gpt-4o, gpt-3.5-turbo. Default: gpt-4o.
system_promptstringNoInstructions defining the agent's behavior. Max 4,000 characters.
temperaturenumberNoResponse randomness (0.0 - 2.0). Default: 0.7.
max_tokensintegerNoMaximum response length (1 - 4096). Default: 1024.
statusstringAgent state: active, paused, or deleted. Read-only.
created_atstringISO 8601 creation timestamp. Read-only.
updated_atstringISO 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

ParameterTypeRequiredDescription
namestringYesAgent display name. Max 100 characters.
modelstringNoAI model to use. Default: gpt-4o.
system_promptstringNoBehavioral instructions for the agent.
temperaturenumberNoRandomness control (0.0 - 2.0). Default: 0.7.
max_tokensintegerNoMax 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

StatusCodeDescription
400missing_required_fieldThe name field is required.
400invalid_parameterA parameter value is out of the allowed range (e.g., temperature > 2.0).
401invalid_api_keyInvalid or missing API key.
422validation_errorRequest 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

ParameterTypeDefaultDescription
page_sizeinteger20Number of agents per page (1 - 100).
cursorstringPagination cursor from a previous response.
statusstringFilter 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

ParameterTypeDescription
agent_idstringThe 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

StatusCodeDescription
401invalid_api_keyInvalid or missing API key.
404resource_not_foundNo 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

ParameterTypeDescription
agent_idstringThe unique identifier of the agent.

Request Body

All fields are optional. Include only the fields you want to change.

ParameterTypeDescription
namestringUpdated display name.
modelstringUpdated AI model.
system_promptstringUpdated behavioral instructions.
temperaturenumberUpdated randomness (0.0 - 2.0).
max_tokensintegerUpdated max response tokens (1 - 4096).
statusstringSet 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

StatusCodeDescription
400invalid_parameterA parameter value is out of range.
401invalid_api_keyInvalid or missing API key.
404resource_not_foundNo agent exists with the given ID.
422validation_errorRequest 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

ParameterTypeDescription
agent_idstringThe 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 success

Response 204 No Content

No response body. The agent and all associated data have been permanently deleted.

Error Responses

StatusCodeDescription
401invalid_api_keyInvalid or missing API key.
404resource_not_foundNo 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.`);