PHPackages                             zzhenping/replicate-client - 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. zzhenping/replicate-client

ActiveLibrary[API Development](/categories/api)

zzhenping/replicate-client
==========================

这是一个基于 Hyperf 框架封装的 PHP 客户端，用于调用 Replicate 的 AI 推理 API。支持同步推理、Webhook 通知、以及协程等待任务完成。

v1.0.0.0(1y ago)00MITPHPPHP &gt;=8.1

Since May 14Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Zzhenping/replicate-client)[ Packagist](https://packagist.org/packages/zzhenping/replicate-client)[ RSS](/packages/zzhenping-replicate-client/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (10)Versions (2)Used By (0)

Replicate Client for Hyperf
===========================

[](#replicate-client-for-hyperf)

这是一个基于 Hyperf 框架封装的 PHP 客户端组件，用于调用 [Replicate API](https://replicate.com/) 的 AI 推理 API。支持同步推理、Webhook 通知、以及协程等待任务完成。

---

✨ 功能概览

- 支持预测任务的创建与执行
- 支持同步模式调用（适合短时间运行的模型）
- 支持 Webhook 模式（适合异步回调）
- 支持协程阻塞等待任务完成（基于 Swoole）
- 支持任务取消、状态获取、任务列表

---

📦 安装
----

[](#-安装)

```
composer require zzhenping/replicate-client
```

🔧 快速生成配置文件
----------

[](#-快速生成配置文件)

```
php bin/hyperf.php vendor:publish zzhenping/replicate-client
```

🧩 使用示例 运行预测任务
-------------

[](#-使用示例-运行预测任务)

```
use Zzhenping\ReplicateClient\Prediction\Predictions;

class IndexController extends AbstractController
{

    public function __construct(protected Predictions $predictions){}

    public function index()
    {
        $result = $this->predictions->setWebhook()->run('models/black-forest-labs/flux-schnell/predictions', [
            "input" => [
                "prompt" => "black forest gateau cake spelling out the words 'FLUX SCHNELL', tasty, food photography, dynamic shot",
                "go_fast" => true,
                "megapixels"=> "1",
                "num_outputs"=> 1,
                "aspect_ratio"=> "1:1",
                "output_format"=> "webp",
                "output_quality"=> 80,
                "num_inference_steps"=> 4
            ]
        ]);
        return [
            'result' => $result
        ];
    }
}

```

🧩 方法说明
------

[](#-方法说明)

- withPool(string $poolName): 为不同的模型池创建独立的请求客户端。

```
$this->predictions->withPool('default')->run()
```

- setSync(): 使用同步模式（设置 Prefer: wait 请求头），适用于运行时间较短的任务。

```
$this->predictions->setSync()->run()
```

- setWebhook(bool $bool = true): 使用 Webhook，接收回调。

```
$this->predictions->setWebhook()->run()
```

---

- create(string $version, array $payload): 根据模型版本创建一个新的预测任务。

```
version: 模型版本 ID（从 Replicate 网站获取）
payload: 输入参数，如 prompt、图像 URL 等

```

---

- run(string $version, array $payload): 直接调用指定模型用最新的版本进行预测。

```
model: 路由路径，如 models/black-forest-labs/flux-schnell/predictions
payload: 输入参数

```

---

- get(string $id): 获取指定 ID 的预测任务状态。

---

- cancel(string $id): 取消指定 ID 的预测任务。

---

- coroutineWait(string $id): 协程阻塞等待任务完成，适用于要等待返回结果的预测。

```
\Swoole\Coroutine\run(function () use ($client) {
    $predictions = new Predictions($client);
    $response = $predictions->create('xxx', [
        "input" => [
            "image" => "xxx"
        ]
    ]);
    $result = $predictions->coroutineWait($response);
    $this->assertEquals($result['status'], 'succeeded');
});
```

📌 注意事项
------

[](#-注意事项)

若启用 Webhook 模式，请确保在初始化 ReplicateClient 时正确设置 webhook 地址。

协程等待功能依赖于 Swoole 环境，请确保开启协程支持。

建议同步模式仅用于运行时间不超过 60 秒的模型。

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance46

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

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

416d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/128675240?v=4)[zhanzhenping](/maintainers/Zzhenping)[@Zzhenping](https://github.com/Zzhenping)

---

Top Contributors

[![Zzhenping](https://avatars.githubusercontent.com/u/128675240?v=4)](https://github.com/Zzhenping "Zzhenping (1 commits)")

---

Tags

phphyperfreplicate

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/zzhenping-replicate-client/health.svg)

```
[![Health](https://phpackages.com/badges/zzhenping-replicate-client/health.svg)](https://phpackages.com/packages/zzhenping-replicate-client)
```

###  Alternatives

[hyperf/amqp

A amqplib for hyperf.

231.3M73](/packages/hyperf-amqp)[hyperf/http-server

A HTTP Server for Hyperf.

103.0M373](/packages/hyperf-http-server)[hyperf/swagger

A swagger library for Hyperf.

20371.1k7](/packages/hyperf-swagger)[hyperf/graphql

A GraphQL component for hyperf.

151.5k](/packages/hyperf-graphql)

PHPackages © 2026

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