Skip to content

Repository files navigation

FastPix C# SDK

NuGet version NuGet downloads license .NET 8.0+

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

The FastPix C# SDK is a strongly-typed .NET client for the FastPix video API. From any .NET 8 app you can upload and manage videos, run live streams and simulcasts, create and secure playback IDs, manage playlists and signing keys, pull video analytics (views, metrics, dimensions, and errors), and drive in-video AI features such as subtitles, chapters, summaries, and content moderation.

Works with: .NET 8.0+ · C# · NuGet package Fastpix · ASP.NET Core, console, and worker apps

📖 Docs: https://fastpix.com/docs/language-sdks/csharp-sdk  ·  🚀 Free account: https://dashboard.fastpix.com

Jump to

Skip straight to a section without scrolling:

Get started Reference Help & more
Start here Available resources & operations FAQ
Before you begin Error handling Which SDK?
Install the SDK Server selection Related tools
Make your first API request Custom HTTP client Development
Media workflow Retries Examples

Start here

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

  1. Check your .NET version
  2. Create a .NET project
  3. Install the FastPix SDK
  4. Verify the SDK installation
  5. Configure authentication
  6. Initialize the FastPix client
  7. Make your first API request
  8. Retrieve a media asset
  9. Generate a playback ID

Do not skip the verification steps. If the SDK does not install or the project does not build, resolve that issue before making an API request.


Before you begin

Make sure you have the following:

  • .NET 8.0 or later.
  • The .NET CLI.
  • Internet access.
  • A FastPix account.
  • A FastPix Access Token.
  • A FastPix Secret Key.
  • A publicly accessible video URL for the first media-creation example.

Environment and Version Support

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

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

FastPix uses HTTP Basic Authentication.

SDK property FastPix credential
Username Access Token
Password Secret Key

Follow the steps in the Authentication with Basic Auth guide to obtain your credentials from the FastPix Dashboard.

Optionally, store your credentials as environment variables:

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

Security: Do not commit your Access Token or Secret Key to source control. Use environment variables or a secure secrets manager.


1. Check your .NET version

Run:

dotnet --version

The output must be 8.0 or later.

For example:

8.0.414

You can also check the installed SDKs:

dotnet --list-sdks

If .NET 8 or later is not installed, install a supported .NET SDK before continuing.


2. Create a .NET project

Create a new console application:

mkdir fastpix-csharp-demo
cd fastpix-csharp-demo
dotnet new console

This creates a new .NET console application containing files similar to:

fastpix-csharp-demo/
├── fastpix-csharp-demo.csproj
├── Program.cs
└── obj/

Verify that the project builds before installing the FastPix SDK:

dotnet build

You should see output similar to:

Build succeeded.
    0 Warning(s)
    0 Error(s)

If the build fails, resolve the .NET project issue before continuing.


3. Install the FastPix SDK

Install the FastPix SDK from NuGet:

dotnet add package Fastpix

The SDK is added to your project as a NuGet dependency.

Verify the package:

dotnet list package

You should see an entry similar to:

Fastpix    1.1.6

The exact version may be different if a newer version has been published.


4. Verify the SDK installation

Before making an API request, verify that your application can import and initialize the FastPix SDK.

Replace the contents of Program.cs with:

using Fastpix;
using Fastpix.Models.Components;

var sdk = new FastpixSDK(
    security: new Security
    {
        Username = "test",
        Password = "test"
    }
);

Console.WriteLine("FastPix SDK initialized successfully");

Run:

dotnet run

Expected output:

FastPix SDK initialized successfully

At this point you have verified that:

  • .NET is installed.
  • The project builds.
  • The Fastpix package is installed.
  • The required namespaces are available.
  • The FastpixSDK client can be initialized.

The example uses placeholder credentials, so it does not make an API request.


5. Configure authentication

Do not put your FastPix credentials directly in Program.cs.

Set the credentials as environment variables instead.

macOS and Linux

export FASTPIX_USERNAME="your-access-token"
export FASTPIX_PASSWORD="your-secret-key"

Verify that the variables are set without printing the actual credentials:

