Sapling Logo
AI detector quickstart

Go AI Detector

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

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

Go 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.
Go /api/v1/aidetect
package main

import (
  "bytes"
  "encoding/json"
  "fmt"
  "io"
  "net/http"
  "os"
)

func main() {
  apiKey := os.Getenv("SAPLING_API_KEY")
  if apiKey == "" {
    panic("set SAPLING_API_KEY first")
  }

  payload, err := json.Marshal(map[string]interface{}{
    "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,
  })
  if err != nil {
    panic(err)
  }

  req, err := http.NewRequest(
    http.MethodPost,
    "https://api.sapling.ai/api/v1/aidetect",
    bytes.NewReader(payload),
  )
  if err != nil {
    panic(err)
  }
  req.Header.Set("Authorization", "Bearer "+apiKey)
  req.Header.Set("Content-Type", "application/json")

  resp, err := http.DefaultClient.Do(req)
  if err != nil {
    panic(err)
  }
  defer resp.Body.Close()

  body, err := io.ReadAll(resp.Body)
  if err != nil {
    panic(err)
  }
  if resp.StatusCode < 200 || resp.StatusCode >= 300 {
    panic(fmt.Sprintf("Sapling API error %s: %s", resp.Status, body))
  }

  fmt.Println(string(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 Go

Go is a programming language designed at Google, to have performance similarity to C but with easier readability, memory safety, garbage collection and easier concurrency.