Build with the AfterLib API
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
- One credit shows one ad or page. You pay for an ad or a page one time in a credit month.
- Seeing the same one again this month is free. The app, the API, and MCP do not charge it again.
- Unused plan credits carry over. Plan credits that you do not use carry over while your plan runs.
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.
400. Check the inputs against OpenAPI.401. Check the API key.402. Check your plan and credit balance.403. Check API access and key permissions.404. Check the path or item ID.429. Wait forRetry-Afterwhen present. For a credit usage limit, read the error details.
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
add_ads_to_collectionadd_ads_to_favoritesadd_pages_to_collectionadd_pages_to_favoritesclear_viewing_historycreate_ad_media_downloadcreate_collectioncreate_presetdelete_collectiondelete_presetdelete_viewing_history_entryget_accountget_adget_ad_duplicate_historyget_ad_reach_historyget_collectionget_pageget_page_ad_historyget_page_reach_historyget_presetget_updateslist_ad_collectionslist_collectionslist_page_collectionslist_presetslist_viewing_historypreview_collection_actionpublish_collectionremove_ad_from_collectionremove_ad_from_favoritesremove_page_from_collectionremove_page_from_favoritesrestore_collectionsearch_adssearch_pagesset_collection_visibilityupdate_collectionupdate_preset