Skip to main content

Making Requests

This page covers the structure of API requests, responses, and error handling.

Base URL

https://api.custodianai.com/v1

Request format

All requests use JSON as the content type.

POST /v1/process
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

{
"text": "The content you want to process"
}

Response format

A successful response returns a 200 OK with a JSON body:

{
"result": "Processed output from CustodianAI",
"characters_used": 312,
"credits_remaining": 49688
}
FieldTypeDescription
resultstringThe processed output
characters_usednumberCharacters consumed by this request
credits_remainingnumberCharacter credits left on your key

Error responses

When something goes wrong, the API returns a non-2xx status with a JSON error body:

{
"error": "character_limit_reached",
"message": "You have used all available character credits on this plan."
}

Common error codes

StatusError codeMeaning
401unauthorizedAPI key missing or invalid
403expiredAPI key has expired
403character_limit_reachedNo credits remaining
403not_enough_creditsRequest requires more credits than available
422invalid_inputRequest body is missing required fields
429rate_limitedToo many requests — slow down
500server_errorSomething went wrong on our end

Example: full request/response cycle

async function processText(text: string): Promise<string> {
const response = await fetch('https://api.custodianai.com/v1/process', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.CUSTODIAN_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ text }),
});

if (!response.ok) {
const error = await response.json();
throw new Error(`CustodianAI error: ${error.error}${error.message}`);
}

const data = await response.json();
console.log(`Credits remaining: ${data.credits_remaining}`);
return data.result;
}

Tips

  • Check credits_remaining in each response to monitor usage proactively.
  • Handle character_limit_reached gracefully so your app doesn't crash when credits run out.
  • For large volumes of text, consider batching requests to stay within rate limits.