Making Requests
This page covers the conventions and patterns you need to know when interacting with the Chainabit API: base URL, headers, response format, pagination, error handling, and idempotency.
Base URL
All endpoints are relative to:
https://api.chainabit.com/api/v1For example, append /ai/sessions to that address. The address already includes /api/v1; do not add that prefix twice.
Set up authentication and the shared environment in Prerequisites.
Required Headers
Every request should include:
| Header | Value | Required |
|---|---|---|
Content-Type | application/json | For POST, PUT, and PATCH requests |
Authorization | Bearer <accessToken> | For all authenticated endpoints |
Response Envelope
Most JSON resource responses use the following envelope. OAuth, MCP, event streams, and other explicitly documented protocol responses have their own shapes:
{
"data": { ... },
"meta": { ... }
}This diagram shows the envelope structure; the ellipses are not valid JSON values.
| Field | Description |
|---|---|
data | The requested resource or result. Omitted when an error occurs. |
meta | Additional metadata such as pagination info and requestId. Omitted when not applicable. |
error | Error details. Omitted when the request succeeds. |
For a deeper explanation of the envelope design, see Response Envelope.
Successful Response
{
"data": {
"id": "c9f8e7d6-5432-10fe-dcba-0987654321fe",
"title": "Research Assistant",
"status": "active"
}
}Error Response
{
"error": {
"code": "not_found",
"message": "Chain not found"
},
"meta": {
"requestId": "fce07573-311d-4be3-8846-1156877a6022"
}
}Pagination
Many list endpoints use offset pagination. Others use cursors or a resource-specific contract; follow the strategy in the endpoint reference. For an offset-based endpoint, the typical parameters are:
| Parameter | Default | Description |
|---|---|---|
limit | 20 | Number of items to return (max varies by endpoint). |
offset | 0 | Number of items to skip. |
Example
curl "https://api.chainabit.com/api/v1/ai/sessions?limit=10&offset=20" \
-H "Authorization: Bearer $TOKEN"const response = await fetch(
`https://api.chainabit.com/api/v1/ai/sessions?limit=10&offset=20`,
{
headers: { Authorization: `Bearer ${TOKEN}` },
}
);
const { data, meta } = await response.json();import requests
response = requests.get(
f"{BASE_URL}/ai/sessions",
params={"limit": 10, "offset": 20},
headers={"Authorization": f"Bearer {TOKEN}"},
)
result = response.json()
data, meta = result["data"], result["meta"]Open AI → GET List Sessions
Add query params: limit=10, offset=20Response
{
"data": [
{ "id": "...", "title": "Developer Pipeline" },
{ "id": "...", "title": "Research Assistant" }
],
"meta": {
"total": 42,
"limit": 10,
"offset": 20
}
}Use meta.total to calculate the number of pages or determine whether more items exist. For full pagination details, see Pagination.
Error Handling
Always check the error field in the response. Common HTTP status codes:
| Status | Meaning |
|---|---|
400 | Bad request -- invalid or missing parameters. |
401 | Unauthorized -- missing or expired token. |
403 | Forbidden -- insufficient permissions or captcha failure. |
404 | Not found -- the resource does not exist. |
409 | Conflict -- duplicate resource or idempotency key collision. |
422 | Unprocessable entity -- the request was well-formed but could not be processed. |
429 | Too many requests -- rate limit exceeded. |
500 | Internal server error. |
Rate Limiting
When you exceed the rate limit, the API returns 429 Too Many Requests with a Retry-After header indicating how many seconds to wait:
{
"error": {
"code": "RATE_LIMITED",
"message": "Too many attempts. Please wait before trying again.",
"details": {
"retryAfterSeconds": 300
}
},
"meta": {}
}Best practice: implement exponential backoff and respect the Retry-After header. For rate limit tiers and quotas, see Rate Limiting.
For the full error code reference, see Errors.
Idempotency
Use an idempotency key only where the operation documents support for it. Adding the header does not make an arbitrary write retry-safe; ordinary AI session creation, for example, does not deduplicate requests through this header.
Triggering a Chain run supports a key; send one when you need safe retries. Use a real authorized CHAIN_ID. Generate one key for the intended operation and reuse that same key when retrying it; use a different key for a new intentional run.
export IDEMPOTENCY_KEY="$(uuidgen)"
curl -X POST "https://api.chainabit.com/api/v1/chains/$CHAIN_ID/trigger-run" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $IDEMPOTENCY_KEY" \
-d '{}'const idempotencyKey = crypto.randomUUID(); // retain this value for retries
const response = await fetch(`https://api.chainabit.com/api/v1/chains/${CHAIN_ID}/trigger-run`, {
method: 'POST',
headers: {
Authorization: `Bearer ${TOKEN}`,
'Content-Type': 'application/json',
'Idempotency-Key': idempotencyKey,
},
body: JSON.stringify({}),
});
const { data } = await response.json();import requests
import uuid
idempotency_key = str(uuid.uuid4()) # retain this value for retries
response = requests.post(
f"{BASE_URL}/chains/{CHAIN_ID}/trigger-run",
headers={
"Authorization": f"Bearer {TOKEN}",
"Idempotency-Key": idempotency_key,
},
json={},
)
data = response.json()["data"]Open POST Trigger Chain Run for an authorized Chain.
Set Idempotency-Key to a saved UUID; retain it for retries of this run.Guidelines:
- Use a UUID v4 as the idempotency key.
- Deduplication scope, retention, and replay behavior belong to the individual operation.
- Do not assume a universal 24-hour lifetime or reuse a key for unrelated work.
- Follow the endpoint's actual replay or conflict response rather than expecting every retry to return
409.
Full Request-Response Example
Here is a complete example that creates an AI session, handles potential errors, and demonstrates proper header usage:
curl -s -w "\nHTTP_STATUS:%{http_code}" \
-X POST https://api.chainabit.com/api/v1/ai/sessions \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"title": "Research Assistant"
}'Success -- 201 Created (selected fields)
{
"data": {
"id": "550e8400-e29b-41d4-a716-446655440000",
"title": "Research Assistant",
"startedAt": "2026-05-04T20:00:00.000Z"
}
}Validation error -- 400 Bad Request
{
"error": {
"code": "bad_request",
"message": "title must be shorter than or equal to 120 characters; title must be a string"
},
"meta": {
"requestId": "51f5b975-524f-493c-8db3-1c78494349a8"
}
}Token expired -- 401 Unauthorized
{
"error": {
"code": "unauthorized",
"message": "Access token expired"
},
"meta": {}
}When you receive a 401, refresh your token (see Authentication) and retry the request.
Next Steps
- Browse the full API Reference for detailed endpoint documentation.
- Learn about Authentication for token management.
- Review Errors for the complete error code catalog.