Skip to content

FastPix C# SDK offers a secure, high-performance interface to the FastPix API—simplifying media uploads, live streaming, and simulcasting.

License

Notifications You must be signed in to change notification settings

FastPix/fastpix-sdk-csharp

Repository files navigation

FastPix C# SDK

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

Introduction

The FastPix C# SDK simplifies integration with the FastPix platform. It provides a clean, type-safe interface for secure and efficient communication with the FastPix API, enabling easy management of media uploads, live streaming, on‑demand content, playlists, video analytics, and signing keys for secure access and token management. It is intended for use with .NET 8 and above.

Prerequisites

Environment and Version Support

Requirement Version Description
.NET SDK 8.0+ Core runtime environment
NuGet Latest Package manager for dependencies
Internet Required API communication and authentication

Pro Tip: We recommend using .NET 9+ for optimal performance and the latest language features.

Getting Started with FastPix

To get started with the FastPix C# SDK, ensure you have the following:

  • The FastPix APIs are authenticated using a Username and a Password. You must generate these credentials to use the SDK.

  • Follow the steps in the Authentication with Basic Auth guide to obtain your credentials.

Environment Variables (Optional)

Configure your FastPix credentials using environment variables for enhanced security and convenience:

# Set your FastPix credentials
export FASTPIX_USERNAME="your-access-token"
export FASTPIX_PASSWORD="your-secret-key"

Security Note: Never commit your credentials to version control. Use environment variables or secure credential management systems.

Table of Contents

Setup

Installation

Install the FastPix C# SDK using your preferred package manager:

dotnet add package Fastpix  

NuGet Package Manager

Install-Package Fastpix

Package Manager Console

PM> Install-Package Fastpix

Imports

This SDK supports both C# 8.0+ and .NET Framework 4.8+. Examples in this documentation use modern C# syntax as it's the preferred format, but you can use either approach.

Modern C# (Recommended)

// Basic imports
using Fastpix;
using Fastpix.Models.Components;

Legacy .NET Framework

// Legacy using statements
using Fastpix;
using Fastpix.Models.Components;

Why Modern C#? Modern C# provides better type safety, nullable reference types, and are the current .NET standard. They enable better IntelliSense and development tooling support.

Note: This SDK automatically provides both framework support. If you encounter compatibility issues in your project, you may need to update your target framework to .NET 8.0 or higher.

Security Note: For production applications, it's recommended to make API calls from your backend server rather than directly from client applications to:

  • Keep credentials secure
  • Avoid CORS issues
  • Implement proper authentication.

Initialization

Initialize the FastPix SDK with your credentials:

using Fastpix;
using Fastpix.Models.Components;

var sdk = new FastPix(
    security: new Security
    {
        Username = "your-access-token",  // ⚠️ Replace with your actual FastPix username
        Password = "secret-key",         // ⚠️ Replace with your actual FastPix password
    }
);

Or using environment variables:

using Fastpix;
using Fastpix.Models.Components;

var sdk = new FastPix(
    security: new Security
    {
        Username = Environment.GetEnvironmentVariable("FASTPIX_USERNAME"),
        Password = Environment.GetEnvironmentVariable("FASTPIX_PASSWORD"),
    }
);

Example Usage

Example

using Fastpix;
using Fastpix.Models.Components;
using System.Collections.Generic;
using Newtonsoft.Json;

var sdk = new FastPix(security: new Security() {
    Username = "your-access-token",
   Password = "your-secret-key",
});

CreateMediaRequest req = new CreateMediaRequest() {
    Inputs = new List<Fastpix.Models.Components.Input>() {
        Fastpix.Models.Components.Input.CreateVideoInput(
            new VideoInput() {
                Type = "video",
                Url = "https://static.fastpix.io/sample.mp4",
            }
        ),
    },
    Metadata = new Dictionary<string, string>() {
        { "key1", "value1" },
    },
    AccessPolicy = CreateMediaRequestAccessPolicy.Public,
};

var res = await sdk.Videos.CreateFromUrlAsync(req);
Console.WriteLine(JsonConvert.SerializeObject(res.CreateMediaSuccessResponse, Formatting.Indented) ?? "null");
//  handle response

⚠️ IMPORTANT: Replace Credentials

You MUST replace the placeholder credentials with your actual FastPix API credentials:

  • Replace "your-access-token" with your actual FastPix username/access token
  • Replace "your-secret-key" with your actual FastPix password/secret key

Using placeholder credentials will result in UnauthorizedException errors.

Get your credentials from the FastPix Dashboard or follow the Authentication Guide.

Available Resources and Operations

Comprehensive C# 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

Play Specific Segments

  • Stream only a portion of a video by appending start/end parameters to the playback URL. Explore: Play specific segments. For creating reusable assets instead, see Create clips from existing media.
  • Try it: https://stream.fastpix.io/{PLAYBACK_ID}.m3u8?start=20&end=60 (replace {PLAYBACK_ID} and tweak times).

Create Clips from Existing Media

  • Create reusable, shareable clip assets from a source video with precise start/end control. Explore: Create clips from existing media.
  • Try it: use the clipping API from the guide to generate a new clip asset, then retrieve it via Media Clips to validate.

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

Live Clipping

  • Explore instant live clipping during a live stream to capture key moments without creating new assets. See the Live Clipping guide: Instant Live Clipping.
  • Try it: enable a test live stream and capture a highlight clip while broadcasting to see it appear instantly.

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

Transformations

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

Error Handling

Handle and manage errors with comprehensive error handling capabilities and detailed error information for all API operations.

  • List Errors - Retrieve comprehensive error logs and diagnostics

Retries

Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.

To change the default retry strategy for a single API call, simply pass a RetryConfig to the call:

