PHP code example of runapi-ai / grok-imagine

1. Go to this page and download the library: Download runapi-ai/grok-imagine library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

runapi-ai / grok-imagine example snippets




unApi\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 = $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',
]);