PHP SDK

The official PHP client for the Synthient API: IP lookups, account details, real-time feed streams, and Parquet exports.

Getting started

1. Install

composer require synthient/synthient-php

Composer also installs Guzzle, which the SDK uses to send requests.

Requires a 64-bit build of PHP 8.3 or later, and Guzzle 7.15.2 or later, or 8.0.1 or later. Guzzle uses the cURL extension when it is available. With the default HTTP client, streams and downloads go through Guzzle's PHP stream handler, so they need the allow_url_fopen ini setting, which is on by default. The client is Synthient\Client. Response models live in Synthient\Model, stream events in Synthient\Event, value sets in Synthient\Enum, and exceptions in Synthient\Exception. Unlike the other SDKs, this package has no gRPC schema fetcher.

This SDK follows Semantic Versioning. Breaking changes ship only in a new major version, so the ^1.0 constraint that composer require adds accepts every compatible release.

2. Make your first lookup

Each lookup costs one credit.

<?php

declare(strict_types=1);

require __DIR__ . '/vendor/autoload.php';

$client = new Synthient\Client();

$info = $client->lookupIp('8.8.8.8');
if ($info->network !== null) {
    echo $info->network->isp, ' ', $info->network->type, "\n";
}
if ($info->intelligence !== null) {
    echo $info->intelligence->riskScore, ' ', implode(', ', $info->intelligence->categories), "\n";
}

With no arguments, the client reads the API key from the SYNTHIENT_API_KEY environment variable. IpInfo::$network, IpInfo::$location, and IpInfo::$intelligence are null when the API has no data for that section, so check them before reading their properties.

3. Check your credits

account() returns the account that owns the API key, including its scopes and remaining lookup credits. It costs no credits.

$account = $client->account();
echo $account->email, ' ', $account->organization->name, ' ', implode(', ', $account->scopes), "\n";
echo $account->lookupQuota->credits, ' credits, resetting in ', $account->lookupQuota->resetsIn, " seconds\n";

4. Handle errors

Every error the SDK throws at runtime extends SynthientException, which extends \RuntimeException. Invalid arguments throw \InvalidArgumentException instead, before any request is made.

use Synthient\Exception\ApiException;

try {
    $info = $client->lookupIp('8.8.8.8');
    echo $info->ip, "\n";
} catch (ApiException $e) {
    if ($e->statusCode === 402) {
        echo "out of lookup credits\n";
    } elseif ($e->statusCode === 429 && $e->retryAfter !== null) {
        echo "rate limited, retry after {$e->retryAfter} seconds\n";
    } elseif ($e->statusCode === 429) {
        echo "monthly request budget spent\n";
    } else {
        echo "request {$e->requestId} failed: ", $e->detail ?? $e->title, "\n";
    }
}

5. Keep going

  • Client: create and configure the client, and read the metadata of every API response.
  • Lookups: look up IP addresses and check your account and the API's health.
  • Feeds: stream each feed's real-time events and download its hourly and daily Parquet exports.
  • Errors and retries: how failed requests are reported, and which requests are retried.
  • Types: the fields of every response and event type, and the enumerations they use.

gRPC schema

This package has no gRPC schema fetcher. To get the protobuf schema of the Synthient gRPC API, use the gRPC schema fetcher of the Node, Python, Java, C#, Go, Rust, or Ruby SDK, or any gRPC reflection client such as grpcurl.

grpcurl -H "x-api-key: $SYNTHIENT_API_KEY" -protoset-out synthient.protoset grpc.synthient.com:443 describe synthient.v1.SynthientService

-protoset-out writes the service and every message it uses to synthient.protoset as a FileDescriptorSet.