Skip to content

These examples use plain HTTP so they work in any environment that can send HTTPS requests.

Set the key once:

Terminal window
export AFTERLIB_API_KEY="al_live_replace_me"

Start with GET /v1/whoami to confirm which account the key or OAuth connection resolves to.

Terminal window
curl https://api.afterlib.com/v1/whoami \
-H "Authorization: Bearer $AFTERLIB_API_KEY"

Response:

{
"authenticated": true,
"authSource": "api_key",
"user": {
"userId": "00000000-0000-7001-8001-aa0000000001",
"billingUserId": "00000000-0000-7001-8001-aa0000000001",
"name": "Ada Lovelace",
"emailAddress": "ada@example.com",
"planId": "pro",
"isTeamMember": false,
"subscriptionStatus": "active"
},
"apiKey": {
"id": "019e6387-e2e9-7478-9d6d-170158c523b0",
"name": "Claude Desktop",
"keyPrefix": "al_live_abc12345"
},
"oauthClientId": null
}

Use fetch, PHP streams, Python standard library, or curl. The JavaScript, TypeScript, PHP, and Python examples include simple error handling that preserves the public request ID.

Terminal window
curl https://api.afterlib.com/v1/ads/search \
-H "Authorization: Bearer $AFTERLIB_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"search": "running shoes",
"limit": 10
}'

Use GET /v1/credits before a workflow that may return many ads or pages:

Terminal window
curl https://api.afterlib.com/v1/credits \
-H "Authorization: Bearer $AFTERLIB_API_KEY"

If the remaining balance is low, lower limit, narrow the search query, or wait for the next billing period.

Website Library reads are no-credit in this phase.

Terminal window
curl "https://api.afterlib.com/v1/websites/links?limit=10&search=product" \
-H "Authorization: Bearer $AFTERLIB_API_KEY"

Treat both 402 and 429 as stop signals for the current workflow. Do not immediately retry the same credit-consuming request.

if (response.status === 402 || response.status === 429) {
const body = await response.json();
console.error('AfterLib credits or limits blocked the request', {
code: body.error?.code,
requestId: body.error?.requestId,
});
}

402 means the account needs an active subscription or available credits. 429 means a usage limit has been reached.

  1. Save error.requestId from the error response or the X-Afterlib-Request-Id response header.
  2. Open the Developer Portal request log.
  3. Compare the method, path, status, operation, credit charge, and key prefix.
  4. Include the request ID when asking support to investigate.