Swift / iOS 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.
No language-specific SDK is required. The example uses a standard or commonly used HTTP client to call Sapling's JSON API.
Swift / iOS
/api/v1/aidetect
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
@main
struct Main {
static func main() async throws {
guard let apiKey = ProcessInfo.processInfo.environment["SAPLING_API_KEY"] else {
throw NSError(
domain: "Quickstart",
code: 1,
userInfo: [NSLocalizedDescriptionKey: "Set SAPLING_API_KEY first."]
)
}
let payload: [String: Any] = [
"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,
]
var request = URLRequest(
url: URL(string: "https://api.sapling.ai/api/v1/aidetect")!
)
request.httpMethod = "POST"
request.setValue("Bearer \(apiKey)", forHTTPHeaderField: "Authorization")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = try JSONSerialization.data(withJSONObject: payload)
let (data, response) = try await URLSession.shared.data(for: request)
guard let httpResponse = response as? HTTPURLResponse,
(200..<300).contains(httpResponse.statusCode) else {
throw NSError(domain: "SaplingAPI", code: 1)
}
print(String(decoding: data, as: UTF8.self))
}
}
Example response
application/json
{
"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 Swift / iOS
Swift is a compiled programming language developed by Apple as a replacement for Objective-C. It is used with Cocoa and Cocoa Touch frameworks for application development for iOS and macOS platforms.