Sapling Logo
AI detector quickstart

Ruby AI Detector

Analyze text from a Ruby application and receive document- and sentence-level AI detection scores.

  • HTTPS POST
  • HTTP API
  • API key required
POST Ruby logo Ruby /api/v1/aidetect

Ruby 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.
Ruby /api/v1/aidetect
require 'json'
require 'net/http'

api_key = ENV.fetch('SAPLING_API_KEY')
uri = URI('https://api.sapling.ai/api/v1/aidetect')

request = Net::HTTP::Post.new(uri)
request['Authorization'] = "Bearer #{api_key}"
request['Content-Type'] = 'application/json'
request.body = {
  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
}.to_json

response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
  http.request(request)
end

response.value
puts JSON.pretty_generate(JSON.parse(response.body))
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 Ruby

Ruby is a programming language that shares design philosophies of Python and Perl around scripting, usability, and programming productivity but with a more object-oriented approach. Its popularity and adoption increased with Ruby on Rails, an MVC web framework written in Ruby.