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

ActiveLibrary[API Development](/categories/api)

soiposervices/replicate-php
===========================

A PHP client for the Replicate API

0.0.1(2y ago)0779MITPHPPHP ^8.1.0

Since Feb 8Pushed 2y agoCompare

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

READMEChangelogDependencies (6)Versions (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/d4be987f13628b9ef3020e2804b8f24fef939a6f864d9a957e3e9273b8991f68/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736f69706f73657276696365732f7265706c69636174652d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/soiposervices/replicate-php)[![GitHub Tests Action Status](https://github.com/SoipoServices/replicate-php/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/SoipoServices/replicate-php/actions/workflows/tests.yml)

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

[](#table-of-contents)

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

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

[](#-quick-start)

Install with composer.

```
composer require soiposervices/replicate-php
```

Create a new api instance.

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

If you enjoy this, please consider supporting SoipoServices:

[![Buy Me A Coffee](https://camo.githubusercontent.com/0cf29a542375e1a46e84d8bf5805a4e5c0a6ee98b6547ccdc0c55eed49d99c69/68747470733a2f2f63646e2e6275796d6561636f666665652e636f6d2f627574746f6e732f76322f64656661756c742d79656c6c6f772e706e67)](https://www.buymeacoffee.com/SoipoServices)

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

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

Unknown

Total

1

Last Release

829d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6cbf7b15aa95b4f96a243793fdcb6365420dda7a873cef7424384ea815aa80bf?d=identicon)[SoipoServices](/maintainers/SoipoServices)

---

Top Contributors

[![benbjurstrom](https://avatars.githubusercontent.com/u/12499093?v=4)](https://github.com/benbjurstrom "benbjurstrom (5 commits)")

---

Tags

phppackagereplicate

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/soiposervices-replicate-php/health.svg)](https://phpackages.com/packages/soiposervices-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)
