styley/styley-php-sdk
Composer 安装命令:
composer require styley/styley-php-sdk
包简介
PHP SDK for the STYLEY AI Platform
README 文档
README
📥 Install PHP
Option 1: Install Using System Package Manager (Linux/Unix)
For Ubuntu/Debian:
sudo apt update sudo apt install php php-cli php-mbstring unzip curl
For CentOS/RHEL:
sudo yum install epel-release sudo yum install php php-cli php-mbstring unzip curl
Option 2: Install Using Homebrew (MacOS)
brew update brew install php
Option 3: Install PHP on Windows
-
Download the PHP installer:
-
Extract the files to C:\php.
-
Add PHP to System PATH:
- Open Control Panel → System → Advanced System Settings → Environment Variables.
- Edit the Path variable and add:
C:\php
- Restart your terminal to apply changes.
Verify Installation
Check if PHP is installed and working correctly.
php -v
Expected output:
PHP 8.1.2 (cli) (built: Jan 22 2024 13:05:35) ( NTS ) Copyright (c) The PHP Group Zend Engine v4.1.2, Copyright (c) Zend Technologies
If you see "command not found," double-check that PHP is installed and is in your PATH.
📦Install Composer
Composer is a dependency manager for PHP, like npm for JavaScript or pip for Python.
Option 1: Automatic Installation (Linux/MacOS)
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
Option 2: Install Using Installer (Windows)
-
Download the Composer installer: 👉 https://getcomposer.org/download/
-
Follow the on-screen instructions.
-
Verify Composer installation:
composer -v
Expected output:
Composer version 2.6.0 2024-04-10 00:13:15
Note: If you see "command not found," ensure Composer is installed and is in your PATH.
📁 Setup Project Workspace
Create a project directory:
mkdir php-sdk-project
cd php-sdk-project
Create a composer.json file in the project directory:
touch composer.json
Add the below content into composer.json
{
"name": "your-project-name",
"require": {}
}
📦 Installation
Install the Styley PHP SDK via Composer.
composer require styley/styley-php-sdk:dev-main
⚙️ Usage
This guide demonstrates how to initialize the SDK and interact with the available methods for deployments and models.
🌐 Set X_STYLEY_KEY Environment Variable
PowerShell
$env:X_STYLEY_KEY = "your-api-key-here"
Bash
export X_STYLEY_KEY="your-api-key-here"
🏆 Deployments
📤 Create Deployment
The Create Deployment method allows you to create a new deployment using a model name and arguments. It returns an output with a job_id that you can use to fetch the final results.
<?php require __DIR__ . '/vendor/autoload.php'; use \Styley\Client; use \Styley\Deployments\DeploymentInput; $client = new Client(); $createdeployment = $client->deployments->create( new DeploymentInput( "Background Removal", "844218fa-c5d0-4cee-90ce-0b42d226ac8d", [ "input" => "https://cdn.mediamagic.dev/media/799f2adc-384e-11ed-8158-e679ed67c206.jpeg" ] ) ); echo "Deployment created:\n"; echo json_encode($createdeployment, JSON_PRETTY_PRINT);
With Additional Parameters:
-
output_format (str, optional): Output format for the result.
- Images:
png,jpg,jpeg,gif,bmp,tiff,webp,ico - Videos:
mp4,webm,mkv,mov,avi
- Images:
-
output_width (int, optional): Output image width in pixels (positive integer)
-
output_height (int, optional): Output image height in pixels (positive integer)
Note: For image resizing, both width and height must be specified together. If only one dimension is provided, the original image size will be maintained.
<?php require __DIR__ . '/vendor/autoload.php'; use \Styley\Client; use \Styley\Deployments\DeploymentInput; $client = new Client(); $createdeployment = $client->deployments->create( new DeploymentInput( "Background Removal", "844218fa-c5d0-4cee-90ce-0b42d226ac8d", [ "input" => "https://cdn.mediamagic.dev/media/799f2adc-384e-11ed-8158-e679ed67c206.jpeg" ], "png", 1024, 1024 ) ); echo "Deployment created:\n"; echo json_encode($createdeployment, JSON_PRETTY_PRINT);
📄 Get Deployment By ID
Retrieve deployment details by ID.
<?php require __DIR__ . '/vendor/autoload.php'; use \Styley\Client; use \Styley\Deployments\Deployments; $client = new Client(); // Replace with actual deployment_id from deployment response $deployment = $client->deployments->getById("deployment_id"); echo "Deployment details retrieved:\n"; echo json_encode($deployment, JSON_PRETTY_PRINT);
📜 Get Job
Retrieve the status of a deployment job using its job ID.
<?php require __DIR__ . '/vendor/autoload.php'; use \Styley\Client; $client = new Client(); // Replace with actual job_id from Deployement response $jobStatus = $client->deployments->getJob("job_id"); echo "Job status retrieved:\n"; echo json_encode($jobStatus, JSON_PRETTY_PRINT);
⚡Models
📜List Models
Retrieve a list of all models available for deployments.
<?php require __DIR__ . '/vendor/autoload.php'; use \Styley\Client; $client = new Client(); $models = $client->models->list(); echo "Models retrieved:\n"; echo json_encode($models, JSON_PRETTY_PRINT);
🔍 Get Model By ID
Fetch model details using its model ID.
<?php require __DIR__ . '/vendor/autoload.php'; use \Styley\Client; $client = new Client(); $model = $client->models->getById("model_id"); echo "Model retrieved:\n"; echo json_encode($model, JSON_PRETTY_PRINT);
🔍 Get Model By Name
Fetch model details using its name.
<?php require __DIR__ . '/vendor/autoload.php'; use \Styley\Client; $client = new Client(); $model = $client->models->getByName("Virtual Staging Fast"); echo "Model retrieved:\n"; echo json_encode($model, JSON_PRETTY_PRINT);
📘 Summary of Available Methods
| Class | Method | Description |
|---|---|---|
| Deployments | create(payload) |
Create a new deployment. |
| Deployments | getById(id) |
Get deployment details by ID. |
| Deployments | getJob(jobID) |
Get the status of a deployment job. |
| Models | list() |
List all available models. |
| Models | getById(id) |
Get model details by model ID. |
| Models | getByName(name) |
Get model details by model name. |
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: proprietary
- 更新时间: 2025-04-21