BotsAPI Reference

API Reference

All bot management endpoints require JWT authentication via the Authorization: Bearer <token> header. Webhook endpoints use platform-specific verification instead.

Base URL: https://api.aerostack.dev


Bot CRUD

List Bots

GET /api/bots

Returns all bots owned by the authenticated user, with conversation counts.

Auth: JWT required

curl https://api.aerostack.dev/api/bots \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Response:

{
  "bots": [
    {
      "id": "bt_a1b2c3d4e5f6g7h8i9j0",
      "name": "Support Bot",
      "slug": "support-bot",
      "platform": "telegram",
      "status": "active",
      "llm_provider": "anthropic",
      "llm_model": "claude-sonnet-4-6",
      "created_at": "2026-03-14T10:00:00Z",
      "updated_at": "2026-03-14T12:00:00Z",
      "last_active_at": "2026-03-14T15:30:00Z",
      "conversation_count": 42
    }
  ]
}

Create Bot

POST /api/bots

Auth: JWT required

Required fields:

FieldTypeDescription
namestringBot display name
platformstringtelegram, discord, whatsapp, slack, or custom
workspace_idstringMCP workspace ID (must be owned by the user)
system_promptstringLLM system instructions

Optional fields:

FieldTypeDefaultDescription
descriptionstringnullBot description
platform_configobject{}Platform-specific credentials (stored securely)
llm_providerstringanthropicanthropic, openai, gemini, groq, workers-ai, custom
llm_modelstringclaude-sonnet-4-6Model identifier
llm_api_keystringnullBYOK LLM API key (stored securely)
llm_configobject{}LLM config (e.g., { "temperature": 0.7 })
billing_modestringwalletwallet, byok, plan_quota
max_loop_iterationsnumber10Max agent loop tool-call rounds
max_tokens_per_turnnumber8192Max output tokens per LLM call
timeout_msnumber30000Processing timeout (max 60000)
conversation_max_messagesnumber20Context window size (messages)
conversation_ttl_hoursnumber24Conversation expiry
enable_ragbooleanfalseReserved for RAG integration
welcome_messagestringnullSent on first interaction
fallback_messagestringnullSent on error
spending_cap_centsnumbernullLifetime spending cap
curl -X POST https://api.aerostack.dev/api/bots \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "My Bot",
    "platform": "telegram",
    "workspace_id": "ws-abc123",
    "system_prompt": "You are a helpful assistant.",
    "platform_config": { "bot_token": "123:ABC" },
    "llm_provider": "openai",
    "llm_model": "gpt-4o-mini"
  }'

Response: 201 Created

{
  "bot": {
    "id": "bt_a1b2c3d4e5f6g7h8i9j0",
    "name": "My Bot",
    "platform": "telegram",
    "status": "draft",
    "has_platform_config": true,
    "has_llm_api_key": false
  }
}

Sensitive fields like platform credentials and LLM API keys are never returned in API responses. Instead, boolean flags has_platform_config and has_llm_api_key indicate whether they are set.


Get Bot

GET /api/bots/:id

Auth: JWT required (must be bot owner)

Returns the bot with template info (if created from a template).

curl https://api.aerostack.dev/api/bots/bt_abc123 \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Update Bot

PATCH /api/bots/:id

Auth: JWT required (must be bot owner)

Update any bot field. Validates workflow_json structure if provided.

curl -X PATCH https://api.aerostack.dev/api/bots/bt_abc123 \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "system_prompt": "Updated prompt.",
    "max_loop_iterations": 5,
    "spending_cap_cents": 1000
  }'

Updatable fields: name, description, system_prompt, llm_provider, llm_model, llm_config, llm_api_key, platform_config, billing_mode, max_loop_iterations, max_tokens_per_turn, timeout_ms, conversation_max_messages, conversation_ttl_hours, enable_rag, welcome_message, fallback_message, spending_cap_cents, workflow_json, workflow_enabled


Delete Bot

DELETE /api/bots/:id

Auth: JWT required (must be bot owner)

Deletes the bot and all associated conversations, messages, and analytics. Unregisters the Telegram webhook (best effort).

curl -X DELETE https://api.aerostack.dev/api/bots/bt_abc123 \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Response:

{ "deleted": true }

Lifecycle

Activate Bot

POST /api/bots/:id/activate

Auth: JWT required (must be bot owner)

Registers the webhook with the platform and sets status to active.

curl -X POST https://api.aerostack.dev/api/bots/bt_abc123/activate \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Response:

{
  "status": "active",
  "webhook_url": "https://api.aerostack.dev/api/bots/webhook/telegram/bt_abc123",
  "warnings": [],
  "manual_setup_required": false
}
FieldDescription
webhook_urlThe URL registered with the platform
warningsSecurity warnings (e.g., missing webhook secret)
manual_setup_requiredtrue for Slack and WhatsApp (webhook URL must be set manually)

Pause Bot

POST /api/bots/:id/pause

Auth: JWT required (must be bot owner)

Unregisters the webhook and sets status to paused. The bot stops receiving messages.

curl -X POST https://api.aerostack.dev/api/bots/bt_abc123/pause \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Response:

{ "status": "paused" }

Test Bot

POST /api/bots/:id/test

Auth: JWT required (must be bot owner)

Rate limit: 10 requests per 60 seconds per user

Sends a test message through the full bot engine pipeline without going through a platform adapter.