test -n "$FASTPIX_USERNAME" && echo "FASTPIX_USERNAME is set"
test -n "$FASTPIX_PASSWORD" && echo "FASTPIX_PASSWORD is set"

Expected output:

FASTPIX_USERNAME is set
FASTPIX_PASSWORD is set

Windows PowerShell

$env:FASTPIX_USERNAME="your-access-token"
$env:FASTPIX_PASSWORD="your-secret-key"

Verify:

if ($env:FASTPIX_USERNAME) { "FASTPIX_USERNAME is set" }
if ($env:FASTPIX_PASSWORD) { "FASTPIX_PASSWORD is set" }

Do not print the values of the credentials themselves.


6. Initialize the FastPix client

Update Program.cs:

using Fastpix;
using Fastpix.Models.Components;

var username = Environment.GetEnvironmentVariable("FASTPIX_USERNAME");
var password = Environment.GetEnvironmentVariable("FASTPIX_PASSWORD");

if (string.IsNullOrWhiteSpace(username))
{
    throw new InvalidOperationException(
        "FASTPIX_USERNAME environment variable is not set."
    );
}

if (string.IsNullOrWhiteSpace(password))
{
    throw new InvalidOperationException(
        "FASTPIX_PASSWORD environment variable is not set."
    );
}

var sdk = new FastpixSDK(
    security: new Security
    {
        Username = username,
        Password = password
    }
);

Console.WriteLine("FastPix client initialized successfully");

Run:

dotnet run

Expected output:

FastPix client initialized successfully

Initializing the SDK does not make an API request. The SDK contacts the FastPix API when you call an operation such as CreateMediaAsync.


7. Make your first API request

The simplest way to verify the complete integration is to create a media asset from a publicly accessible video URL.

Replace Program.cs with:

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

var username = Environment.GetEnvironmentVariable("FASTPIX_USERNAME");
var password = Environment.GetEnvironmentVariable("FASTPIX_PASSWORD");

if (string.IsNullOrWhiteSpace(username))
{
    throw new InvalidOperationException(
        "FASTPIX_USERNAME environment variable is not set."
    );
}

if (string.IsNullOrWhiteSpace(password))
{
    throw new InvalidOperationException(
        "FASTPIX_PASSWORD environment variable is not set."
    );
}

var sdk = new FastpixSDK(
    security: new Security()
    {
        Username = username,
        Password = password,
    }
);

var request = new CreateMediaRequest()
{
    Inputs = new List<Fastpix.Models.Components.Input>()
    {
        Fastpix.Models.Components.Input.CreatePullVideoInput(
            new PullVideoInput()
            {
                Url = "https://static.fastpix.com/fp-sample-video.mp4"
            }
        )
    },

    Metadata = new Dictionary<string, string>()
    {
        { "title", "My first FastPix video" },
        { "source", "csharp-demo" }
    }
};

try
{
    var response = await sdk.InputVideo.CreateMediaAsync(request);

    Console.WriteLine("Media creation request succeeded.");
    Console.WriteLine();
    Console.WriteLine("Response type:");
    Console.WriteLine(response.GetType().FullName);
    Console.WriteLine();
    Console.WriteLine("Response:");
    Console.WriteLine(
        JsonSerializer.Serialize(
            response,
            new JsonSerializerOptions
            {
                WriteIndented = true
            }
        )
    );
}
catch (Exception ex)
{
    Console.Error.WriteLine("FastPix API request failed.");
    Console.Error.WriteLine(ex.Message);
}

Run:

dotnet run

If the request succeeds, FastPix returns the response from the media creation API.

Note: The example URL above is a placeholder. You must replace it with a URL that points directly to a video file that FastPix can access.


8. Retrieve a media asset

After creating media, use the returned media ID to retrieve the media details.

The media ID returned by the create operation can be passed to the corresponding media retrieval operation.

For a media asset to become playable, wait until its processing status indicates that it is ready.


9. Generate a playback ID

Once your media is ready, you can create a playback ID for video playback.

Playback IDs can be used with FastPix playback clients such as the FastPix Web Player.

For secure content, use signed playback and the appropriate signing configuration.

See the FastPix playback documentation for details.


Understand the media workflow

