Skip to content

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/v1

For 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:

HeaderValueRequired
Content-Typeapplication/jsonFor POST, PUT, and PATCH requests
AuthorizationBearer <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:

text
{
  "data": { ... },
  "meta": { ... }
}

This diagram shows the envelope structure; the ellipses are not valid JSON values.

FieldDescription
dataThe requested resource or result. Omitted when an error occurs.
metaAdditional metadata such as pagination info and requestId. Omitted when not applicable.
errorError details. Omitted when the request succeeds.

For a deeper explanation of the envelope design, see Response Envelope.

Successful Response ​

json
{
  "data": {
    "id": "c9f8e7d6-5432-10fe-dcba-0987654321fe",
    "title": "Research Assistant",
    "status": "active"
  }
}

Error Response ​

json
{
  "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:

ParameterDefaultDescription
limit20Number of items to return (max varies by endpoint).
offset0Number of items to skip.

Example ​

bash
curl "https://api.chainabit.com/api/v1/ai/sessions?limit=10&offset=20" \
  -H "Authorization: Bearer $TOKEN"
js
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();
python
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"]
txt
Open AI → GET List Sessions
Add query params: limit=10, offset=20

Response

json
{
  "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:

StatusMeaning
400Bad request -- invalid or missing parameters.
401Unauthorized -- missing or expired token.
403Forbidden -- insufficient permissions or captcha failure.
404Not found -- the resource does not exist.
409Conflict -- duplicate resource or idempotency key collision.
422Unprocessable entity -- the request was well-formed but could not be processed.
429Too many requests -- rate limit exceeded.
500Internal 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:

json
{
  "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.

bash
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 '{}'
js
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();
python
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"]
txt
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)

json
{
  "data": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "title": "Research Assistant",
    "startedAt": "2026-05-04T20:00:00.000Z"
  }
}

Validation error -- 400 Bad Request

json
{
  "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

json
{
  "error": {
    "code": "unauthorized",
    "message": "Access token expired"
  },
  "meta": {}
}

When you receive a 401, refresh your token (see Authentication) and retry the request.


Next Steps ​

Built with purpose. chainabit.com