承接 halilcosdu/laravel-replicate 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

halilcosdu/laravel-replicate

Composer 安装命令:

composer require halilcosdu/laravel-replicate

包简介

Laravel client for Replicate predictions, files, models, trainings, and signed webhooks

README 文档

README

Latest Version on Packagist PHP Version License Total Downloads

A Laravel-native client for the Replicate HTTP API. Run community, official, and deployment models; manage models and trainings; upload files; and authenticate incoming webhooks using Laravel's familiar HTTP client and facade APIs.

Highlights

  • Laravel 11, 12, and 13 support, including PHP 8.5 on supported framework versions.
  • Predictions for community models, official models, and deployments.
  • Sync mode, prediction deadlines, filters, and cursor pagination.
  • Multipart uploads and resource management through Replicate's Files API.
  • HMAC-SHA256 webhook verification with timestamp and key-rotation support.
  • Native Illuminate\Http\Client\Response results with accurate IDE return types.
  • Hermetic HTTP tests, PHPStan analysis, and a full version matrix in CI.

Requirements

Laravel Supported PHP versions Framework status in 2026
11.x 8.2–8.4 Legacy compatibility; EOL
12.x 8.2–8.5 Security-supported
13.x 8.3–8.5 Actively supported

The matrix follows Laravel's official support policy. The package requires PHP ^8.2; PHP 8.5 is tested with Laravel 12 and 13. Laravel 11 is not paired with PHP 8.5 because that combination is not supported by the framework itself.

Laravel 11 reached end-of-life on March 12, 2026 and currently has upstream security advisories. Compatibility remains available for migration windows because it is an explicit target of this package, but new and internet-facing applications should use Laravel 12 or 13. Composer may report or block affected Laravel 11 dependency resolutions; do not suppress that warning in production without reviewing the advisories.

Installation

Install the package with Composer:

composer require halilcosdu/laravel-replicate

Laravel discovers the service provider and facade automatically. Publish the configuration only when you need to customize it:

php artisan vendor:publish --tag=replicate-config

Add your Replicate API token to .env:

REPLICATE_API_TOKEN=r8_your_token

The published configuration contains:

return [
    'api_token' => env('REPLICATE_API_TOKEN'),
    'api_url' => env('REPLICATE_API_URL', 'https://api.replicate.com/v1'),
    'webhook_secret' => env('REPLICATE_WEBHOOK_SECRET'),
    'webhook_tolerance' => (int) env('REPLICATE_WEBHOOK_TOLERANCE', 300),
];

Quick start

All API methods return Laravel's HTTP client Response, so throw(), json(), collect(), successful(), and the other standard response helpers are available.

use HalilCosdu\Replicate\Facades\Replicate;

$prediction = Replicate::createOfficialModelPrediction(
    owner: 'black-forest-labs',
    name: 'flux-schnell',
    data: [
        'input' => ['prompt' => 'A quiet library floating above Istanbul'],
    ],
)->throw()->json();

$predictionId = $prediction['id'];

Run a versioned community model through the generic predictions endpoint:

$response = Replicate::createPrediction([
    'version' => 'replicate/hello-world:version-id',
    'input' => ['text' => 'Laravel'],
]);

$prediction = $response->throw()->json();

Sync mode and deadlines

Prediction creation methods accept optional request headers. Prefer controls how long the HTTP request waits; Cancel-After controls the prediction's lifetime.

$response = Replicate::createOfficialModelPrediction(
    'black-forest-labs',
    'flux-schnell',
    ['input' => ['prompt' => 'Minimal geometric poster']],
    ['Prefer' => 'wait=30', 'Cancel-After' => '2m'],
);

$prediction = $response->throw()->json();

A sync request may still return starting or processing when the wait period expires. Retrieve its latest state with:

$prediction = Replicate::getPrediction($predictionId)->throw()->json();

Pagination and filters

List methods accept an optional query array and pass it directly to Replicate:

$page = Replicate::listPredictions([
    'created_after' => now()->subDay()->toIso8601String(),
    'source' => 'web',
    'cursor' => $cursor,
])->throw()->json();

This is supported by listCollections, listDeployments, listFiles, listModels, listModelExamples, listPredictions, and listTrainings.

Files API

Upload a string or readable PHP stream as multipart content. Metadata is encoded as a JSON multipart field.

$stream = fopen(storage_path('app/training-images.zip'), 'rb');

throw_if($stream === false, RuntimeException::class, 'Unable to open the upload.');

try {
    $file = Replicate::createFile(
        contents: $stream,
        filename: 'training-images.zip',
        contentType: 'application/zip',
        metadata: ['dataset' => 'product-photography'],
    )->throw()->json();
} finally {
    fclose($stream);
}

Manage uploaded resources with listFiles(), getFile($id), deleteFile($id), and downloadFile($id, $owner, $expiry, $signature).