Creating media is usually the first operation in an on-demand video workflow. You carry the media ID from one call to the next, from upload through to playback.

FastPix C# media workflow: create media returns a media ID, get the media details, wait until the status is ready, create a playback ID, then play the video.

A playback ID is created separately, only when you need playback access.

More examples: For runnable, end-to-end flows (media creation, live streaming, playlists, analytics, and more), see the examples/ directory in the repo.

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

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

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

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

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 Fastpix.Utils.Retries;
using System.Collections.Generic;

var sdk = new FastpixSDK(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.CreatePullVideoInput(
            new PullVideoInput() {}
        ),
    },
    Metadata = new Dictionary<string, string>() {
        { "<key>", "<value>" },
    },
};

var res = await sdk.InputVideo.CreateMediaAsync(
    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 Fastpix.Utils.Retries;
using System.Collections.Generic;

var sdk = new FastpixSDK(
    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 = "your-secret-key",
    }
);

CreateMediaRequest req = new CreateMediaRequest() {
    Inputs = new List<Fastpix.Models.Components.Input>() {
        Fastpix.Models.Components.Input.CreatePullVideoInput(
            new PullVideoInput() {}
        ),
    },
    Metadata = new Dictionary<string, string>() {
        { "<key>", "<value>" },
    },
};

var res = await sdk.InputVideo.CreateMediaAsync(req);

// handle response

Error Handling

FastpixException is the base exception 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
Body string HTTP response body

Example

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

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

try
{
    CreateMediaRequest req = new CreateMediaRequest() {
        Inputs = new List<Fastpix.Models.Components.Input>() {
            Fastpix.Models.Components.Input.CreatePullVideoInput(
                new PullVideoInput() {}
            ),
        },
        Metadata = new Dictionary<string, string>() {
            { "<key>", "<value>" },
        },
    };

    var res = await sdk.InputVideo.CreateMediaAsync(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;
}
catch (OperationCanceledException ex)
{
    // CancellationToken was cancelled
}
catch (System.Net.Http.HttpRequestException ex)
{
    // Check ex.InnerException for Network connectivity errors
}

Error Classes

Primary exception:

Less common exceptions (2)

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 FastpixSDK(
    serverUrl: "<server-url>",
    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.CreatePullVideoInput(
            new PullVideoInput() {}
        ),
    },
    Metadata = new Dictionary<string, string>() {
        { "<key>", "<value>" },
    },
};

var res = await sdk.InputVideo.CreateMediaAsync(req);

// handle response

Custom HTTP Client

The C# SDK makes API calls using an IFastpixHttpClient that wraps the native HttpClient. This client provides the ability to attach hooks around the request lifecycle that can be used to modify the request or handle errors and response.

The IFastpixHttpClient interface allows you to either use the default FastpixHttpClient that comes with the SDK, or provide your own custom implementation with customized configuration such as custom message handlers, timeouts, connection pooling, and other HTTP client settings.

The following example shows how to create a custom HTTP client with request modification and error handling:

using Fastpix;
using Fastpix.Utils;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;

// Create a custom HTTP client
public class CustomHttpClient : IFastpixHttpClient
{
    private readonly IFastpixHttpClient _defaultClient;

    public CustomHttpClient()
    {
        _defaultClient = new FastpixHttpClient();
    }

    public async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken? cancellationToken = null)
    {
        // Add custom header and timeout
        request.Headers.Add("x-custom-header", "custom value");
        request.Headers.Add("x-request-timeout", "30");
        
        try
        {
            var response = await _defaultClient.SendAsync(request, cancellationToken);
            // Log successful response
            Console.WriteLine($"Request successful: {response.StatusCode}");
            return response;
        }
        catch (Exception error)
        {
            // Log error
            Console.WriteLine($"Request failed: {error.Message}");
            throw;
        }
    }

    public void Dispose()
    {
        _defaultClient?.Dispose();
    }
}

// Use the custom HTTP client with the SDK
var customHttpClient = new CustomHttpClient();
var sdk = new FastpixSDK(client: customHttpClient);
You can also provide a completely custom HTTP client with your own configuration:
using Fastpix.Utils;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;

