API Reference
Complete reference for the Castopia Partner API v1. All endpoints use JSON and authenticate via x-api-key header.
Authentication
Include your API key in every request using either method:
# Header method (recommended) curl -H "x-api-key: sk_live_your_key_here" ... # Bearer method curl -H "Authorization: Bearer sk_live_your_key_here" ...
Get your API key from Settings → API Keys. Partner endpoints require an active partner account.
Base URL
https://app.castopia.ai
Marketing (One-Call)
The core endpoint. Submit content and get a full marketing campaign created automatically.
Customers
Manage your customers. Each customer gets their own isolated organization, project, and knowledge base.
Campaigns & Analytics
View campaign performance and content analytics for your customers or your own org.
Embeddable Dashboard
Generate tokens to embed analytics dashboards in your product.
Usage & Billing
Monitor API usage and billing across all your customers.
Webhooks
Configure webhooks to receive real-time notifications when events occur.
Error Codes
| Code | Status | Description |
|---|---|---|
| MISSING_API_KEY | 401 | No API key provided |
| INVALID_API_KEY | 401 | Key is invalid, expired, or revoked |
| NO_ORGANIZATION | 400 | No org linked to the API key |
| NOT_A_PARTNER | 403 | Endpoint requires a partner account |
| PARTNER_INACTIVE | 403 | Partner account pending or suspended |
| CUSTOMER_NOT_FOUND | 404 | Customer ID or externalId not found |
| CUSTOMER_EXISTS | 409 | A customer with this externalId already exists |
Webhook Verification
Verify webhook signatures using HMAC-SHA256 with your webhook secret:
const crypto = require('crypto');
function verifyWebhook(body, signature, secret) {
const expected = crypto
.createHmac('sha256', secret)
.update(body)
.digest('hex');
return signature === expected;
}
// In your webhook handler:
app.post('/webhooks/castopia', (req, res) => {
const signature = req.headers['x-castopia-signature'];
if (!verifyWebhook(JSON.stringify(req.body), signature, WEBHOOK_SECRET)) {
return res.status(401).send('Invalid signature');
}
// Process event...
const { event, data } = req.body;
});