C# AI detector quickstart
Send at least 150 characters for a more reliable signal. The response score ranges from 0 (more likely human-written) to 1 (more likely AI-generated); use it as evidence, not proof.
This example uses the HTTP and JSON libraries included with modern .NET.
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Text.Json;
var apiKey = Environment.GetEnvironmentVariable("SAPLING_API_KEY")
?? throw new InvalidOperationException("Set SAPLING_API_KEY first.");
using var client = new HttpClient();
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", apiKey);
var response = await client.PostAsJsonAsync(
"https://api.sapling.ai/api/v1/aidetect",
new {
text = "I am an artificial intelligence system designed to help people solve complex problems. " +
"My capabilities include natural language processing, machine learning, and predictive analytics.",
sent_scores = true
});
response.EnsureSuccessStatusCode();
var result = await response.Content.ReadFromJsonAsync<JsonElement>();
Console.WriteLine(JsonSerializer.Serialize(result, new JsonSerializerOptions {
WriteIndented = true
}));
{
"score": 0.9989,
"sentence_scores": [
{
"score": 0.9764,
"sentence": "I am an artificial intelligence system designed to help people solve complex problems."
},
{
"score": 0.9812,
"sentence": "My capabilities include natural language processing, machine learning, and predictive analytics."
}
],
"text": "I am an artificial intelligence system designed to help people solve complex problems. My capabilities include natural language processing, machine learning, and predictive analytics."
}
The overall score and sentence scores use different methods and may not match exactly. Choose thresholds based on the false-positive and false-negative costs of your use case.
About C#
C# is an object-oriented programming language for the Microsoft Windows platform. It is the primary language used for development inside the Windows ecosystem along with the .NET Framework and Visual Studio. This is also the language used by the cross-platform application framework Xamarin.