SfwApi 0.1.1

dotnet add package SfwApi --version 0.1.1
                    
NuGet\Install-Package SfwApi -Version 0.1.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SfwApi" Version="0.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SfwApi" Version="0.1.1" />
                    
Directory.Packages.props
<PackageReference Include="SfwApi" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SfwApi --version 0.1.1
                    
#r "nuget: SfwApi, 0.1.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SfwApi@0.1.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SfwApi&version=0.1.1
                    
Install as a Cake Addin
#tool nuget:?package=SfwApi&version=0.1.1
                    
Install as a Cake Tool

SfwApi

Official .NET client for the SFW API: NSFW and nudity detection for images, GIFs and videos. Targets .NET 8 and .NET Standard 2.0 (works on .NET 8+, .NET Framework 4.6.2+ and Unity) with strongly typed results, typed errors and CancellationToken support on every method.

Media is processed in memory and never stored. Every account includes 500 free credits a month, with no card required.

Install

dotnet add package SfwApi

Get an API key at sfwapi.dev/console and store it in SFWAPI_API_KEY.

Quick start

using SfwApi;

using var api = new SfwApiClient(Environment.GetEnvironmentVariable("SFWAPI_API_KEY")!);

// Analyse media at a public URL with a blocking policy
var result = await api.AnalyzeUrlAsync("https://example.com/photo.jpg", new AnalyzeOptions
{
    Policy = new Policy { BlockLevel = NudityLevel.ImpliedNudity, BlockSexObjects = true },
});

Console.WriteLine($"{result.Nudity.Level} blocked={result.Policy?.Blocked} credits left={result.Usage.Balance}");

// Upload a local image, GIF or video
var clip = await api.AnalyzeFileAsync("clip.gif", new AnalyzeOptions { MaxFrames = 5, IncludeFrames = true });

ASP.NET Core and IHttpClientFactory

SfwApiClient is thread-safe. Create one and reuse it, or pass an HttpClient from IHttpClientFactory to the second constructor:

builder.Services.AddHttpClient("sfwapi");
builder.Services.AddSingleton(services => new SfwApiClient(
    services.GetRequiredService<IHttpClientFactory>().CreateClient("sfwapi"),
    builder.Configuration["SfwApi:Key"]!));

Content levels

Each score runs from 0 to 100 and counts above 50 (SfwApiClient.Cutoff). Nudity.Level is the NudityLevel enum; SfwApiClient.LevelName(level) returns its display name.

Level Enum Meaning
0 NudityLevel.Everyday Normal photos, clothed people, landscapes, objects
1 NudityLevel.Revealing Swimwear, lingerie, cleavage and other revealing clothing
2 NudityLevel.ImpliedNudity Partial or covered nudity, suggestive poses without exposed genitalia
3 NudityLevel.Explicit Exposed genitalia or explicit sexual acts

Responses also include Flags.Art (drawings, anime, paintings, stylised 3D) and Flags.SexObject (adult toys and objects).

Methods

Method Description
AnalyzeUrlAsync(url, options?, ct) Analyse an image, GIF or video at a public http(s) URL
AnalyzeFileAsync(path, options?, ct) Upload a local file as multipart
AnalyzeBytesAsync(bytes, options?, ct) Upload raw bytes as multipart
AnalyzeStreamAsync(stream, options?, ct) Upload a Stream as multipart
AnalyzeBase64Async(base64, options?, ct) Send base64-encoded media
GetAccountAsync(ct) Account tier, rate limits and credit balance
GetUsageAsync(ct) Current month's request, credit and byte totals

One credit is charged per image, or one per analysed frame for a GIF or video.

Errors and retries

Non-2xx responses throw SfwApiException with Status, Type, Code, ApiMessage, RequestId and DocUrl. Statuses 429, 503 and 504 are retried twice honouring Retry-After (uploads are not retried; set MaxRetries = 0 in SfwApiClientOptions to disable). Failed requests are never charged.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.1 55 11/28/2026
0.1.0 116 11/11/2026