# PHP SDK [View original](https://ittybit.com/sdks/php) ## Requirements Use of the Ittybit PHP SDK requires: * PHP ^8.1 *** ## Installation Use Composer to configure and install the Ittybit PHP SDK: ```shell composer require ittybit/ittybit ``` *** ## Usage ```php use Ittybit\IttybitClient; $ittybit = new IttybitClient( token: "ITTYBIT_API_KEY" ); // Example usage with automations $response = $ittybit->automations->create(); ``` *** ## Instantiation To get started with the Ittybit SDK, instantiate the `IttybitClient` class as follows: ```php use Ittybit\IttybitClient; $ittybit = new IttybitClient( token: "ITTYBIT_API_KEY" ); ``` *** ### Configuration Options The SDK allows you to configure various options when creating the client: ```php use Ittybit\IttybitClient; use GuzzleHttp\Client; $ittybit = new IttybitClient( token: "ITTYBIT_API_KEY", options: [ 'baseUrl' => 'https://api.ittybit.com', // Custom base URL 'client' => new Client(), // Custom HTTP client 'maxRetries' => 3, // Maximum number of retries 'timeout' => 30.0, // Request timeout in seconds 'headers' => [ // Additional headers 'X-Custom-Header' => 'value' ] ] ); ``` *** ## Available Clients The SDK provides several specialized clients for different API areas: ```php $ittybit->automations; // AutomationsClient $ittybit->files; // FilesClient $ittybit->media; // MediaClient $ittybit->tasks; // TasksClient $ittybit->signatures; // SignaturesClient ``` *** ## Exception Handling When the API returns a non-success status code (4xx or 5xx response), an exception will be thrown: ```php try { $ittybit->files->create([ 'url' => 'https://example.com/video.mp4', 'filename' => 'video.mp4', 'folder' => 'example', ]); } catch (\Exception $e) { echo 'Error: ' . $e->getMessage() . "\n"; // Handle the error appropriately } ``` *** ## Advanced ### Custom HTTP Client This SDK is built to work with any HTTP client that implements Guzzle's `ClientInterface`. By default, if no client is provided, the SDK will use Guzzle's default HTTP client. However, you can pass your own client that adheres to `ClientInterface`: ```php use GuzzleHttp\Client; use Ittybit\IttybitClient; $customClient = new Client([ 'timeout' => 5.0, ]); $ittybit = new IttybitClient( token: "ITTYBIT_API_KEY", options: [ 'client' => $customClient ] ); ```