using Fastpix;
using Fastpix.Models.Components;
using System.Collections.Generic;

var sdk = new FastPix(security: new Security() {
    Username = "your-access-token",
    Password = "secret-key",
});

CreateMediaRequest req = new CreateMediaRequest() {
    Inputs = new List<Fastpix.Models.Components.Input>() {
        Fastpix.Models.Components.Input.CreateVideoInput(
            new VideoInput() {
                Type = "video",
                Url = "https://static.fastpix.io/sample.mp4",
            }
        ),
    },
    Metadata = new Dictionary<string, string>() {
        { "key1", "value1" },
    },
    AccessPolicy = CreateMediaRequestAccessPolicy.Public,
};

var res = await sdk.Videos.CreateFromUrlAsync(
    retryConfig: new RetryConfig(
        strategy: RetryConfig.RetryStrategy.BACKOFF,
        backoff: new BackoffStrategy(
            initialIntervalMs: 1L,
            maxIntervalMs: 50L,
            maxElapsedTimeMs: 100L,
            exponent: 1.1
        ),
        retryConnectionErrors: false
    ),
    request: req
);

// handle response

If you'd like to override the default retry strategy for all operations that support retries, you can use the RetryConfig optional parameter when initializing the SDK:

using Fastpix;
using Fastpix.Models.Components;
using System.Collections.Generic;

var sdk = new FastPix(
    retryConfig: new RetryConfig(
        strategy: RetryConfig.RetryStrategy.BACKOFF,
        backoff: new BackoffStrategy(
            initialIntervalMs: 1L,
            maxIntervalMs: 50L,
            maxElapsedTimeMs: 100L,
            exponent: 1.1
        ),
        retryConnectionErrors: false
    ),
    security: new Security() {
        Username = "your-access-token",
        Password = "secret-key",
    }
);

CreateMediaRequest req = new CreateMediaRequest() {
    Inputs = new List<Fastpix.Models.Components.Input>() {
        Fastpix.Models.Components.Input.CreateVideoInput(
            new VideoInput() {
                Type = "video",
                Url = "https://static.fastpix.io/sample.mp4",
            }
        ),
    },
    Metadata = new Dictionary<string, string>() {
        { "key1", "value1" },
    },
    AccessPolicy = CreateMediaRequestAccessPolicy.Public,
};

var res = await sdk.Videos.CreateFromUrlAsync(req);

// handle response

Error Handling

FastPixException is the base class for all HTTP error responses. It has the following properties:

Property Type Description
Message string Error message
Request HttpRequestMessage HTTP request object
Response HttpResponseMessage HTTP response object

Example

using Fastpix;
using Fastpix.Models.Components;
using Fastpix.Models.Errors;
using System.Collections.Generic;

var sdk = new FastPix(security: new Security() {
    Username = "your-access-token",
    Password = "secret-key",
});

try
{
    CreateMediaRequest req = new CreateMediaRequest() {
        Inputs = new List<Fastpix.Models.Components.Input>() {
            Fastpix.Models.Components.Input.CreateVideoInput(
                new VideoInput() {
                    Type = "video",
                    Url = "https://static.fastpix.io/sample.mp4",
                }
            ),
        },
        Metadata = new Dictionary<string, string>() {
            { "key1", "value1" },
        },
        AccessPolicy = CreateMediaRequestAccessPolicy.Public,
    };

    var res = await sdk.Videos.CreateFromUrlAsync(req);

    // handle response
}
catch (FastPixException ex)  // all SDK exceptions inherit from FastPixException
{
    // ex.ToString() provides a detailed error message
    System.Console.WriteLine(ex);

    // Base exception fields
    HttpRequestMessage request = ex.Request;
    HttpResponseMessage response = ex.Response;
    var statusCode = (int)response.StatusCode;
    var responseBody = ex.Body;

    if (ex is BadRequestException badRequestEx) // different exceptions may be thrown depending on the method
    {
        // Check error data fields
        BadRequestExceptionPayload payload = badRequestEx.Payload;
        bool? Success = payload.Success;
        BadRequestError? Error = payload.Error;
        // ...
    }

    // An underlying cause may be provided
    if (ex.InnerException != null)
    {
        Exception cause = ex.InnerException;
    }
}
catch (OperationCanceledException ex)
{
    // CancellationToken was cancelled
}
catch (System.Net.Http.HttpRequestException ex)
{
    // Check ex.InnerException for Network connectivity errors
}

Error Classes

Primary exceptions:

Less common exceptions (24)

* Refer to the relevant documentation to determine whether an exception applies to a specific operation.

Server Selection

Override Server URL Per-Client

The default server can be overridden globally by passing a URL to the serverUrl: string optional parameter when initializing the SDK client instance. For example:

using Fastpix;
using Fastpix.Models.Components;
using System.Collections.Generic;

var sdk = new FastPix(
    serverUrl: "https://api.fastpix.io/v1/",
    security: new Security() {
        Username = "your-access-token",
        Password = "secret-key",
    }
);

CreateMediaRequest req = new CreateMediaRequest() {
    Inputs = new List<Fastpix.Models.Components.Input>() {
        Fastpix.Models.Components.Input.CreateVideoInput(
            new VideoInput() {
                Type = "video",
                Url = "https://static.fastpix.io/sample.mp4",
            }
        ),
    },
    Metadata = new Dictionary<string, string>() {
        { "key1", "value1" },
    },
    AccessPolicy = CreateMediaRequestAccessPolicy.Public,
};

var res = await sdk.Videos.CreateFromUrlAsync(req);

// handle response

Development

This C# 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

FastPix C# SDK offers a secure, high-performance interface to the FastPix API—simplifying media uploads, live streaming, and simulcasting.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •