C# + PixelPanda API

Remove Background with C#

Remove image backgrounds from C# with HttpClient. Works with .NET 6+, ASP.NET Core, Blazor, and console apps.

$ # No NuGet packages needed — uses built-in System.Net.Http

C# examples — copy and go

Each example is self-contained. Copy the one that matches your use case.

Quick start

Basic background removal with HttpClient.

using System.Net.Http;
using System.Text.Json;

var apiKey = "pk_live_your_api_key";
var client = new HttpClient();
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}");

var form = new MultipartFormDataContent();
var fileContent = new ByteArrayContent(File.ReadAllBytes("product.jpg"));
form.Add(fileContent, "file", "product.jpg");

var response = await client.PostAsync(
    "https://pixelpanda.ai/api/v1/remove-background", form);

var json = await response.Content.ReadAsStringAsync();
var result = JsonSerializer.Deserialize<JsonElement>(json);
Console.WriteLine(result.GetProperty("image_url"));

ASP.NET Core controller

Accept uploads in an ASP.NET Core API.

[ApiController]
[Route("api/[controller]")]
public class ImageController : ControllerBase
{
    private readonly HttpClient _http;
    private readonly string _apiKey;

    public ImageController(IHttpClientFactory factory, IConfiguration config)
    {
        _http = factory.CreateClient();
        _apiKey = config["PixelPanda:ApiKey"];
    }

    [HttpPost("remove-bg")]
    public async Task<IActionResult> RemoveBackground(IFormFile image)
    {
        if (image == null) return BadRequest("No image");

        var form = new MultipartFormDataContent();
        var stream = image.OpenReadStream();
        form.Add(new StreamContent(stream), "file", image.FileName);

        _http.DefaultRequestHeaders.Clear();
        _http.DefaultRequestHeaders.Add("Authorization", $"Bearer {_apiKey}");

        var response = await _http.PostAsync(
            "https://pixelpanda.ai/api/v1/remove-background", form);

        var json = await response.Content.ReadAsStringAsync();
        return Content(json, "application/json");
    }
}

Response format

Every successful request returns this JSON. The image_url is a permanent link to the transparent PNG.

{
    "success": true,
    "image_url": "https://pub-xxx.r2.dev/results/abc123.png",
    "credits_remaining": 199
}
FieldTypeDescription
successbooleantrue if background was removed successfully
image_urlstringURL to the transparent PNG result (permanent, hosted on CDN)
credits_remainingintegerHow many credits are left on your account

Error codes

CodeMeaning
200Success
401Invalid API key
402Out of credits

Common questions

.NET 6+ recommended. Uses top-level statements and HttpClient.
Yes — see the ASP.NET Core controller example above.
1 credit per image ($0.029). 280 credits/week for $7.99.

Start removing backgrounds with C#

280 credits/week for $7.99. Copy the code above and go.

Get Your API Key