PHPackages                             shorter/sdk - 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. shorter/sdk

ActiveLibrary[API Development](/categories/api)

shorter/sdk
===========

PHP SDK for the shorter.sh URL shortener

v1.0.0(1mo ago)00MITPHPPHP &gt;=8.1

Since Mar 15Pushed 1mo agoCompare

[ Source](https://github.com/ShorterSH/php-sdk)[ Packagist](https://packagist.org/packages/shorter/sdk)[ Docs](https://shorter.sh)[ RSS](/packages/shorter-sdk/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

shorter/sdk
===========

[](#shortersdk)

PHP SDK for the [shorter.sh](https://shorter.sh) URL shortener. Requires PHP &gt;=8.1 and Guzzle 7.

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

[](#installation)

```
composer require shorter/sdk
```

Quick Start
-----------

[](#quick-start)

```
use Shorter\Sdk\ShorterClient;

$client = new ShorterClient(
    api_key: 'sk_your_key_here', // or set SHORTER_API_KEY env var
);

// Shorten a URL
$result = $client->shorten('https://example.com');
echo $result->short_url;  // https://shorter.sh/xK9mP2

// List your URLs
$list = $client->list(page: 1, limit: 50);
foreach ($list->urls as $url) {
    echo "{$url->short_url} → {$url->original_url} ({$url->click_count} clicks)\n";
}
echo "Total clicks: {$list->total_clicks}\n";

// Delete a URL
$client->delete('xK9mP2');
```

Authentication
--------------

[](#authentication)

The API key is resolved in order:

1. `api_key` constructor parameter
2. `SHORTER_API_KEY` environment variable

The key must start with `sk_`.

Analytics
---------

[](#analytics)

```
// Overview analytics
$overview = $client->analytics->overview(
    start: '2024-01-01',
    end: '2024-01-31',
);
echo "Total clicks: {$overview->total_clicks}\n";
echo "Unique visitors: {$overview->unique_visitors}\n";

// Top URLs
foreach ($overview->top_urls as $url) {
    echo "{$url->short_url}: {$url->clicks} clicks\n";
}

// Breakdowns (country, device, browser, os, referrer)
foreach ($overview->country_breakdown as $item) {
    echo "{$item->value}: {$item->clicks} ({$item->percentage}%)\n";
}

// Per-URL analytics
$stats = $client->analytics->url('xK9mP2');
echo "Clicks: {$stats->summary->total_clicks}\n";
echo "Top country: {$stats->summary->top_country}\n";

// Per-URL with a specific breakdown dimension
$stats = $client->analytics->url('xK9mP2', dimension: 'country');
echo "Breakdown: {$stats->breakdown->dimension}\n";
foreach ($stats->breakdown->data as $item) {
    echo "  {$item->value}: {$item->clicks}\n";
}

// Detailed analytics (all breakdowns at once)
$detail = $client->analytics->url('xK9mP2', detail: true);
echo "Original URL: {$detail->url->original_url}\n";
foreach ($detail->breakdowns as $dimension => $breakdown) {
    echo "{$dimension}: {$breakdown->total} total\n";
}
```

### Dimensions

[](#dimensions)

Available breakdown dimensions: `country`, `device_type`, `browser`, `os`, `referrer_domain`, `language`

Error Handling
--------------

[](#error-handling)

```
use Shorter\Sdk\Exceptions\ValidationException;
use Shorter\Sdk\Exceptions\RateLimitException;
use Shorter\Sdk\Exceptions\NetworkException;
use Shorter\Sdk\Exceptions\ShorterException;

try {
    $client->shorten('not-a-url');
} catch (ValidationException $e) {
    echo $e->getMessage();  // "Invalid URL"
    echo $e->errorCode;     // "VALIDATION_ERROR"
    echo $e->status;        // 400
} catch (RateLimitException $e) {
    // Back off and retry
} catch (NetworkException $e) {
    // Connection failed
} catch (ShorterException $e) {
    // Any other API error
}
```

### Exception Classes

[](#exception-classes)

ClassStatusDefault Code`ValidationException`400`VALIDATION_ERROR``AuthenticationException`401`AUTH_REQUIRED``ForbiddenException`403`FORBIDDEN``NotFoundException`404`NOT_FOUND``RateLimitException`429`RATE_LIMITED``ServerException`500`SERVER_ERROR``NetworkException`0`NETWORK_ERROR`All extend `ShorterException`, which extends `\RuntimeException`.

Custom HTTP Client
------------------

[](#custom-http-client)

Inject your own Guzzle client for proxies, timeouts, or testing:

```
use GuzzleHttp\Client;

$client = new ShorterClient(
    api_key: 'sk_...',
    http_client: new Client([
        'timeout' => 10,
        'proxy' => 'http://proxy:8080',
    ]),
);
```

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

[](#requirements)

- PHP &gt;= 8.1
- Guzzle &gt;= 7.0

License
-------

[](#license)

MIT

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance90

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

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

Unknown

Total

1

Last Release

55d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b931389048e1a402acdf133cef6a4a6f1c89da59c84dc649b7ba5463533f5223?d=identicon)[VishnuSivadasVS](/maintainers/VishnuSivadasVS)

---

Top Contributors

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

---

Tags

apiphpshortershorter-urlurl-shortenersdkshort urlurl shortenerlink-shortenershorter.sh

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/shorter-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/shorter-sdk/health.svg)](https://phpackages.com/packages/shorter-sdk)
```

###  Alternatives

[openai-php/laravel

OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with the Open AI API

3.7k7.6M74](/packages/openai-php-laravel)[saloonphp/saloon

Build beautiful API integrations and SDKs with Saloon

2.4k9.6M467](/packages/saloonphp-saloon)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[php-opencloud/openstack

PHP SDK for OpenStack APIs. Supports BlockStorage, Compute, Identity, Images, Networking and Metric Gnocchi

2292.2M24](/packages/php-opencloud-openstack)[mailchimp/transactional

458.9M16](/packages/mailchimp-transactional)[resend/resend-php

Resend PHP library.

564.7M21](/packages/resend-resend-php)

PHPackages © 2026

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