Search by

runapi-ai / grok-imagine

runapi

RunAPI Grok Imagine Composer package for PHP applications

v0.1.6 2026-09-04 12:02 UTC

README

Packagist License

The Grok Imagine PHP SDK is the Composer package for Grok Imagine on RunAPI. Use it when your PHP application needs associative-array request bodies for image and video generation, task status lookup, polling helpers, file helpers, and consistent RunAPI errors.

Install

composer require runapi-ai/grok-imagine

Quick start

<?php

require __DIR__ . "/vendor/autoload.php";

use RunApi\GrokImagine\GrokImagineClient;

$client = new GrokImagineClient(); // reads RUNAPI_API_KEY

$task = $client->textToImage->create([
    'model' => 'grok-imagine-text-to-image',
    'prompt' => 'A precise product render on white marble',
]);

$status = $client->textToImage->get($task->id);

$result = $client->textToImage->run([
    'model' => 'grok-imagine-text-to-image',
    'prompt' => 'A serene mountain lake at dawn',
]);

echo reset($result->images)->url . PHP_EOL;

Edit with Image 2.0

Image 2.0 edits one to five source images directly. Provide the source URLs and output aspect ratio; the edit prompt is optional. The task-based source_task_id and mask_indices fields are no longer accepted by this request.

$edit = $client->editImage->create([
    'model' => 'grok-imagine-image-2-0',
    'source_image_urls' => ['https://cdn.runapi.ai/public/samples/input.png'],
    'aspect_ratio' => '1:1',
    'prompt' => 'Change the background to a sunset beach',
]);

Use create() to submit a task and return quickly, get() to fetch the latest task state, and run() when a script should create and poll until completion. In web request handlers, prefer create() plus webhook or later get() polling so a worker is not held open.

Returned file URLs are temporary. Download and store generated files in your own durable storage within the retention window.

All SDK exceptions inherit from RunApi\Core\Errors\RunApiException, including validation, authentication, rate limit, task failure, and task timeout errors.

Links

License

Licensed under the Apache License, Version 2.0.