Developers

Documentation

A technical guide to integrating leading AI models through Oblion's unified API.

PHP Image Editing Example

Below is a PHP demo showing how to call the image editing endpoint using Guzzle.

<?php
// Load the Composer autoloader
require_once 'vendor/autoload.php';

use GuzzleHttp\Client;

// Test variables
$model = "flux-kontext-max";
$queue = ['prompt' => 'Change it to blue'];
$correctedImg = 'scene1.png'; // Image file path

// Create the Guzzle HTTP client
$client = new Client();

// Build the multipart data array
$multipart = [
    [
        'name' => 'model',
        'contents' => $model
    ],
    [
        'name' => 'prompt',
        'contents' => $queue['prompt']
    ],
    [
        'name' => 'n',
        'contents' => '1'
    ],
    [
        'name' => 'size',
        'contents' => '1024x1024'
    ],
    [
        'name' => 'response_format',
        'contents' => 'b64_json'
    ]
];

// If an image file is provided, attach the file data
if ($correctedImg !== false && file_exists($correctedImg)) {
    $multipart[] = [
        'name' => 'image',
        'contents' => fopen($correctedImg, 'r'),
        'filename' => basename($correctedImg),
        'headers' => [
            'Content-Type' => 'image/png'
        ]
    ];
    echo "Image file attached: " . $correctedImg . "\n";
} else {
    echo "Warning: image file not found or path is incorrect: " . $correctedImg . "\n";
}

// Print request info
echo "Model: " . $model . "\n";
echo "Prompt: " . $queue['prompt'] . "\n";
echo "Image file: " . $correctedImg . "\n\n";

// Send the HTTP request
try {
    echo "Sending request to Oblion AI...\n";

    $response = $client->request('POST', 'https://api.oblion.io/v1/images/edits', [
        'headers' => [
            'Authorization' => 'Bearer YOUR_OBLION_API_KEY',
            'Accept' => 'application/json'
        ],
        'multipart' => $multipart,
        'timeout' => 60, // Increase timeout to 60 seconds
        'debug' => true // Enable debug mode to inspect request details
    ]);

    // Read the response
    $statusCode = $response->getStatusCode();
    $responseBody = $response->getBody()->getContents();

    echo "Request succeeded!\n";
    echo "Status code: " . $statusCode . "\n";
    echo "Response body:\n" . $responseBody . "\n";

    // Parse the JSON response
    $responseData = json_decode($responseBody, true);
    if (isset($responseData['data']) && isset($responseData['data'][0]['url'])) {
        echo "\nGenerated image URL: " . $responseData['data'][0]['url'] . "\n";
    }

} catch (GuzzleHttp\Exception\ClientException $e) {
    echo "Client error (4xx): " . $e->getMessage() . "\n";
    echo "Response body: " . $e->getResponse()->getBody()->getContents() . "\n";
} catch (GuzzleHttp\Exception\ServerException $e) {
    echo "Server error (5xx): " . $e->getMessage() . "\n";
    echo "Response body: " . $e->getResponse()->getBody()->getContents() . "\n";
} catch (Exception $e) {
    echo "Request failed: " . $e->getMessage() . "\n";
}