curl -X POST https://api.aerostack.dev/api/bots/bt_abc123/test \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "message": "What can you help with?" }'

Response:

{
  "response": "I can help you with...",
  "tool_calls": [],
  "tokens": { "input": 342, "output": 28 },
  "token_breakdown": { "systemPrompt": 120, "total": 370 },
  "cost_cents": 0,
  "latency_ms": 1230,
  "loop_iterations": 0,
  "conversation_id": "bconv_abc123"
}
⚠️

The test endpoint creates real conversations and messages in the database. Costs are charged to your wallet in wallet billing mode.


Conversations

List Conversations

GET /api/bots/:id/conversations

Auth: JWT required (must be bot owner)

Query parameters:

ParamDefaultMaxDescription
limit50100Number of conversations to return
offset0-Pagination offset
curl "https://api.aerostack.dev/api/bots/bt_abc123/conversations?limit=20&offset=0" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Get Conversation with Messages

GET /api/bots/:id/conversations/:convId

Auth: JWT required (must be bot owner)

Query parameters:

ParamDefaultMaxDescription
limit100500Number of messages to return
curl "https://api.aerostack.dev/api/bots/bt_abc123/conversations/bconv_xyz/messages?limit=200" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Response:

{
  "conversation": {
    "id": "bconv_xyz",
    "platform_user_id": "user_123",
    "message_count": 15,
    "total_cost_cents": 3,
    "started_at": "2026-03-14T10:00:00Z",
    "last_message_at": "2026-03-14T10:05:00Z"
  },
  "messages": [
    { "id": "bmsg_1", "role": "user", "content": "Hello", "created_at": "..." },
    { "id": "bmsg_2", "role": "assistant", "content": "Hi there!", "created_at": "..." }
  ]
}

Analytics

Get Analytics

GET /api/bots/:id/analytics

Auth: JWT required (must be bot owner)

Query parameters:

ParamDefaultDescription
from30 days agoStart date (YYYY-MM-DD)
totodayEnd date (YYYY-MM-DD)

Returns daily analytics, summary totals, top tools, average latency, and conversations by status.

curl "https://api.aerostack.dev/api/bots/bt_abc123/analytics?from=2026-03-01&to=2026-03-15" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Get Insights

GET /api/bots/:id/insights

Auth: JWT required (must be bot owner)

Returns unanswered questions (messages where the bot did not use tools) and resolution rate.

curl https://api.aerostack.dev/api/bots/bt_abc123/insights \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Response:

{
  "unanswered_questions": [
    { "question": "Can I get a refund?", "bot_response": "...", "created_at": "..." }
  ],
  "resolution_rate": 78,
  "total_answered": 312,
  "total_responses": 400
}

Setup Wizard

Create Bot from Template

POST /api/bots/setup

Auth: JWT required

Creates a workspace, connects MCP servers, and creates a bot in one call.

FieldRequiredDescription
template_idYesTemplate ID (e.g., tpl_support)
bot_nameNoBot name (defaults to template name)
platformNoPlatform (defaults to custom)
platform_configNoPlatform credentials
config_valuesNoKey-value pairs injected into the system prompt
llm_api_keyNoBYOK LLM API key
curl -X POST https://api.aerostack.dev/api/bots/setup \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "template_id": "tpl_support",
    "bot_name": "Acme Support",
    "platform": "telegram",
    "platform_config": { "bot_token": "123:ABC" },
    "config_values": { "company_name": "Acme Corp" }
  }'

Templates

List Templates

GET /api/bots/templates

Auth: None required

ParamDefaultMaxDescription
type--Filter by category
limit50100Number of templates

Get Template

GET /api/bots/templates/:templateId

Auth: None required

Create Template

POST /api/bots/templates

Auth: JWT required

Required: name, description, category, system_prompt

Update Template

PATCH /api/bots/templates/:templateId

Auth: JWT required (must be template owner; system templates return 403)

Delete Template

DELETE /api/bots/templates/:templateId

Auth: JWT required (must be template owner; system templates return 403)


Webhook Endpoints

These endpoints receive messages from messaging platforms. They use platform-specific verification, not JWT auth.

MethodPathPlatformVerification
POST/api/bots/webhook/telegram/:botIdTelegramX-Telegram-Bot-Api-Secret-Token header
POST/api/bots/webhook/discord/:botIdDiscordEd25519 signature
POST/api/bots/webhook/whatsapp/:botIdWhatsAppHMAC-SHA256 X-Hub-Signature-256
GET/api/bots/webhook/whatsapp/:botIdWhatsAppVerify token challenge
POST/api/bots/webhook/slack/:botIdSlackHMAC-SHA256 X-Slack-Signature
POST/api/bots/webhook/custom/:botIdCustomNone

Custom Webhook Request

curl -X POST https://api.aerostack.dev/api/bots/webhook/custom/bt_abc123 \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Hello",
    "user_id": "user_1",
    "channel_id": "channel_1",
    "user_name": "Jane"
  }'

Response:

{
  "response": "Hi Jane! How can I help?",
  "tool_calls": [],
  "tokens": { "input": 200, "output": 15 },
  "cost_cents": 0,
  "latency_ms": 890
}

Error Responses

All error responses follow this format:

{ "error": "Error description" }
StatusMeaning
400Invalid request (missing fields, invalid JSON, etc.)
404Bot or resource not found, or not owned by caller
403Cannot modify system template
429Rate limited