PHPackages                             d4ve-r/replicate-php - 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. d4ve-r/replicate-php

ActiveLibrary[API Development](/categories/api)

d4ve-r/replicate-php
====================

A PHP client for the Replicate API

08PHP

Since Jan 26Pushed 1y agoCompare

[ Source](https://github.com/D4ve-R/replicate-php)[ Packagist](https://packagist.org/packages/d4ve-r/replicate-php)[ RSS](/packages/d4ve-r-replicate-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

Replicate PHP client
====================

[](#replicate-php-client)

This is a framework-agnostic PHP client for [Replicate.com](https://replicate.com/) built on the amazing [Saloon v3](https://docs.saloon.dev/) 🤠 library. Use it to easily interact with machine learning models such as Stable Diffusion right from your PHP application.

[![Latest Version on Packagist](https://camo.githubusercontent.com/509e341fae2a42e89802e3e55d754ec617d09ed1db511917e3502320acd8bfea/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f643476652d722f7265706c69636174652d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/d4ve-r/replicate-php)[![GitHub Tests Action Status](https://camo.githubusercontent.com/3fa3e983dc0ff7b8dc3b1fcd891d759d5ed7304446a7711978c52dbb7630efd8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f643476652d722f7265706c69636174652d7068702f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/d4ve-r/replicate-php/actions?query=workflow%3tests+branch%3Amain)

Table of contents
-----------------

[](#table-of-contents)

- [Quick Start](https://github.com/d4ve-r/replicate-php#-quick-start)
- [Using with Laravel](https://github.com/d4ve-r/replicate-php#using-with-laravel)
- [Response Data](https://github.com/d4ve-r/replicate-php#response-data)
- [Webhooks](https://github.com/d4ve-r/replicate-php#webhooks)
- [Prediction Methods](https://github.com/d4ve-r/replicate-php#available-prediction-methods)
    - [get](https://github.com/d4ve-r/replicate-php#get)
    - [list](https://github.com/d4ve-r/replicate-php#list)
    - [create](https://github.com/d4ve-r/replicate-php#create)

🚀 Quick start
-------------

[](#-quick-start)

Install with composer.

```
composer require d4ve-r/replicate-php
```

Create a new api instance.

```
use D4veR\Replicate\Replicate;
...

$api = new Replicate(
    apiToken: $_ENV['REPLICATE_API_TOKEN'],
);
```

Then use it to invoke your model (or in replicate terms "create a prediction").

```
$version = 'db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf';
$input = [
    'model' => 'stable-diffusion-2-1',
    'prompt' => 'a photo of an astronaut riding a horse on mars',
    'negative_prompt' => 'moon, alien, spaceship',
    'width' => 768,
    'height' => 768,
    'num_inference_steps' => 50,
    'guidance_scale' => 7.5,
    'scheduler' => 'DPMSolverMultistep',
    'seed' => null,
];

$data = $api->predictions()->create($version, $input);
$data->id; // yfv4cakjzvh2lexxv7o5qzymqy
```

Note that the input parameters will vary depending on what version (model) you're using. In this example version [db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf](https://replicate.com/stability-ai/stable-diffusion/versions/db21e45d3f7023abc2a46ee38a23973f6dce16bb082a930b0c49861f96d1e5bf) is a Stable Diffusion 2.1 model optimized for speed.

Using with Laravel
------------------

[](#using-with-laravel)

Begin by adding your credentials to your services config file.

```
// config/services.php
'replicate' => [
    'api_token' => env('REPLICATE_API_TOKEN'),
],
```

Bind the `Replicate` class in a service provider.

```
// app/Providers/AppServiceProvider.php
public function register()
{
    $this->app->bind(Replicate::class, function () {
        return new Replicate(
            apiToken: config('services.replicate.api_token'),
        );
    });
}
```

And use anywhere in your application.

```
$data = app(Replicate::class)->predictions()->get($id);
```

Test your integration using Saloon's amazing [response recording](https://docs.saloon.dev/testing/recording-requests#fixture-path).

```
use Saloon\Laravel\Saloon; // composer require sammyjo20/saloon-laravel "^2.0"
...
Saloon::fake([
    MockResponse::fixture('getPrediction'),
]);

$id = 'yfv4cakjzvh2lexxv7o5qzymqy';

// The initial request will check if a fixture called "getPrediction"
// exists. Because it doesn't exist yet, the real request will be
// sent and the response will be recorded to tests/Fixtures/Saloon/getPrediction.json.
$data = app(Replicate::class)->predictions()->get($id);

// However, the next time the request is made, the fixture will
// exist, and Saloon will not make the request again.
$data = app(Replicate::class)->predictions()->get($id);
```

Response Data
-------------

[](#response-data)

All responses are returned as data objects. Detailed information can be found by inspecting the following class properties:

- [PredictionData](https://github.com/d4ve-r/replicate-php/blob/main/src/Data/PredictionData.php)
- [PredictionsData](https://github.com/d4ve-r/replicate-php/blob/main/src/Data/PredictionsData.php)

Webhooks
--------

[](#webhooks)

Replicate allows you to configure a webhook to be called when your prediction is complete. To do so chain `withWebhook($url)` onto your api instance before calling the `create` method. For example:

```
$api->predictions()->withWebhook('https://www.example.com/webhook')->create($version, $input);
$data->id; // la5xlbbrfzg57ip5jlx6obmm5y
```

### Verify Webhooks

[](#verify-webhooks)

You can verify request to your webhook route. Here's an example using Laravel:

```
use D4veR\Replicate\VerifyWebhook;

Route::get('/webhook', function (Request $request) {
    // ...
    $isValid = Replicate::webhooks()->verify($request, 'YOUR_WEBHOOK_SECRET');
    // ...
});
```

You can get you webhook secret, to verify the request.

```
$secret = $api->webhooks()->secret();
```

Available Prediction Methods
----------------------------

[](#available-prediction-methods)

### get()

[](#get)

Use to get details about an existing prediction. If the prediction has completed the results will be under the output property.

```
use D4veR\Replicate\Data\PredictionData;
...
$id = 'la5xlbbrfzg57ip5jlx6obmm5y'
/* @var PredictionData $data */
$data = $api->predictions()->get($id);
$data->output[0]; // https://replicate.delivery/pbxt/6UFOVtl1xCJPAFFiTB2tfveYBNRLhLmJz8yMQAYCOeZSFhOhA/out-0.png
```

### list()

[](#list)

Use to get a cursor paginated list of predictions. Returns an PredictionsData object.

```
use D4veR\Replicate\Data\PredictionsData
...

/* @var PredictionsData $data */
$data = $api->predictions()->list(
    cursor: '123', // optional
);

$data->results[0]->id; // la5xlbbrfzg57ip5jlx6obmm5y
```

### create()

[](#create)

Use to create a new prediction (invoke a model). Returns an PredictionData object.

```
use D4veR\Replicate\Data\PredictionData;
...
$version = '5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa';
$input = [
    'text' => 'Alice'
];

/* @var PredictionData $data */
$data = $api->predictions()
    ->withWebhook('https://www.example.com/webhook') // optional
    ->create($version, $input);
$data->id; // la5xlbbrfzg57ip5jlx6obmm5y
```

Credits
-------

[](#credits)

- [Ben Bjurstrom](https://github.com/benbjurstrom)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

16

—

LowBetter than 5% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity18

Early-stage or recently created project

 Bus Factor1

Top contributor holds 76% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/4bd4f3f80368e9e28696bd48aa5b6e7c80a590daa3893e78eaa02ae801e02ec1?d=identicon)[D4ve-R](/maintainers/D4ve-R)

---

Top Contributors

[![D4ve-R](https://avatars.githubusercontent.com/u/69651599?v=4)](https://github.com/D4ve-R "D4ve-R (19 commits)")[![benbjurstrom](https://avatars.githubusercontent.com/u/12499093?v=4)](https://github.com/benbjurstrom "benbjurstrom (6 commits)")

### Embed Badge

![Health badge](/badges/d4ve-r-replicate-php/health.svg)

```
[![Health](https://phpackages.com/badges/d4ve-r-replicate-php/health.svg)](https://phpackages.com/packages/d4ve-r-replicate-php)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[facebook/php-business-sdk

PHP SDK for Facebook Business

90821.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

74513.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

265103.1M454](/packages/google-gax)[google/common-protos

Google API Common Protos for PHP

173103.7M50](/packages/google-common-protos)

PHPackages © 2026

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