Build with the AfterLib API

Open in Claude (opens in a new tab) Open in ChatGPT (opens in a new tab)

Search Meta ads and Pages, and work with collections and presets. Use REST from your own code or MCP from an AI assistant.

The AfterLib API and MCP are in preview. They work today, but they are still in development and can change at any time while we improve them.

REST authentication

Base URL https://api.afterlib.com/v1

Open API/MCP in AfterLib (API & Assistants in the previous app), then For developers. Create a key there. Store it as AFTERLIB_API_KEY in your server environment. Send Authorization: Bearer <key> with each API call.

Links

Each ad, Meta Page, collection and preset in an answer has appUrl. It is the absolute link that opens the item in AfterLib. Show appUrl to your users. Do not build AfterLib links from IDs.

Examples

Check your account and credit balance

Requires account:read.

curl --fail-with-body 'https://api.afterlib.com/v1/account' \
  -H "Authorization: Bearer $AFTERLIB_API_KEY"

Read API updates

Requires account:read.

curl --fail-with-body 'https://api.afterlib.com/v1/updates' \
  -H "Authorization: Bearer $AFTERLIB_API_KEY"

Search ads with TypeScript

Requires library:read. Run on your server. The search can spend credits.

const key = process.env.AFTERLIB_API_KEY
if (!key) throw new Error('Set AFTERLIB_API_KEY')

const response = await fetch('https://api.afterlib.com/v1/ads/search', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${key}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ limit: 5 }),
})

const result = await response.json()
if (!response.ok) throw new Error(`${response.status} ${result.code}: ${result.message}`)
console.log(result.items)

To get the next page, send nextCursor as cursor with the same filters and sort.

Rate limits and credits

REST allows 60 requests per key and 300 requests per account in each 60-second window. Read RateLimit-Remaining and RateLimit-Reset to see how many calls are left and how many seconds remain.

How credits work

The AfterLib app, the API, and MCP use the same credits. Only ads and Meta Pages use credits. Calls for your account, presets, and the list of your collections are free. Paused Meta Pages are hidden by default and excluded from API and MCP results.

When your credits run out during a call, the response contains fewer ads or Meta Pages than limit. When you have no credits left, the call returns PAYMENT_REQUIRED. Check credits.left with GET /account or get_account before large reads. See the credits of each plan.

Errors

Read the HTTP status and the JSON code and message fields.

Include the AfterLib-Request-Id response header if you contact support.

MCP

A tool error has isError: true, a message that says what happened, and a nextStep. See What you can ask AfterLib for example prompts and troubleshooting.

Available tools