PHP code example of buble / sdk
1. Go to this page and download the library: Download buble/sdk 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/ */
buble / sdk example snippets
use Buble\BubleClient;
use Buble\Generations\CreateGenerationRequest;
$client = BubleClient::fromEnv();
$task = $client->generations()->create(
CreateGenerationRequest::make(
model: 'google/nano-banana',
mode: 'text_to_image',
prompt: 'A cinematic product photo of a matte black espresso cup',
)->withParam('aspect_ratio', '1:1')
->withParam('output_format', 'png')
);
$result = $client->generations()->wait($task['data']['id']);
echo $result['data']['result']['images'][0]['url'] . PHP_EOL;
use Buble\BubleClient;
use Buble\BubleClientOptions;
$client = new BubleClient(new BubleClientOptions(
apiKey: 'sk_...',
baseUrl: 'https://buble.ai',
timeout: 60.0,
));
$models = $client->mediaModels()->list(mediaType: 'video');
foreach ($models['data'] as $model) {
echo $model['model'] . PHP_EOL;
}
use Buble\Files\FileUpload;
use Buble\Files\UploadOptions;
use Buble\Generations\CreateGenerationRequest;
$uploaded = $client->files()->upload(
FileUpload::fromPath('reference.png', 'image/png'),
new UploadOptions(
fileType: 'image',
model: 'google/nano-banana',
mode: 'image_to_image',
),
);
$task = $client->generations()->create(new CreateGenerationRequest(
model: 'google/nano-banana',
mode: 'image_to_image',
prompt: 'Turn this reference into a polished ecommerce hero image.',
imageUrls: [$uploaded['data']['url']],
));
use Buble\WaitOptions;
$task = $client->generations()->create(
CreateGenerationRequest::make(
model: 'doubao/seedance-2.0-fast',
mode: 'text_to_video',
prompt: 'A slow cinematic shot of a futuristic train station at sunrise.',
)->withParam('duration', '8s')
->withParam('resolution', '720p')
->withParam('aspect_ratio', '16:9')
);
$result = $client->generations()->wait(
$task['data']['id'],
new WaitOptions(interval: 2.0, timeout: 600.0),
);
$app = $client->apps()->retrieve('video-background-remover');
print_r($app['data']['input_parameters']);
$task = $client->apps()->generations()->create('video-background-remover', [
'source_video' => ['https://example.com/source.mp4'],
'refine_foreground_edges' => true,
'subject_is_person' => true,
]);
$result = $client->apps()->generations()->wait('video-background-remover', $task['data']['id']);
$completion = $client->chat()->completions()->create([
'model' => 'openai/gpt-5.5',
'messages' => [
['role' => 'user', 'content' => 'Write a short launch summary.'],
],
'max_completion_tokens' => 800,
]);
echo $completion['choices'][0]['message']['content'];
foreach ($client->chat()->completions()->streamText([
'model' => 'openai/gpt-5.5',
'messages' => [
['role' => 'user', 'content' => 'Write one sentence at a time.'],
],
]) as $text) {
echo $text;
}
$message = $client->chat()->messages()->create([
'model' => 'openai/gpt-5.5',
'system' => 'You are concise.',
'messages' => [
['role' => 'user', 'content' => 'Summarize this release.'],
],
'max_tokens' => 800,
]);
$response = $client->chat()->gemini()->generateContent('openai/gpt-5.5', [
'contents' => [
[
'role' => 'user',
'parts' => [
['text' => 'Write a short launch summary.'],
],
],
],
]);
use Buble\Exception\ApiException;
use Buble\Exception\GenerationFailedException;
try {
$client->generations()->retrieve('task_id');
} catch (ApiException $error) {
echo $error->statusCode . PHP_EOL;
echo $error->apiCode . PHP_EOL;
echo $error->getMessage() . PHP_EOL;
print_r($error->details);
}
try {
$client->generations()->wait('task_id');
} catch (GenerationFailedException $error) {
print_r($error->task['error'] ?? null);
}
bash
BUBLE_API_KEY=sk_... php tools/live-smoke.php
bash
git subtree split --prefix=php -b php-release
git push [email protected] :bublehq/php-sdk.git php-release:main --force-with-lease
txt
https://github.com/bublehq/php-sdk