PHP SDK · Feature

Errors, Rate Limits & Usage

The client throws a typed exception for every HTTP failure and never retries — you stay in control of back-off. It also exposes your current quota so you can throttle before you hit a limit, and aggregate usage for dashboards and alerts.

Trusted by thousands of businesses
Fast JSON API responses
Real-time validation
Simple integration, SDKs & examples
What it does

Predictable failures, no hidden retries

Network calls fail — keys expire, quotas run out, servers hiccup. The SDK turns each HTTP status into a specific exception class you can catch, and deliberately leaves retry policy to you, so a burst of failures can't silently multiply your request volume. When you do hit a rate limit, the exception tells you exactly when the quota resets.

Prerequisites

1

Catch typed exceptions

Every exception extends IpApiError, which carries $statusCode and the raw response $body. Catch the specific subclass you care about.

<?php

use IpApiIo\Client;
use IpApiIo\IpApiError;
use IpApiIo\AuthenticationError;
use IpApiIo\RateLimitError;
use IpApiIo\InvalidRequestError;
use IpApiIo\ServerError;

$client = new Client(apiKey: getenv('IP_API_IO_KEY'));

try {
    $info = $client->lookup('8.8.8.8');
    echo $info['location']['country'];
} catch (RateLimitError $e) {
    echo "quota hit — resets at {$e->reset}";
} catch (AuthenticationError $e) {
    echo 'check your API key';
} catch (InvalidRequestError $e) {
    echo 'bad request: ', $e->getMessage();
} catch (ServerError $e) {
    echo 'ip-api.io is having trouble, try later';
} catch (IpApiError $e) {
    echo "error {$e->statusCode}: ", $e->getMessage();
}
2

Handle rate limits with RateLimitError

On HTTP 429 the client throws RateLimitError, parsed from the x-ratelimit-* headers. Because the client never retries, reset tells you when to.

try {
    $client->lookup('8.8.8.8');
} catch (RateLimitError $e) {
    echo $e->limit;      // your quota for the window
    echo $e->remaining;  // requests left (0 here)
    echo $e->reset;      // unix timestamp when quota renews
    $wait = $e->reset - time();
    // schedule a retry after $wait seconds instead of hammering the API
}
3

Check quota proactively with rateLimit

Read your current limits without triggering a 429, so you can throttle in advance.

$rl = $client->rateLimit();

echo $rl['plan_name'];
echo $rl['ip_api']['remaining'], ' / ', $rl['ip_api']['limit'];
echo $rl['email_api']['usage_percent'], '% used';
echo $rl['next_renewal_date'];
4

Account usage with usageSummary

Aggregate usage for the current period — handy for dashboards and internal alerts.

$usage = $client->usageSummary();

echo $usage['totalRequests'], ' ', $usage['successfulRequests'];
echo $usage['rateLimitedRequests'], ' ', $usage['quotaConsumed'];
echo $usage['periodStart'], ' -> ', $usage['periodEnd'];
Reference

Exception taxonomy

ExceptionHTTP statusMeaning
AuthenticationError401, 403Missing or invalid API key
RateLimitError429Quota exhausted; exposes limit, remaining, reset
InvalidRequestError400, 404, 422Malformed input or unknown resource
ServerError5xxip-api.io server-side failure
IpApiErrorotherBase / fallback (carries statusCode, body)
FAQ

Frequently asked questions

How do I handle errors from the ip-api.io SDK in PHP?

Wrap calls in try/catch and catch the typed subclass: AuthenticationError (401/403), RateLimitError (429), InvalidRequestError (400/404/422), ServerError (5xx), or the base IpApiError. All live in the IpApiIo namespace.

Does the SDK retry failed requests automatically?

No. The client never retries — you stay in control of back-off. On a 429, RateLimitError::$reset gives the unix timestamp when your quota renews, so you can schedule a retry instead of hammering the API.

How do I check my remaining quota before hitting a limit?

Call $client->rateLimit(). It returns plan_id, plan_name, and ip_api / email_api blocks with limit, remaining, used and usage_percent, plus interval_seconds and next_renewal_date.

What does RateLimitError expose?

RateLimitError is parsed from the x-ratelimit-* response headers and exposes $e->limit (quota for the window), $e->remaining (requests left), and $e->reset (unix timestamp when quota renews). Use reset to compute how long to wait before retrying.

Start building with the ip-api.io PHP SDK

Run composer require ip-api-io/ipapi-php, drop in your free API key, and ship in minutes — one zero-dependency client for geolocation, fraud detection, and email validation.

Need support?

Explore how IP-API.io can enhance your security, provide robust bot protection, and improve IP geolocation accuracy for your applications.

Contact Support

Found a bug in the SDK?

The ip-api-io/ipapi-php package is open source. Open an issue or pull request on GitHub and we'll take a look.

Open on GitHub