This is a simple PHP client for the Replicate. It covers the main prediction functionalities of the Replicate HTTP API.
- PHP 8.1
Install the package with composer:
composer require replicate/replicate-php
Get your API token from your Replicate account.
$replicate = new Replicate('token');
try {
$prediction = $replicate->createPrediction(
version: 'v1',
input: ['text' => 'foo'],
);
echo $prediction->id; // take a look at Prediction data class for available fields
} catch (ReplicateException|ReplicateWebhookInputException|ResponseException $e) {
echo $e->getMessage();
}
try {
$prediction = $this->replicate->prediction(predictionId: 'prediction-id');
echo $prediction->id;
} catch (ReplicateException|ResponseException $e) {
// log error
}
try {
$predictions = $this->replicate->predictions();
// if you would like to paginate.
if ($predictions->next) {
// extract the cursor from the next url
$nextUrl = $predictions->next;
$query = parse_url($nextUrl, PHP_URL_QUERY);
parse_str($query, $params);
$cursor = $params['cursor'];
$predictions = $this->replicate->predictions(cursor: $cursor);
// $predictions->results;
}
// take a look at the Predictions data class for available fields.
} catch (ReplicateException|ResponseException $e) {
// log error
}
try {
$response = $this->replicate->cancelPrediction(predictionId: 'prediction-id');
echo $response->status;
} catch (ReplicateException|ResponseException $e) {
// log error
}
composer install
composer test
MIT