PHPackages                             c-delouvencourt/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. c-delouvencourt/replicate-php

ActiveLibrary[API Development](/categories/api)

c-delouvencourt/replicate-php
=============================

A PHP client for the Replicate API

0.2.0(11mo ago)03.1k↓35%MITPHPPHP ^8.1.0

Since Jan 26Pushed 11mo agoCompare

[ Source](https://github.com/c-delouvencourt/replicate-php)[ Packagist](https://packagist.org/packages/c-delouvencourt/replicate-php)[ GitHub Sponsors](https://github.com/benbjurstrom)[ RSS](/packages/c-delouvencourt-replicate-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (6)Versions (3)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/346340c655d3095be85c42ccd10b9f185793c349f99a3c02ddab7b51c640c1d8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f62656e626a75727374726f6d2f7265706c69636174652d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/benbjurstrom/replicate-php)[![GitHub Tests Action Status](https://camo.githubusercontent.com/7705ce6e1c5b30d29a21e0aa19c3b3d734e784bb77224b41b8e6414349b5107b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f62656e626a75727374726f6d2f7265706c69636174652d7068702f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/benbjurstrom/replicate-php/actions?query=workflow%3tests+branch%3Amain)

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

[](#table-of-contents)

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

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

[](#-quick-start)

Install with composer.

```
composer require benbjurstrom/replicate-php
```

Create a new api instance.

```
use BenBjurstrom\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/benbjurstrom/replicate-php/blob/main/src/Data/PredictionData.php)
- [PredictionsData](https://github.com/benbjurstrom/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
```

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 BenBjurstrom\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 BenBjurstrom\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 BenBjurstrom\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

32

—

LowBetter than 72% of packages

Maintenance50

Moderate activity, may be stable

Popularity21

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

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

Every ~489 days

Total

2

Last Release

354d ago

### Community

Maintainers

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

---

Top Contributors

[![benbjurstrom](https://avatars.githubusercontent.com/u/12499093?v=4)](https://github.com/benbjurstrom "benbjurstrom (6 commits)")[![cldt-fr](https://avatars.githubusercontent.com/u/26087186?v=4)](https://github.com/cldt-fr "cldt-fr (4 commits)")

---

Tags

phppackagereplicate

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/c-delouvencourt-replicate-php/health.svg)

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

###  Alternatives

[joisarjignesh/bigbluebutton

BigBlueButton Server API Library for Laravel

162145.5k1](/packages/joisarjignesh-bigbluebutton)[benbjurstrom/cloudflare-images-php

A PHP client for the Cloudflare Images API

1414.6k1](/packages/benbjurstrom-cloudflare-images-php)[sandorian/moneybird-api-php

Moneybird API client for PHP

127.3k](/packages/sandorian-moneybird-api-php)[marceloeatworld/falai-php

Professional PHP client for the fal.ai serverless AI platform

105.5k](/packages/marceloeatworld-falai-php)

PHPackages © 2026

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