Inference API

The Inference API allows you to submit text and receive an AI likelihood score.

Tip

Use the batch endpoint to maximize throughput when classifying multiple documents.

Note

text.api.pangramlabs.com and text-batch.api.pangramlabs.com only use the first ~400 words of the input text when making its prediction.

For accurate predictions on longer text with mixed human and AI content, break your document into chunks of ~400 words or use the sliding window API.

POST https://text.api.pangramlabs.com
Request JSON Object:
  • text (string) – The input text to classify.

Response JSON Object:
  • ai_likelihood (float) – The classification of the text, on a scale from 0.0 (human) to 1.0 (AI).

  • text (string) – The classified text.

  • prediction (string) – A string representing the classification.

Request Headers

{
  "Content-Type": "application/json",
  "x-api-key": "<api-key>"
}

Request Body

{
  "text": "<text>"
}

Example Request

POST https://text.api.pangramlabs.com HTTP/1.1
Content-Type: application/json
x-api-key: your_api_key_here

{
  "text": "The text to analyze"
}

Example Response

{
  "text": "The text to analyze",
  "prediction": "Likely AI",
  "ai_likelihood": 0.92
}
POST https://text-batch.api.pangramlabs.com
Request JSON Object:
  • text (array) – An array of input texts to classify.

Response JSON Object:
  • responses (array) – The classification results as a list, each item containing “text”, “ai_likelihood”, and “prediction”. Each item in the array is the same as a response from a single text prediction.

Batch Inference

Request Headers

{
  "Content-Type": "application/json",
  "x-api-key": "<api-key>"
}

Request Body

{
  "text": ["<text1>", "<text2>", "..."]
}

Example Request

POST https://text-batch.api.pangramlabs.com HTTP/1.1
Content-Type: application/json
x-api-key: your_api_key_here

{
  "text": ["The first text to analyze", "The second text to analyze"]
}

Example Response

{
  "responses": [
    {
      "text": "The first text to analyze",
      "prediction": "Likely AI",
      "ai_likelihood": 0.92
    },
    {
      "text": "The second text to analyze",
      "prediction": "Possibly AI",
      "ai_likelihood": 0.58
    }
  ]
}
POST https://text-sliding.api.pangramlabs.com
Request JSON Object:
  • text (string) – The input text to segment into windows and classify.

Response JSON Object:
  • text (string) – The classified text.

  • ai_likelihood (float) – The classification of the text, on a scale from 0.0 (human) to 1.0 (AI).

  • max_ai_likelihood (float) – The maximum AI likelihood score among all windows.

  • avg_ai_likelihood (float) – The average AI likelihood score among all windows.

  • prediction (string) – A string representing the classification.

  • fraction_ai_content (float) – The fraction of windows that are classified as AI.

  • windows (array) – A list of windows and their individual classifications. Each object in the array is the response from a single text prediction.

Request Headers

{
  "Content-Type": "application/json",
  "x-api-key": "<api-key>"
}

Request Body

{
  "text": "<text>"
}

Example Request

POST https://text.api.pangramlabs.com HTTP/1.1
Content-Type: application/json
x-api-key: your_api_key_here

{
  "text": "Extremely long text."
}

Example Response

{
  "text": "Extremely long text.",
  "prediction": "Highly likely AI",
  "ai_likelihood": 1.0,
  "max_ai_likelihood": 1.0,
  "avg_ai_likelihood": 0.6,
  "fraction_ai_content": 0.5,
  "windows": [
    {
      "text": "Extremely long",
      "ai_likelihood": 1.0,
      "prediction": "Highly likely AI"
    },
    {
      "text": "long text.",
      "ai_likelihood": 0.1,
      "prediction": "Unlikely AI"
    }
  ]
}

Errors

The API may return the following error codes:

  • 400 Bad Request - If the request body is not properly formatted.

  • 401 Unauthorized - If the x-api-key is missing, invalid, or does not have enough credits to process the request.

  • 500 Internal Server Error - If there is an error processing the request.

Please reach out at support@pangram.com if you are running into errors with your requests.