> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pangram.com/llms.txt
> Use this file to discover all available pages before exploring further.

# AI Detection

> Detect AI-generated and AI-assisted text using the async inference API

For more information on billing units and pricing, check our [pricing page](https://www.pangram.com/pricing).

Current

**Async inference API**

Current version

The current AI detection API creates an async task and returns a task ID. Poll the task endpoint until it reaches `STAGE_SUCCESS` or `STAGE_FAILED`.

Use the [Bulk API](https://docs.pangram.com/api-reference/bulk-api.md) when you need to analyze many texts as one asynchronous job.

Use [`GET /models`](https://docs.pangram.com/api-reference/models) to discover the selectors available to your API key. The REST API temporarily accepts an omitted `model` for backward compatibility and resolves it to `"default"`. New integrations should always send a selector explicitly.

`pangram-4` selects the Pangram 4 series. Minor versions within the series can change without changing the selector. The completed response's `version` field reports the model version used, such as `4.0` or `4.1`.

## POST /task

Create an async AI detection task.

```
POST https://text.external-api.pangram.com/task
```

### Request

**text** `string` *required*

The input text to analyze.

**model** `string` (default: default)

A model selector returned by [`GET /models`](https://docs.pangram.com/api-reference/models).

**public\_dashboard\_link** `boolean` (default: false)

Whether to include a public dashboard link in the completed response.

### Response

**task\_id** `string`

The ID of the async inference task.

### Example

```bash cURL theme={null}
curl -X POST https://text.external-api.pangram.com/task \
  -H "Content-Type: application/json" \
  -H "x-api-key: your_api_key_here" \
  -d '{
    "text": "AI-assisted passage. Human passage.",
    "model": "pangram-4",
    "public_dashboard_link": false
  }'
```

```python Python SDK theme={null}
from pangram import Pangram

pangram_client = Pangram()
result = pangram_client.predict(
    "AI-assisted passage. Human passage.",
    model="pangram-4",
)
```

**Example Response**

```json theme={null}
{
  "task_id": "123e4567-e89b-12d3-a456-426614174000"
}
```

### Model selection errors

| Status Code | Description |
| - | - |
| `403 Forbidden` | The requested model is not enabled for the API key. |
| `422 Unprocessable Entity` | The model selector is malformed or unknown. |
| `503 Service Unavailable` | The requested model is temporarily unavailable. |

***

## GET /task/{task_id}

Fetch the current status or completed result for an AI detection task.

```
GET https://text.external-api.pangram.com/task/{task_id}
```

### Request

**task\_id** `string` *required*

The task ID returned by `POST /task`.

### Response

**task\_id** `string`

The ID of the async inference task. Present while the task is in progress.

**stage** `string`

Current task stage. Terminal stages are `STAGE_SUCCESS` and `STAGE_FAILED`.

**text** `string`

The analyzed text returned by the model. Pangram 4 may normalize the submitted text before inference; window offsets refer to this returned value. Present on success.

**version** `string`

The model version used for this result (e.g., `"4.1"` or `"4.0"`). Minor versions can change within the selected model series. Present on success.

**headline** `string`

Classification headline summarizing the result. Present on success.

**prediction** `string`

Long-form prediction string describing the classification. Present on success.

**prediction\_short** `string`

Short-form prediction string. Pangram 4 returns `"AI"`, `"Human"`, or `"Mixed"`. Present on success.

**fraction\_ai** `float`

Fraction of text classified as AI-written (0.0–1.0). Present on success.

**fraction\_ai\_assisted** `float`

Fraction of text classified as AI-assisted (0.0–1.0). Present on success.

**fraction\_human** `float`

Fraction of text classified as human-written (0.0–1.0). Present on success.

**num\_ai\_segments** `integer`

Number of text segments classified as AI. Present on success.

**num\_ai\_assisted\_segments** `integer`

Number of text segments classified as AI-assisted. Present on success.

**num\_human\_segments** `integer`

Number of text segments classified as human. Present on success.

**dashboard\_link** `string`

A link to the dashboard page containing the full classification result. Present on success when `public_dashboard_link` is `true`.

**windows** `array`

List of text segments (windows (The text is divided into overlapping segments (windows) that are each classified independently, enabling granular detection across long documents.)) analyzed individually. Present on success.

**Window object properties**

**text** `string`

The window text.

**label** `string`

Descriptive classification label. Pangram 4 returns `"AI-Generated"`, `"AI-Assisted"`, or `"Human Written"`.

**ai\_assistance\_score** `float`

AI assistance score (A continuous score from 0 to 1, where 0 means entirely human-written and 1 means fully AI-generated. Values in between indicate varying degrees of AI assistance.) detailing the level of AI assistance (0.0–1.0).

**confidence** `string`

Confidence level (High = strong signal, the model is very sure. Medium = moderate signal. Low = weak signal, treat with caution.) for the classification (`"High"`, `"Medium"`, `"Low"`).

**start\_index** `integer`

Starting character index in the returned top-level `text`.

**end\_index** `integer`

End-exclusive character index in the returned top-level `text`.

**word\_count** `integer`

Number of words in the window.

**token\_length** `integer`

Token length of the window.

**is\_humanized** `boolean`

Whether Pangram 4's humanizer head classified the window as humanized. Present on every Pangram 4 window.

**humanizer\_score** `float`

Pangram 4 humanizer-head score from 0.0–1.0. Present on every Pangram 4 window.

**class\_probabilities** `array`

Pangram 4.1 posterior probabilities for Human, AI-Assisted, and AI-Generated, in that order (array of 3 floats). Present on Pangram 4.1 windows.

### Example

```bash cURL theme={null}
curl -X GET https://text.external-api.pangram.com/task/123e4567-e89b-12d3-a456-426614174000 \
  -H "x-api-key: your_api_key_here"
```

**In-Progress Response**

```json theme={null}
{
  "task_id": "123e4567-e89b-12d3-a456-426614174000",
  "stage": "STAGE_PREPROCESSING"
}
```

**Success Response**

This example shows a version `4.0` result from the Pangram 4 series. It uses `"AI-Assisted"` instead of lightly or moderately assisted window labels and keeps `confidence` as `"Low"`, `"Medium"`, or `"High"`.

```json theme={null}
{
  "stage": "STAGE_SUCCESS",
  "text": "AI-assisted passage. Human passage.",
  "version": "4.0",
  "headline": "AI Assisted",
  "prediction": "We believe that this text is a mix of AI-assisted and human-written content.",
  "prediction_short": "Mixed",
  "fraction_ai": 0.0,
  "fraction_ai_assisted": 0.6,
  "fraction_human": 0.4,
  "num_ai_segments": 0,
  "num_ai_assisted_segments": 1,
  "num_human_segments": 1,
  "windows": [
    {
      "text": "AI-assisted passage. ",
      "label": "AI-Assisted",
      "ai_assistance_score": 0.55,
      "confidence": "High",
      "start_index": 0,
      "end_index": 21,
      "word_count": 2,
      "token_length": 5,
      "is_humanized": true,
      "humanizer_score": 0.91
    },
    {
      "text": "Human passage.",
      "label": "Human Written",
      "ai_assistance_score": 0.02,
      "confidence": "Medium",
      "start_index": 21,
      "end_index": 35,
      "word_count": 2,
      "token_length": 4,
      "is_humanized": false,
      "humanizer_score": 0.0
    }
  ]
}
```

**Failed Response**

```json theme={null}
{
  "stage": "STAGE_FAILED",
  "text": "",
  "version": "",
  "headline": "preprocessing: Input text contains no valid text after preprocessing",
  "prediction": "",
  "prediction_short": "",
  "fraction_ai": 0.0,
  "fraction_ai_assisted": 0.0,
  "fraction_human": 0.0,
  "num_ai_segments": 0,
  "num_ai_assisted_segments": 0,
  "num_human_segments": 0,
  "windows": []
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.