Skip to main content

Overview

Meta Ads Kit wraps Meta’s Graph API, but you can also call it directly using curl or your own scripts. This guide covers token management, rate limits, error codes, and retry logic.

API Version

Meta Ads Kit uses Graph API v22.0:
Meta releases new API versions quarterly. v22.0 is supported until Q1 2027.

Authentication

Getting Your Access Token

Meta Ads Kit uses social-cli for authentication:

Required Scopes

Token Lifespan

User access tokens expire after 60 days. Check expiration:
Output:
If expires_at is within 7 days, re-authenticate:

Ad Account Setup

List Your Ad Accounts

Output:

Set Default Account

Store in workspace/brand/stack.md to avoid setting every time:
stack.md

Core Endpoints

Upload Image

Response:
Extract hash:

Create Ad Creative

Response:

Create Ad

Response:
Always create ads in PAUSED status. Review in Ads Manager before activating.

Get Ad Insights

Response:

Update Ad Status

Rate Limits

How Meta’s Rate Limiting Works

Meta uses score-based rate limiting, not a simple per-minute cap. Each API call consumes a score based on complexity: Your rate limit budget refreshes over time. If you exceed it, you get error 294.

Check Rate Limit Headers

Every API response includes rate limit headers:
Look for:
If estimated_time_to_regain_access > 0, you’re rate limited. Wait before making more calls.

Handling Rate Limit Errors (294)

Best Practices

  1. Batch requests - Upload multiple images in one call instead of separate calls
  2. Add delays - Wait 1-2 seconds between calls in loops
  3. Monitor headers - Check x-business-use-case-usage to see when you’re approaching limits
  4. Retry with backoff - Wait 10s, then 20s, then 40s on error 294
  5. Use webhooks - For insights, set up webhooks instead of polling

Error Codes

Common Errors

Meaning: Access token expired or revokedCheck token validity:
Fix:

Error Response Format

All Graph API errors follow this structure:

Retry Logic

Exponential Backoff Strategy

retry.sh

Error-Specific Retry

Debugging

Verbose Output

Save Requests for Replay

Test Token Validity

Inspect Creative Before Creating Ad

Next Steps

OpenClaw Integration

Natural language ad management

Batch Operations

Upload multiple ads at once