// Custom HTTP client with custom configuration
public class AdvancedHttpClient : IFastpixHttpClient
{
    private readonly HttpClient _httpClient;

    public AdvancedHttpClient()
    {
        var handler = new HttpClientHandler()
        {
            MaxConnectionsPerServer = 10,
            // ServerCertificateCustomValidationCallback = customCertValidation, // Custom SSL validation if needed
        };

        _httpClient = new HttpClient(handler)
        {
            Timeout = TimeSpan.FromSeconds(30)
        };
    }

    public async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken? cancellationToken = null)
    {
        return await _httpClient.SendAsync(request, cancellationToken ?? CancellationToken.None);
    }

    public void Dispose()
    {
        _httpClient?.Dispose();
    }
}

var sdk = new FastpixSDK(client: new AdvancedHttpClient());
For simple debugging, you can enable request/response logging by implementing a custom client:
public class LoggingHttpClient : IFastpixHttpClient
{
    private readonly IFastpixHttpClient _innerClient;

    public LoggingHttpClient(IFastpixHttpClient innerClient = null)
    {
        _innerClient = innerClient ?? new FastpixHttpClient();
    }

    public async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken? cancellationToken = null)
    {
        // Log request
        Console.WriteLine($"Sending {request.Method} request to {request.RequestUri}");
        
        var response = await _innerClient.SendAsync(request, cancellationToken);
        
        // Log response
        Console.WriteLine($"Received {response.StatusCode} response");
        
        return response;
    }

    public void Dispose() => _innerClient?.Dispose();
}

var sdk = new FastpixSDK(client: new LoggingHttpClient());

The SDK also provides built-in hook support through the SDKConfiguration.Hooks system, which automatically handles BeforeRequestAsync, AfterSuccessAsync, and AfterErrorAsync hooks for advanced request lifecycle management.

FAQ

How do I install the FastPix C# SDK? Add the NuGet package with dotnet add package Fastpix (or Install-Package Fastpix in Visual Studio). See Install the FastPix SDK.

How do I authenticate the FastPix .NET SDK? FastPix uses Basic Auth: pass your access token as Username and your secret key as Password when constructing FastpixSDK. See Initialize the FastPix client.

How do I upload a video from C#? Create media from a URL or upload from a device through sdk.InputVideo, for example await sdk.InputVideo.CreateMediaAsync(req). See Make your first API request and Available Resources and Operations.

How do I start a live stream in .NET? Use the Live API 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 C#? The Video Data API exposes metrics, views, dimensions, and errors for monitoring quality of experience. See Available Resources and Operations.

How do I handle API errors? Catch FastpixException (the base class for all HTTP error responses); it exposes the request, response, status code, and body. See Error Handling.

How do I configure automatic retries? Pass a RetryConfig per call or when constructing the SDK to control the backoff strategy. See Retries.

How do I use a custom HttpClient, proxy, or timeout? Provide your own IFastpixHttpClient implementation (custom headers, handlers, timeouts, connection pooling) or use the built-in hooks. See Custom HTTP Client.

Which .NET versions are supported? The SDK targets .NET 8.0 and above. See Before you begin.

Is the SDK strongly typed? Yes - it is a strongly-typed client generated from the FastPix API specification, so requests and responses are fully typed. 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
C# / .NET (this repo) fastpix-sdk-csharp dotnet add package Fastpix
Node.js / TypeScript node-sdk npm install @fastpix/fastpix-node
Python fastpix-python pip install fastpix-python
Go fastpix-go go get github.com/FastPix/fastpix-go
PHP fastpix-php composer require fastpix/sdk
Java fastpix-java io.fastpix:sdk (Maven/Gradle)
Ruby fastpix-ruby gem install fastpixapi

Related FastPix tools

The C# SDK manages media, live streams, and playback on the server. To upload and play that media in the browser, pair it with these FastPix client-side libraries:

  • web-uploads-sdk - resumable, chunked file uploads from the browser (@fastpix/resumable-uploads)
  • react-web-uploader - a drop-in React upload component (@fastpix/fp-react-uploader)
  • web-player-component - the FastPix HLS video player web component (@fastpix/fp-player)

Browse every SDK and tool in the FastPix organization.

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

Contributing

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages