Select Page

An Easy-to-Use PHP SDK For The API

by | 7 June 2023

Artificial intelligence (AI) is changing how we go about marketing our businesses, and BHuman is at the forefront of this transformation. is an advanced AI-based video generation platform that allows us to create dynamic and personalised videos with ease. We’ve implemented the personalised videos BHuman creates in a number of places in our business during our customer’s buying journey, including in our abandon cart, onboarding and re-order sequence.

BHuman API is easy to use out of the box. However, BHuman’s API docs and examples are currently only written in Python & I wanted to integrate BHuman’s capabilities in a PHP stack. Plus we have a number of calls we want to make to the API so instead of having to rewrite code I decided to make an SDK for the BHuman API.

In this article, we will delve into a PHP SDK i have created for the BHuman API. This SDK speeds up the process of making HTTP requests to the API and provides you with a set of easy-to-use functions. It makes interacting with the BHuman API as simple as calling a method on an object.

Download The BHuman PHP SDK

Here is my full BHuman PHP SDK you need to include in your php script where you want to make calls to the BHuman API.

How To Use The BHuman SDK

Include the SDK

You can include the SDK in your script with a require once call:



Next, we need to initiate the BHuman PHP SDK. The SDK class requires your BHuman API key and secret for initialisation. These credentials are used to authenticate your requests to the BHuman API.

$api_key_id = "your_api_key_id";
$api_key_secret = "your_api_key_secret";
$bh = new BHumanSDK($api_key_id, $api_key_secret);

You can get your API credentials from your BHuman account.

Now we have our SDK initiated we can make calls to the BHuman API. I suggest checking the offical API doc’s to get more detail on the required and optional fields for each call.

Retrieving Video Instances

To fetch video instances, we use the getVideoInstances function. This function returns an array of video instances.

$video_instances = $bh->getVideoInstances();

Get a Specific Video Instance

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);

Generating a Video

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);

Get Generated Videos

To get a generated video, we’ll use the getGeneratedVideos class. This requires a instance ID as well.

$generated_videos = $bhuman->getGeneratedVideos($instance_id);

Get Workspace

To get your workspace setting we can use the getWorkspace class.

$workspace = $bhuman->getWorkspace();

Get Products

To get the products from the store with the getProducts class.

$products = $bhuman->getProducts();

Use A Product

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);

Get BHuman Store Settings

To get the store setting in your BHuman account, you can use the getStoreSettings class.

$store_settings = $bhuman->getStoreSettings();


In this article, I’ve provided a robust PHP SDK for the BHuman API. This SDK simplifies the interaction with the API, providing a structured and object-oriented approach. We have covered how to initialise the SDK, retrieve video instances, and generate a video using this SDK.

Now, it’s your turn. How have you been using BHuman and how will this SDK help speed the development process up for you? Share your thoughts and any queries in the comments section.

<a href="" target="_self">Henry Reith</a>

Henry Reith

CEO at Oh Crap. Creating & implementing processes to market businesses in less than 15 mins a day. 'marketing is a commodity, process is priceless'

Related Posts


Submit a Comment

Your email address will not be published. Required fields are marked *