Skip to content

Rate Limits ​

PackEdge API rate limits and optimization strategies.

Public API Limits ​

The Public API runs on Cloudflare Workers with KV caching. Standard Cloudflare Workers limits apply.

Effective Limits ​

EndpointCache TTLNotes
/public/v1/licenses/validate60sCached per public_key + license_key
/public/v1/licenses/check60sCached per public_key + license_key + domain
/v1/wp/update-check5minCached per product slug

Cache Invalidation ​

  • Activation/deactivation invalidates the cache for that license
  • Product updates invalidate the update-check cache

Optimization Tips ​

1. Cache Locally ​

Don't call the API on every page load. Cache results locally:

php
function is_license_valid() {
    $cached = get_transient('my_plugin_license_status');

    if ($cached !== false) {
        return $cached;
    }

    // Call API
    $result = validate_license();

    // Cache for 1 hour
    set_transient('my_plugin_license_status', $result, HOUR_IN_SECONDS);

    return $result;
}

2. Validate on Specific Actions ​

Only validate when necessary:

  • On settings page load
  • On plugin activation
  • Weekly via cron job
php
// Weekly license check
add_action('my_plugin_weekly_check', function() {
    $result = validate_license();
    update_option('my_plugin_license_valid', $result['valid']);
});

if (!wp_next_scheduled('my_plugin_weekly_check')) {
    wp_schedule_event(time(), 'weekly', 'my_plugin_weekly_check');
}

3. Use Check Instead of Validate ​

For quick status checks, use /licenses/check instead of /licenses/validate:

php
// Quick check - is this domain activated?
$result = $client->licenses()->check([...]);

// Full validation - get license details
$result = $client->licenses()->validate([...]);

4. Batch Operations ​

If checking multiple licenses, consider using webhooks instead:

  • Subscribe to license.expired events
  • Update local database when licenses change
  • Check local database instead of API

Error Handling ​

429 Too Many Requests ​

If you receive a 429 response:

json
{
  "error": "Too many requests",
  "retry_after": 60
}

Implement exponential backoff:

php
function api_request_with_retry($url, $args, $max_retries = 3) {
    $delay = 1;

    for ($i = 0; $i < $max_retries; $i++) {
        $response = wp_remote_post($url, $args);
        $code = wp_remote_retrieve_response_code($response);

        if ($code !== 429) {
            return $response;
        }

        sleep($delay);
        $delay *= 2; // Exponential backoff
    }

    return $response;
}

Monitoring ​

Track your API usage in the PackEdge console under Settings > Usage.