Skip to content

SharpAPI.com PHP Core functionalities & communication

Notifications You must be signed in to change notification settings

sharpapi/php-core

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SharpAPI GitHub cover

SharpAPI.com PHP Core functionalities & communication

🚀 Automate workflows with AI-powered API

Leverage AI API to streamline workflows in E-Commerce, Marketing, Content Management, HR Tech, Travel, and more.

See more at SharpAPI.com Website »


Quota Method

The quota() method returns a SubscriptionInfo DTO with the following fields:

Field Type Description
timestamp Carbon Timestamp of the subscription check
on_trial bool Whether the account is on a trial period
trial_ends Carbon End date of the trial period
subscribed bool Whether the user is currently subscribed
current_subscription_start Carbon Start of the current subscription period
current_subscription_end Carbon End of the current subscription period
current_subscription_reset Carbon Quota reset timestamp
subscription_words_quota int Total word quota for the period
subscription_words_used int Words used in the current period
subscription_words_used_percentage float Percentage of word quota used
requests_per_minute int Maximum API requests allowed per minute
$client = new SharpApiClient('your-api-key');
$quota = $client->quota();

echo $quota->subscription_words_quota;
echo $quota->requests_per_minute;

Rate Limiting

The SDK automatically handles API rate limits. When the API returns HTTP 429 (Too Many Requests), the client will:

  1. Retry automatically — reads the Retry-After header, sleeps for the specified duration, and retries the request (up to 3 times by default).
  2. Slow down polling — during fetchResults(), when X-RateLimit-Remaining drops below the low threshold, polling intervals are automatically increased to avoid hitting the limit.

Inspecting Rate-Limit State

After any API call, you can check the current rate-limit values:

$client = new SharpApiClient('your-api-key');
$client->ping();

echo $client->getRateLimitLimit();     // e.g. 60 (requests per window)
echo $client->getRateLimitRemaining(); // e.g. 58 (remaining in current window)

Note: getRateLimitLimit() and getRateLimitRemaining() return null before the first API call or after endpoints that don't return rate-limit headers (e.g. /ping, /quota).

Configuration

// Max automatic retries on HTTP 429 (default: 3)
$client->setMaxRetryOnRateLimit(5);

// Threshold below which polling intervals are increased (default: 3)
$client->setRateLimitLowThreshold(5);

When rateLimitRemaining is at or below the threshold, polling intervals in fetchResults() are multiplied by an increasing factor (2x at threshold, growing as remaining approaches 0). This helps avoid 429 errors during long-running job polling.


Credits


License

The MIT License (MIT).


Social Media

🚀 For the latest news, tutorials, and case studies, don't forget to follow us on:

About

SharpAPI.com PHP Core functionalities & communication

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages