Skip to content

Repository files navigation

FastPix PHP SDK

Packagist version Packagist downloads license PHP version

A robust, type-safe PHP SDK designed for seamless integration with the FastPix API platform.

The FastPix PHP SDK is a strongly typed PHP client for the FastPix video API. From any PHP application, you can upload and manage videos, run live streams and simulcasts, create and secure playback IDs, manage playlists and signing keys, retrieve video analytics, and use in-video AI features.

Supported PHP: 8.2 and later Package: fastpix/sdk Authentication: HTTP Basic Authentication Dependency management: Composer

📖 Docs: FastPix PHP SDK · 🚀 Free account: FastPix Dashboard

Jump to

Skip straight to a section without scrolling:

Get started API reference Help & more
Start here Available resources & operations FAQ
Before you begin Error handling Which SDK?
Install the FastPix SDK Server selection Development
Make your first API request Detailed usage Examples
Verify the integration

Start here

If you are using the FastPix PHP SDK for the first time, follow these steps in order:

  1. Check your PHP version
  2. Check your Composer installation
  3. Create a PHP project
  4. Install the FastPix SDK
  5. Verify the SDK installation
  6. Verify that PHP can load the SDK
  7. Configure authentication
  8. Verify that your credentials are set
  9. Initialize the FastPix client
  10. Make your first API request
  11. Capture the media ID
  12. Verify the integration

Do not skip the verification steps. If installation, dependency loading, authentication, client initialization, or the first API request fails, troubleshoot that problem before continuing.


Before you begin

Make sure you have:

  • PHP 8.2 or later.
  • Composer.
  • Internet access.
  • A FastPix account.
  • A FastPix Access Token.
  • A FastPix Secret Key.

FastPix uses HTTP Basic Authentication:

SDK value FastPix credential
username Access Token
password Secret Key

You can obtain your credentials from the FastPix Dashboard. Follow the Authentication with Basic Auth guide for information about obtaining your credentials.

Security: Never commit your Access Token or Secret Key to source control. Use environment variables or a secure credential-management system.


1. Check your PHP version

Run:

php --version

Output is similar to:

PHP 8.5.10 (cli) ...

The FastPix PHP SDK supports PHP 8.2 and later. If your PHP version is earlier than 8.2, install a supported PHP version before continuing.

You can also check the exact PHP version:

php -r 'echo PHP_VERSION, PHP_EOL;'

Expected output is similar to:

8.5.10

2. Check your Composer installation

The FastPix PHP SDK uses Composer to install and manage dependencies.

Run:

composer --version

Expected output is similar to:

Composer version 2.x.x

You can also verify where Composer is installed:

which composer

On Windows PowerShell:

Get-Command composer

If you see:

zsh: command not found: composer

Composer is not available in your shell. Install Composer before continuing.

Do not continue until this command works:

composer --version

3. Create a PHP project

Create a new directory for your FastPix application:

mkdir fastpix-php-demo
cd fastpix-php-demo

Initialize a Composer project:

composer init

Composer prompts you for project information. For a simple SDK test application, you can accept the default values.

When Composer asks:

Package name (<vendor>/<name>) [your-name/fastpix-php-demo]:

Press Enter to accept the suggested package name.

Do not enter ls at the package-name prompt. ls is a shell command, not a valid Composer package name.

When Composer asks whether you want to define dependencies interactively, you can select no. The FastPix SDK will be added explicitly in the next step.

After initialization, your project should contain:

fastpix-php-demo/
└── composer.json

4. Install the FastPix SDK

Install the FastPix PHP SDK with Composer:

composer require fastpix/sdk

Composer installs the SDK and its dependencies.

After installation, your project should contain:

fastpix-php-demo/
├── composer.json
├── composer.lock
└── vendor/

The vendor/ directory contains the installed SDK and Composer's autoloader.


5. Verify the SDK installation

Before writing application code, verify that Composer installed the FastPix SDK.

Run:

composer show fastpix/sdk

The output should identify the FastPix SDK package and installed version.

You can also search all installed packages:

macOS and Linux

composer show | grep fastpix

Windows PowerShell

composer show | Select-String fastpix

If fastpix/sdk is not listed, do not continue.

Run:

composer install

Then verify again:

composer show fastpix/sdk

6. Verify that PHP can load the SDK

Before configuring authentication or making an API request, verify that PHP can load the SDK.

Create a file named verify.php:

<?php
require 'vendor/autoload.php';

use FastPix\Sdk;

echo "FastPix SDK loaded successfully" . PHP_EOL;

Note: This example intentionally does not use declare(strict_types=1);. The declaration is not required for this SDK verification example and can introduce an unnecessary PHP parsing issue if any output or whitespace appears before the PHP opening tag.

Run:

php verify.php

Expected output:

FastPix SDK loaded successfully

This verifies that:

  • PHP can execute the application.
  • Composer's autoloader is available.
  • The FastPix SDK can be loaded.

If this command fails, do not continue to API requests. Check:

  • PHP 8.2 or later is installed.
  • composer require fastpix/sdk completed successfully.
  • vendor/autoload.php exists.
  • fastpix/sdk is listed by composer show.
  • You are running the command from the fastpix-php-demo directory.

7. Configure authentication

FastPix uses HTTP Basic Authentication.

The SDK expects:

username → Access Token
password → Secret Key

For local development, configure these values as environment variables.

macOS and Linux

export FASTPIX_USERNAME="<YOUR_ACCESS_TOKEN>"
export FASTPIX_PASSWORD="<YOUR_SECRET_KEY>"

Windows PowerShell

$env:FASTPIX_USERNAME="<YOUR_ACCESS_TOKEN>"
$env:FASTPIX_PASSWORD="<YOUR_SECRET_KEY>"

The SDK maps the environment variables as follows:

FASTPIX_USERNAME → Access Token
FASTPIX_PASSWORD → Secret Key

8. Verify that your credentials are set

Do not print the actual credential values.

macOS and Linux

Run:

if [ -n "$FASTPIX_USERNAME" ]; then
  echo "Access Token: set"
else
  echo "Access Token: missing"
fi

if [ -n "$FASTPIX_PASSWORD" ]; then
  echo "Secret Key: set"
else
  echo "Secret Key: missing"
fi

Expected output:

Access Token: set
Secret Key: set

If either value is reported as missing, set the corresponding environment variable before continuing.

Windows PowerShell

Run:

if ($env:FASTPIX_USERNAME) {
    Write-Output "Access Token: set"
} else {
    Write-Output "Access Token: missing"
}

if ($env:FASTPIX_PASSWORD) {
    Write-Output "Secret Key: set"
} else {
    Write-Output "Secret Key: missing"
}

Expected output:

Access Token: set
Secret Key: set

Security

Never:

  • Commit credentials to Git.
  • Put credentials directly into source code.
  • Include credentials in screenshots.
  • Print credentials in logs.
  • Include credentials in bug reports or support requests.
  • Log HTTP authentication headers in production.

Use environment variables or a secure credential-management system.


9. Initialize the FastPix client

Create or replace main.php with:

<?php
require 'vendor/autoload.php';

use FastPix\Sdk;
use FastPix\Sdk\Models\Components;

$username = getenv('FASTPIX_USERNAME');
$password = getenv('FASTPIX_PASSWORD');

if ($username === false || $username === '') {
    throw new RuntimeException('FASTPIX_USERNAME is not set');
}
if ($password === false || $password === '') {
    throw new RuntimeException('FASTPIX_PASSWORD is not set');
}

$sdk = Sdk\Fastpixsdk::builder()
    ->setSecurity(
        new Components\Security(
            username: $username,
            password: $password,
        )
    )
    ->build();

echo "FastPix client initialized" . PHP_EOL;

Run:

php main.php

Expected output:

FastPix client initialized

What this code does

Sdk\Fastpixsdk::builder() creates the FastPix SDK client. setSecurity() configures the credentials used for HTTP Basic Authentication. build() creates the configured SDK client.

Initializing the client does not make an API request. An API request occurs when you call an SDK operation such as:

$sdk->inputVideo->createMedia(...)

10. Make your first API request

The easiest way to verify the complete PHP SDK integration is to create media from a publicly accessible video URL.

FastPix provides a sample video URL:

https://static.fastpix.com/fp-sample-video.mp4

The PHP SDK exposes media creation through:

$sdk->inputVideo->createMedia()

Replace the contents of main.php with:

<?php
require 'vendor/autoload.php';

use FastPix\Sdk;
use FastPix\Sdk\Models\Components;

$username = getenv('FASTPIX_USERNAME');
$password = getenv('FASTPIX_PASSWORD');

if ($username === false || $username === '') {
    throw new RuntimeException('FASTPIX_USERNAME is not set');
}
if ($password === false || $password === '') {
    throw new RuntimeException('FASTPIX_PASSWORD is not set');
}

$sdk = Sdk\Fastpixsdk::builder()
    ->setSecurity(
        new Components\Security(
            username: $username,
            password: $password,
        )
    )
    ->build();

try {
    $request = new Components\CreateMediaRequest(
        inputs: [
            new Components\PullVideoInput(
                url: 'https://static.fastpix.com/fp-sample-video.mp4',
            ),
        ],
        metadata: [
            'source' => 'fastpix-php-demo',
        ],
    );

    $response = $sdk->inputVideo->createMedia(
        request: $request,
    );

    if ($response->statusCode >= 200 && $response->statusCode < 300) {
        $rawBody = (string) $response->rawResponse->getBody();
        $decoded = json_decode($rawBody, true);
        echo json_encode(
            $decoded ?? $rawBody,
            JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES,
        ) . PHP_EOL;
    } else {
        $errorPayload = $response->defaultError
            ?? $response->error
            ?? null;
        if ($errorPayload !== null) {
            echo json_encode(
                $errorPayload,
                JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES,
            ) . PHP_EOL;
        } else {
            echo json_encode(
                ['message' => 'No response data'],
                JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES,
            ) . PHP_EOL;
        }
        exit(1);
    }
} catch (\Exception $e) {
    echo json_encode(
        ['error' => $e->getMessage()],
        JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES,
    ) . PHP_EOL;
    exit(1);
}

Run:

php main.php

A successful request returns information about the newly created media asset. The response contains information similar to:

{
  "success": true,
  "data": {
    "id": "..."
  }
}

The exact response fields depend on the API response and installed SDK version.


11. Capture the media ID

The create-media response contains the unique ID assigned to the media asset.

The media ID is available at:

data.id

For example:

{
  "success": true,
  "data": {
    "id": "12345678-1234-1234-1234-123456789abc"
  }
}

The value of:

data.id

is the media_id.

Save the value for subsequent API operations:

MEDIA_ID=<value returned in data.id>

Do not confuse a media_id with a playback_id. They identify different resources and are used for different operations.


12. Verify the integration

At this point, you have verified the initial FastPix PHP SDK integration.

A successful create-media request confirms that:

  • PHP is installed and supported.
  • Composer is installed.
  • The PHP project is initialized.
  • The FastPix PHP SDK is installed.
  • Composer dependencies are available.
  • PHP can load the FastPix SDK.
  • Your FastPix credentials are configured.
  • The FastPix client can be initialized.
  • Your application can authenticate with the FastPix API.
  • Your application can create a media asset.
  • FastPix returns a media ID.

The completed workflow is:

FastPix PHP SDK workflow: a PHP application uses Composer to install the FastPix PHP SDK, which authenticates to the FastPix API over HTTP Basic Auth, creates a media asset, and receives a media ID (data.id).

At this point, the initial SDK integration is complete.

More examples: For additional runnable examples, see the examples/ directory in this repository.


Available Resources and Operations

Comprehensive PHP SDK for FastPix platform integration with full API coverage.

Media API

Upload, manage, and transform video content with comprehensive media management capabilities.

For detailed documentation, see FastPix Video on Demand Overview.

Input Video

Manage Videos

Playback

Playlist

Signing Keys

DRM Configurations

Live API

Stream, manage, and transform live video content with real-time broadcasting capabilities.

For detailed documentation, see FastPix Live Stream Overview.

Start Live Stream

  • Create Stream - Initialize new live streaming session with DVR mode support

Manage Live Stream

Live Playback

Simulcast Stream

Video Data API

Monitor video performance and quality with comprehensive analytics and real-time metrics.

For detailed documentation, see FastPix Video Data Overview.

Metrics

Views

Dimensions

Errors

  • List Errors - List playback errors for diagnostics and monitoring

Transformations

Transform and enhance your video content with powerful AI and editing capabilities.

In-Video AI Features

Enhance video content with AI-powered features including moderation, summarization, and intelligent categorization.

Media Clips

Subtitles

Media Tracks

Access Control

Format Support

Error Handling

All operations return a response object or throw an exception. By default, an API error will raise an Errors\APIException (or operation-specific error types).

Property Type Description
$message string The error message
$statusCode int The HTTP status code
$rawResponse ?\Psr\Http\Message\ResponseInterface The raw HTTP response
$body string The response content

Example

<?php

declare(strict_types=1);

require 'vendor/autoload.php';

use FastPix\Sdk;
use FastPix\Sdk\Models\Components;

$sdk = Sdk\Fastpixsdk::builder()
    ->setSecurity(
        new Components\Security(
            username: 'your-access-token',
            password: 'your-secret-key',
        )
    )
    ->build();

try {
    $request = new Components\CreateMediaRequest(
        inputs: [new Components\PullVideoInput(url: 'https://static.fastpix.com/fp-sample-video.mp4')],
        metadata: ['key1' => 'value1'],
    );

    $response = $sdk->inputVideo->createMedia(request: $request);

    if ($response->createMediaSuccessResponse !== null) {
        $rawBody = (string) $response->rawResponse->getBody();
        $decoded = json_decode($rawBody, true);
        echo json_encode($decoded, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
    }
} catch (\FastPix\Sdk\Models\Errors\APIException $e) {
    echo "Error: " . $e->getMessage() . "\n";
    echo "Status: " . $e->statusCode . "\n";
    echo "Body: " . $e->body . "\n";
}

Refer to the Errors tables in each operation’s SDK doc for possible exception types.

Server Selection

Override Server URL Per-Client

Override the default server by passing a URL when building the SDK:

<?php

declare(strict_types=1);

require 'vendor/autoload.php';

use FastPix\Sdk;
use FastPix\Sdk\Models\Components;

$sdk = Sdk\Fastpixsdk::builder()
    ->setServerUrl('https://api.fastpix.com/v1/')
    ->setSecurity(
        new Components\Security(
            username: 'your-access-token',
            password: 'your-secret-key',
        )
    )
    ->build();

FAQ

How do I install the FastPix PHP SDK? It is a Composer package - add fastpix/sdk to your composer.json and run composer update (or composer require fastpix/sdk). See Install the FastPix SDK.

How do I authenticate the SDK? FastPix uses Basic Auth: pass your access token as the username and your secret key as the password in Components\Security when building the client. See Initialize the FastPix client.

How do I upload a video in PHP? Create media from a URL or a direct upload through the input-video resource on the built $sdk. See Make your first API request and Available Resources and Operations.

How do I start a live stream? Use the Live API resources to create and manage streams, simulcasts, and live playback IDs. See Available Resources and Operations.

How do I create a secure playback ID? Generate playback IDs and manage signing keys and DRM configurations through the Media API resources. See Available Resources and Operations.

How do I get video analytics and metrics in PHP? The Video Data API exposes metrics, views, dimensions, and errors for quality-of-experience monitoring. See Available Resources and Operations.

How do I handle API errors? Wrap calls in try/catch; the SDK throws a typed error exposing the message, status code, and response body. See Error Handling.

How do I change the API base URL? Pass a server URL with setServerUrl(...) when building the client. See Server Selection.

Which PHP versions are supported? PHP 8.2 and above. See Before you begin.

Is the SDK strongly typed? Yes - it is a type-safe client generated from the FastPix API specification. See Development.

Which FastPix SDK should I use?

FastPix publishes a server SDK for every major backend language, each generated from the same API specification:

Language Repo Install
PHP (this repo) fastpix-php composer require fastpix/sdk
Python fastpix-python pip install fastpix-python
Go fastpix-go go get github.com/FastPix/fastpix-go
Java fastpix-java io.fastpix:sdk (Maven/Gradle)
C# / .NET fastpix-sdk-csharp dotnet add package Fastpix
Ruby fastpix-ruby gem install fastpixapi

To upload and play the media these SDKs create, use the FastPix browser libraries: web-uploads-sdk, react-web-uploader, and web-player-component. Browse everything in the FastPix organization.

Development

This PHP SDK is programmatically generated from our API specifications. Any manual modifications to internal files will be overwritten during subsequent generation cycles.

We value community contributions and feedback. Feel free to submit pull requests or open issues with your suggestions, and we'll do our best to include them in future releases.

Detailed Usage

For comprehensive understanding of each API's functionality, including detailed request and response specifications, parameter descriptions, and additional examples, please refer to the FastPix API Reference.

The API reference offers complete documentation for all available endpoints and features, enabling developers to integrate and leverage FastPix APIs effectively.

About

Developer-friendly & type-safe PHP SDK for the FastPix platform API

Topics

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages