PHPackages                             sharpapi/php-core - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. sharpapi/php-core

ActiveLibrary[API Development](/categories/api)

sharpapi/php-core
=================

SharpAPI.com PHP Core functionalities &amp; communication

v1.4.0(2mo ago)16.4k↓25%20MITPHPPHP ^8.1

Since Nov 13Pushed 2mo agoCompare

[ Source](https://github.com/sharpapi/php-core)[ Packagist](https://packagist.org/packages/sharpapi/php-core)[ RSS](/packages/sharpapi-php-core/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (4)Versions (8)Used By (20)

[![SharpAPI GitHub cover](https://camo.githubusercontent.com/82bb36706c1e71276b3dca4ec9120353bb51c8f22bb62543bf056db5c28da36d/68747470733a2f2f73686172706170692e636f6d2f73686172706170692d6769746875622d6c61726176656c2d62672e6a7067 "SharpAPI Laravel Client")](https://camo.githubusercontent.com/82bb36706c1e71276b3dca4ec9120353bb51c8f22bb62543bf056db5c28da36d/68747470733a2f2f73686172706170692e636f6d2f73686172706170692d6769746875622d6c61726176656c2d62672e6a7067)

SharpAPI.com PHP Core functionalities &amp; communication
=========================================================

[](#sharpapicom-php-core-functionalities--communication)

🚀 Automate workflows with AI-powered API
----------------------------------------

[](#-automate-workflows-with-ai-powered-api)

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

[](#leverage-ai-api-to-streamline-workflows-in-e-commerce-marketing-content-management-hr-tech-travel-and-more)

See more at [SharpAPI.com Website »](https://sharpapi.com/)

---

Requirements
------------

[](#requirements)

- PHP &gt;= 8.1
- `ext-json`
- `ext-mbstring`

Installation
------------

[](#installation)

```
composer require sharpapi/php-core
```

> **Note:** This is the core library. Most users will install one of the [specialized endpoint packages](https://packagist.org/packages/sharpapi/) which already require `sharpapi/php-core` as a dependency.

---

Quota Method
------------

[](#quota-method)

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

FieldTypeDescription`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;
```

---

Two-Layer Rate Limiting Architecture
------------------------------------

[](#two-layer-rate-limiting-architecture)

The SDK uses a two-layer approach to keep your requests within API limits:

LayerTypeHow it works**Native Throttling**Proactive (client-side)Sliding window rate limiter blocks outgoing requests *before* they hit the server**429 Retry &amp; Adaptive Polling**Reactive (server-side)Catches HTTP 429 responses, retries with backoff, and slows polling when limits are lowThe proactive layer prevents most 429 errors from ever occurring. The reactive layer acts as a safety net for edge cases (clock drift, concurrent processes, plan changes).

---

Native Throttling
-----------------

[](#native-throttling)

Every `SharpApiClient` instance includes an in-memory **sliding window rate limiter** (`SlidingWindowRateLimiter`) that tracks request timestamps in a 60-second rolling window.

Before each API call, `waitIfNeeded()` checks the window. If capacity is available the request proceeds immediately; if not, the call sleeps until the oldest timestamp expires out of the window.

- **Default limit:** 60 requests/minute (matches most subscription plans)
- **Per-process, in-memory** — no external dependencies (Redis, database, etc.)
- **Server-adaptive** — when the server returns a higher `X-RateLimit-Limit` header (e.g. after a plan upgrade), the limiter automatically ratchets up to match. It never ratchets *down*, so your configured default is always the floor.
- **Metadata bypass** — `ping()` and `quota()` skip throttling to avoid deadlocks when checking connectivity or subscription status.

### Configuration

[](#configuration)

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

// Change the throttle limit (default: 60)
$client->setRequestsPerMinute(120);

// Disable throttling entirely (pass 0)
$client->setRequestsPerMinute(0);
```

### Advanced Throttling Controls

[](#advanced-throttling-controls)

You can access the underlying `SlidingWindowRateLimiter` instance directly for fine-grained control:

```
$limiter = $client->getRateLimiter();

// Non-blocking check — returns true if a request can proceed without waiting
$limiter->canProceed();

// How many requests are available in the current window
$limiter->remaining();       // e.g. 42
```

**Cross-process state caching** — save and restore the server-reported rate limit state (e.g. between HTTP requests in a web app):

```
// After an API call, cache the server-reported state
$state = $client->getRateLimitState();
// $state = ['limit' => 60, 'remaining' => 58]
cache()->put('sharpapi_rate_state', $state, 60);

// In the next process/request, restore it
$client->setRateLimitState(cache()->get('sharpapi_rate_state'));
```

**Quick quota check** — verify the server still reports available capacity before making a request:

```
if ($client->canMakeRequest()) {
    // Server-reported remaining > 0 (or no server data yet)
}
```

---

Automatic 429 Retry &amp; Adaptive Polling
------------------------------------------

[](#automatic-429-retry--adaptive-polling)

If a request does hit the server rate limit, the SDK handles it automatically:

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

[](#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

[](#configuration-1)

```
// 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
-------

[](#credits)

- [A2Z WEB LTD](https://github.com/a2zwebltd)
- [Dawid Makowski](https://github.com/makowskid)
- Boost your [Laravel AI](https://sharpapi.com/) capabilities!

---

License
-------

[](#license)

The MIT License (MIT).

---

Social Media
------------

[](#social-media)

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

- [SharpAPI X (formerly Twitter)](https://x.com/SharpAPI)
- [SharpAPI YouTube](https://www.youtube.com/@SharpAPI)
- [SharpAPI Vimeo](https://vimeo.com/SharpAPI)
- [SharpAPI LinkedIn](https://www.linkedin.com/products/a2z-web-ltd-sharpapicom-automate-with-aipowered-api/)
- [SharpAPI Facebook](https://www.facebook.com/profile.php?id=61554115896974)

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance82

Actively maintained with recent releases

Popularity25

Limited adoption so far

Community22

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~77 days

Total

7

Last Release

89d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2b500dd3d9b470b50b1ed911cd24a6fdcce51dd97dceb4f97879f727a14495a8?d=identicon)[dawid-makowski](/maintainers/dawid-makowski)

---

Top Contributors

[![makowskid](https://avatars.githubusercontent.com/u/6271194?v=4)](https://github.com/makowskid "makowskid (13 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sharpapi-php-core/health.svg)

```
[![Health](https://phpackages.com/badges/sharpapi-php-core/health.svg)](https://phpackages.com/packages/sharpapi-php-core)
```

###  Alternatives

[statamic/cms

The Statamic CMS Core Package

4.8k3.2M720](/packages/statamic-cms)[ashallendesign/laravel-exchange-rates

A wrapper package for interacting with the exchangeratesapi.io API.

485677.8k](/packages/ashallendesign-laravel-exchange-rates)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[laravel/cashier-paddle

Cashier Paddle provides an expressive, fluent interface to Paddle's subscription billing services.

264778.4k3](/packages/laravel-cashier-paddle)[vluzrmos/slack-api

Wrapper for Slack.com WEB API.

102589.1k3](/packages/vluzrmos-slack-api)[smodav/mpesa

M-Pesa API implementation

16363.7k1](/packages/smodav-mpesa)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
