This repository contains a PHP SDK for the BHuman API. BHuman.ai is an awesome AI-based video generation platform. This PHP SDK simplifies the interaction with the BHuman API, providing a structured and object-oriented approach to create dynamic and personalized videos with ease.
You can find the offical BHuman API docs with examples here: https://github.com/bhuman-ai/public_api
- Simple and easy to use PHP classes.
- Object-oriented approach.
- Supports all major functionalities offered by the BHuman API including:
- Retrieving video instances
- Getting a specific video instance
- Generating a video
- Fetching generated videos
- Fetching workspace settings
- Fetching products from the store
- Using a product
- Fetching BHuman store settings
- Clone the repository to your local machine or server.
- Include the SDK in your PHP script:
require_once("./sdk.php");
- Initialize the SDK with your BHuman API key and secret:
$api_key_id = "your_api_key_id";
$api_key_secret = "your_api_key_secret";
$bh = new BHumanSDK($api_key_id, $api_key_secret);
- Now you can make calls to the BHuman API. See the provided examples for more details.
To fetch video instances, we use the getVideoInstances
function. This function returns an array of video instances.
$video_instances = $bh->getVideoInstances();
To get a specific video instance you can use the getVideoInstance
function. This function requires an instance ID e.g.
$instance_id = "7d859e18-dc89-446f-9718-9533bb178a75";
$video_instance = $bhuman->getVideoInstance($instance_id);
To generate a video, we need an instance ID, a list of names, a list of variables, and a callback URL. Here is an example of the generateVideo
class:
$instance_id = "7d859e18-dc89-446f-9718-9533bb178a75";
$names = [["Don", "Apple"], ["James", "Google"]];
$variables = ["name", "company"];
$video = $bh->generateVideo($instance_id, $names, $variables);
To get a generated video, we’ll use the getGeneratedVideos
class. This requires a instance ID as well.
$generated_videos = $bhuman->getGeneratedVideos($instance_id);
To get your workspace setting we can use the getWorkspace
class.
$workspace = $bhuman->getWorkspace();
To get the products from the store with the getProducts
class.
$products = $bhuman->getProducts();
To use a product in the BHuman store we can use the useProduct
class.
$product_id = "example_product_id";
$workspace_id = "example_workspace_id";
$product = $bhuman->useProduct($product_id, $workspace_id);
To get the store setting in your BHuman account, you can use the getStoreSettings
class.
$store_settings = $bhuman->getStoreSettings();
You can find usage examples and a detailed explnation on how to use each SDK class on my blog post: https://henryreith.co/bhuman-ai-api-php-sdk/
Feel free to fork this repository, make your changes, and submit a pull request. We're always open to improvements and new features!
If you have any issues or questions, feel free to open an issue in this repository.