atcipher/runware-php-sdk 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

atcipher/runware-php-sdk

Composer 安装命令:

composer require atcipher/runware-php-sdk

包简介

A lightweight, framework-agnostic PHP SDK for Runware's REST and WebSocket APIs.

README 文档

README

A lightweight, framework-agnostic PHP SDK for Runware — covering REST and WebSocket flows, with conveniences for image generation, uploads, model search, captioning, and async polling.

Status: Community SDK (unofficial). Built for PHP ≥ 8.1.

Installation

composer require atcipher/runware-php-sdk

You may also need to add the SDK via VCS until it’s on Packagist:

composer config repositories.atcipher-runware vcs https://github.com/atcipher/runware-php-sdk
composer require atcipher/runware-php-sdk:dev-main

Quickstart (REST)

use Atcipher\Runware\RunwareClient;

$client = new RunwareClient($_ENV['RUNWARE_API_KEY']);

// Text → Image
$res = $client->textToImage(
    prompt: 'a serene mountain lake at sunrise, ultra-detailed',
    model: 'runware:101@1',
    width: 1024,
    height: 1024,
    options: ['steps' => 30, 'CFGScale' => 7.5, 'numberResults' => 1]
);

// The API may return `data` as an array or an object depending on the endpoint.
// Handle both shapes:
$imageUrl = null;
if (isset($res['data'][0]['imageURL'])) {
    $imageUrl = $res['data'][0]['imageURL'];
} elseif (isset($res['data']['imageURL'])) {
    $imageUrl = $res['data']['imageURL'];
}
echo $imageUrl, PHP_EOL;

Image → Image (upload then transform)

// Upload a local file or public URL (data URI / base64 also supported)
$upload = $client->uploadImage('https://example.com/photo.jpg');
$seedUUID = $upload['data']['imageUUID'] ?? null;

$gen = $client->imageToImage(
    prompt: 'watercolor style',
    seedImage: $seedUUID,
    model: 'civitai:139562@297320',
    width: 1024,
    height: 1024,
    options: ['strength' => 0.7]
);

Model search

$models = $client->modelSearch([
    'search'       => 'photorealistic',
    'category'     => 'checkpoint',
    'architecture' => 'sdxl',
    'limit'        => 5,
]);

Caption an image (image → text)

$caption = $client->imageCaption($seedUUID, ['includeCost' => true]);
$text = $caption['data'][0]['text'] ?? ($caption['data']['text'] ?? '');

Async workflows (polling)

// Send your initial task with "deliveryMethod":"async" in the options.
// Later, poll:
$taskUUID = '...'; // UUID you used on the async task
$status = $client->getResponse($taskUUID);

WebSocket usage (optional)

use Atcipher\Runware\{Config};
use Atcipher\Runware\WebSocket\WebSocketClient;
use Atcipher\Runware\Support\Uuid;

$ws = new WebSocketClient(new Config($_ENV['RUNWARE_API_KEY']));

// Authenticate internally, then send a task
foreach ($ws->send([
    [
        'taskType'       => 'imageInference',
        'taskUUID'       => Uuid::v4(),
        'positivePrompt' => 'a cat',
        'width'          => 512,
        'height'         => 512,
        'model'          => 'civitai:102438@133677',
        'numberResults'  => 1,
    ]
]) as $frame) {
    // Each $frame is the decoded server message (array)
    // Inspect $frame['data'] for results.
}

// Keep-alive (avoid 120s idle close)
$pong = $ws->ping();

Notes

  • Auth: Either add Authorization: Bearer <API_KEY> or include an initial authentication task in the array payload (REST). For WebSockets, the first message must be authentication.
  • Endpoint: REST base is https://api.runware.ai/v1 (POST a JSON array of tasks). WS is wss://ws-api.runware.ai/v1.
  • Responses: Successful calls return { "data": [...] } most of the time; some utilities return { "data": { ... } }. Errors return { "errors": [...] } or { "error": { ... } }. The SDK normalizes nothing on purpose; you get the raw body.
  • UUIDs: Always include a unique taskUUID per task. The helpers do this for you.
  • Output: Pick outputType = URL (default), dataURI, or base64Data in imageInference tasks.
  • Async: Add "deliveryMethod":"async" to your task, then poll with getResponse.
  • WS resume: The server returns connectionSessionUUID after auth; reuse it when reconnecting.

Official docs used while building this SDK:

  • How to connect & authenticate (REST & WS)
  • Task Responses (getResponse)
  • Image Upload
  • Model Search
  • Image Inference (params for text→image / image→image / inpaint / outpaint)

License

MIT © Atcipher Ltd

atcipher/runware-php-sdk 适用场景与选型建议

atcipher/runware-php-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 30 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 08 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 atcipher/runware-php-sdk 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 30
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 9
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-25