Webhook verification

Never trust a webhook payload before verifying its signature. First retrieve your signing secret once, then store it securely rather than requesting it for every delivery:

$secret = Replicate::defaultSecret()->throw()->json('key');
REPLICATE_WEBHOOK_SECRET=whsec_your_signing_secret

Verify the untouched Laravel request before processing its JSON body:

use HalilCosdu\Replicate\Facades\Replicate;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

Route::post('/webhooks/replicate', function (Request $request) {
    abort_unless(Replicate::verifyWebhook($request), 401);

    $prediction = $request->json()->all();

    // Persist output, dispatch a job, or continue a model pipeline...

    return response()->noContent();
});

verifyWebhook() validates the webhook-id, webhook-timestamp, and every v1 candidate in webhook-signature using constant-time comparison. Requests outside the configured 300-second tolerance are rejected to reduce replay risk. You may override the secret and tolerance for a specific request:

$valid = Replicate::verifyWebhook($request, $secret, tolerance: 120);

Remember to exempt the webhook route from CSRF protection and make processing idempotent because Replicate may retry a delivery.

API reference

Account, discovery, and hardware

Replicate::account();
Replicate::search(string $query, ?int $limit = null);
Replicate::listHardware();

Collections

Replicate::listCollections(array $query = []);
Replicate::getCollection(string $slug);

Deployments

Replicate::listDeployments(array $query = []);
Replicate::createDeployment(array $data);
Replicate::getDeployment(string $owner, string $name);
Replicate::updateDeployment(string $owner, string $name, array $data);
Replicate::deleteDeployment(string $owner, string $name);
Replicate::createDeploymentPrediction(string $owner, string $name, array $data, array $headers = []);

Files

Replicate::createFile(mixed $contents, string $filename, string $contentType = 'application/octet-stream', array $metadata = []);
Replicate::listFiles(array $query = []);
Replicate::getFile(string $id);
Replicate::deleteFile(string $id);
Replicate::downloadFile(string $id, string $owner, int $expiry, string $signature);

Models and versions

Replicate::listModels(array $query = []);
Replicate::createModel(array $data);
Replicate::getModel(string $owner, string $name);
Replicate::updateModel(string $owner, string $name, array $data);
Replicate::deleteModel(string $owner, string $name);
Replicate::getModelReadme(string $owner, string $name);
Replicate::searchModels(string $query);
Replicate::listModelExamples(string $owner, string $name, array $query = []);
Replicate::listModelVersions(string $owner, string $name);
Replicate::getModelVersion(string $owner, string $name, string $version);
Replicate::deleteModelVersion(string $owner, string $name, string $version);

Predictions

Replicate::createPrediction(array $data, array $headers = []);
Replicate::createOfficialModelPrediction(string $owner, string $name, array $data, array $headers = []);
Replicate::getPrediction(string $id);
Replicate::listPredictions(array $query = []);
Replicate::cancelPrediction(string $id);

The legacy createModelPrediction($owner, $name, $version, $data, $headers) method remains available for backward compatibility. Replicate's official-model endpoint does not accept a version path parameter, so new code should use createOfficialModelPrediction().

Trainings

Replicate::listTrainings(array $query = []);
Replicate::createTraining(string $owner, string $name, string $version, array $data);
Replicate::getTraining(string $id);
Replicate::cancelTraining(string $id);

Webhooks

Replicate::defaultSecret();
Replicate::verifyWebhook(Request $request, ?string $secret = null, ?int $tolerance = null);

Error handling

The client does not hide API failures. Use Laravel's standard response helpers according to your application's needs:

$response = Replicate::getPrediction($predictionId);

if ($response->tooManyRequests()) {
    // Release the job using Retry-After or your own backoff policy.
}

$prediction = $response->throw()->json();

See Laravel's HTTP client documentation for response inspection, retries, exceptions, and test fakes.

Testing and quality

composer test
composer analyse
vendor/bin/pint --test

The GitHub Actions matrix covers supported Laravel 11–13 and PHP 8.2–8.5 combinations with both lowest and stable dependency sets.

Changelog

See CHANGELOG.md for release notes.

Security

Please follow SECURITY.md to report vulnerabilities privately.

Credits

License

Laravel Replicate is open-source software licensed under the MIT license.

halilcosdu/laravel-replicate 适用场景与选型建议

halilcosdu/laravel-replicate 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11.24k 次下载、GitHub Stars 达 53, 最近一次更新时间为 2024 年 04 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「API-Client」 「webhooks」 「ai」 「replicate」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 halilcosdu/laravel-replicate 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 halilcosdu/laravel-replicate 我们能提供哪些服务?
定制开发 / 二次开发

基于 halilcosdu/laravel-replicate 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 11.24k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 53
  • 点击次数: 12
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 53
  • Watchers: 1
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-04-27