> For the complete documentation index, see [llms.txt](https://docs.getantidote.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.getantidote.com/welcome-to-antidote/integrations/graphql-api.md). Agents can also search and read this documentation through its [MCP server](https://docs.getantidote.com/~gitbook/mcp).

# GraphQL API

Query Antidote data and trigger runs programmatically.

The Antidote GraphQL API gives you programmatic access to products and runs.

### Next steps

For a complete CI walkthrough, see [Triggering explorations from any CI](https://docs.getantidote.com/welcome-to-antidote/integrations/triggering-explorations-from-any-ci.md). It covers token exchange and the preview and environment flows.

### Endpoint

```
POST https://platform.duku.ai/graphql
```

### Authentication

Every request requires a Bearer token in the `Authorization` header. Use the OAuth2 client credentials flow described in [API Keys](https://docs.getantidote.com/welcome-to-antidote/integrations/api-keys.md).

### Request format

All requests use an HTTP `POST` with a JSON body:

```json
{
  "query": "query { subjects { id name } }",
  "variables": {}
}
```

Example request:

```bash
curl -X POST https://platform.duku.ai/graphql \
  -H "Authorization: Bearer <access_token>" \
  -H "Content-Type: application/json" \
  -d '{"query": "{ subjects { id name } }"}'
```

{% hint style="info" %}
Example IDs such as `sms_...` (products), `smt_...` (preview builds), and `key_...` are placeholders.
{% endhint %}

### Queries

* [Issues API](https://docs.getantidote.com/welcome-to-antidote/integrations/issues-api.md)

#### List products

```graphql
query {
  subjects {
    id
    name
  }
}
```

#### List runs

Use this query to retrieve runs. Arguments are `subjectId`, `environmentId`, `batchId`, `appVersionId`, `limit` (default `50`), `offset` (default `0`), `status`, `approach`, `search`, `sortBy`, `sortDirection` and `outcome`. `targetUnavailable` on a run is `true` when the URL under test never answered, so the run could not start. The response is `PaginatedRuns { runs, hasMore, totalCount }`.

```graphql
query GetRuns($environmentId: ID) {
  runs(environmentId: $environmentId) {
    hasMore
    totalCount
    runs {
      id
      name
      status
      outcome
      exceptionCount
      startTime
      endTime
    }
  }
}
```

`batch(id) { runs }` returns at most the 200 most recent runs. For more, page through `runs(batchId: ...)` with `limit` and `offset`.

#### Get run details

```graphql
query GetRun($id: ID!) {
  run(id: $id) {
    id
    name
    status
    exceptionCount
    startTime
    endTime
    outcome
  }
}
```

Run statuses are lowercase: `pending`, `running`, `completed`, or `not_completed`. A run that concluded is `completed` whatever it found. A run that checks a flow carries its result on `outcome`: `passed`, `failed` or `inconclusive`. Exploration runs report what they find as issues, so their `outcome` is `null`.

### Mutations

#### Register a preview build

Use `upsertSimulationTarget` to register a pull request's preview build. It returns the build's ID, which `startExploration` takes as `targetId`. Call it again on later pushes to update the same build.

`buildKey` is the stable identity key for the build. Antidote deduplicates by `subjectId` + `buildKey`. If you call the mutation again with the same pair, Antidote updates the existing build instead of creating a duplicate.

For a pull request, use a stable key such as `github:repo=owner/repo:pr=123`. A pull request key like this records a preview build, so the product needs Preview deployments added first: an organisation admin adds them in **Product settings → Environments**. Without them the call is refused with `FORBIDDEN` and `extensions.reason` `PREVIEW_DEPLOYMENTS_REQUIRED`.

Required input fields:

* `subjectId`: your Product ID
* `buildKey`: the stable identity key
* `name`: the build name shown in the Antidote dashboard

Optional input fields:

* `description`
* `version`
* `environment`
* `buildNumber`
* `metadata`

`commitSha`, `parentCommitSha`, `lineage`, `label` and `environmentId` record the build as a release on an environment. Once you send `commitSha`, `buildKey` must identify that one commit (for example `github:repo=owner/repo:pr=123:sha=<sha>`).

A preview build takes its URL from its product, so there is no URL to set here. To explore a specific URL, pass `url` on `startExploration` (see below).

* `buildUrl` is deprecated and ignored. A build takes its URL from its product; pass a per-run `url` on `startExploration` instead. Use `metadata` for any build context you want to keep with the build.

```graphql
mutation Upsert($input: UpsertSimulationTargetInput!) {
  upsertSimulationTarget(input: $input) {
    id
    name
    version
  }
}
```

Example variables:

```json
{
  "input": {
    "subjectId": "sms_product_id",
    "buildKey": "github:repo=owner/repo:pr=123",
    "name": "PR #123"
  }
}
```

#### Start an exploration

```graphql
mutation StartExploration($input: StartExplorationInput!) {
  startExploration(input: $input) {
    id
    status
    executionId
    warnings
  }
}
```

Variables:

```json
{
  "input": {
    "environmentId": "env_...", "triggerSource": "CI"
  }
}
```

Supported input fields:

* `targetId`: the ID of a preview build from `upsertSimulationTarget`
* `url`: URL to explore. For an API-key caller this per-run URL is treated as an override, and is only honoured when you also send `triggerSource: "CI"` (see below). Without it the `url` is ignored and the run uses the product's base URL (a preview build takes its URL from its product).
* `changeRequest`: the pull request or merge request this build belongs to, so Antidote tests it and reports on it: `{ provider: GITHUB, repository: "owner/repo", number: 123 }`. For a GitLab merge request, send `provider: GITLAB`, the project path as `repository`, the project's numeric ID as `repositoryId` and the merge request IID as `number`, and add `host` for a self-managed instance. `headSha` is optional. When you send it, use the pull request's current head commit, never a merge commit: any other commit is not tested. The older `githubRepository` and `githubPrNumber` fields still work.
* `serverManagedComment`: boolean
* `triggerSource`: optional enum declaring where the run was triggered. Send `CI` from any CI provider, such as GitHub Actions, CircleCI or GitLab CI (the deprecated alias `GITHUB_ACTION` is treated identically). **Required whenever you pass `url`** from an API-key caller: it authorises the per-run URL override. It also labels the run as CI-triggered in your dashboards. Every other origin is derived from your credentials and cannot be declared here.
* `credentialSetId`: optional string that selects a saved persona by ID or name. Credential fields from the set take precedence over inline values. Ignored on a GitHub pull request.
* `inputValues`: ignored. Antidote's runs plan their own input, and `warnings` says so.
* `waitForTargetSeconds`: optional. Wait for the URL to start serving before the exploration starts. Longer waits are shortened to the maximum, with a note in `warnings`. Ignored on a GitHub pull request.
* `environmentId`: explore whatever an environment currently serves (the environment needs a release recorded first). Use it instead of `targetId` and `url`.

The response includes `warnings` (a list of strings). When you name a GitHub pull request, Antidote tests it and its GitHub App posts the PR comment and check run. With `serverManagedComment: true` and a `headSha`, Antidote also concludes the check as Not tested when it cannot test that commit.

{% hint style="info" %}
**PR comments are posted by the Antidote GitHub App, not GitHub Actions**

The App is a one-time install on the repository that lets Antidote's platform post comments through the GitHub API. It is not GitHub Actions and uses no CI minutes.

Each product posts one sticky comment per PR. Later builds on the same PR update that comment in place.
{% endhint %}

#### Reading a result

Outside a GitHub pull request, `startExploration` starts an execution and returns its ID in both `id` and `executionId`; `batch` is empty. Follow the execution with `agenticExecution`:

```graphql
query Execution($id: ID!) {
  agenticExecution(id: $id) {
    id kind status total passed failed inconclusive needsSetup pending
    runs { id status outcome }
  }
}
```

`status` is `QUEUED` or `RUNNING` while the execution is in flight, and `COMPLETED`, `FAILED` or `INTERRUPTED` once it ends. Once `status` has ended and `pending` is `0`, every flow it checked has its result in `passed`, `failed`, `inconclusive` or `needsSetup`. Antidote chooses the pages and the number of runs itself, so `maxPages`, `numberOfRuns`, `maxParallelRuns` and `inputValues` are ignored and `warnings` says so.

On a GitHub pull request, Antidote tests the change with a pull request test instead: the response is a finished batch with no runs and no `executionId`, and the result is reported on the pull request. Find the test with `agenticExecutionsConnection(subjectId: "sms_...", targetId: "smt_...", kind: PR_TEST, first: 1)` and follow it the same way. To list a product's recent executions, use `agenticExecutionsConnection(subjectId: "sms_...", first: 20)`. To list its runs, use `runs(subjectId: "sms_...")`, as in List runs above.

### Trigger from any CI

Use this flow from CircleCI, GitLab CI, Jenkins, or any other pipeline. No GitHub Action is required.

1. Exchange the API key for an access token.

```bash
DECODED_KEY=$(printf '%s' "$PLATFORM_API_KEY" | base64 --decode)
CLIENT_ID=${DECODED_KEY%%:*}
CLIENT_SECRET=${DECODED_KEY#*:}

TOKEN=$(curl -s -X POST https://auth.duku.ai/realms/duku/protocol/openid-connect/token \
  -d "grant_type=client_credentials" \
  -d "client_id=$CLIENT_ID" \
  -d "client_secret=$CLIENT_SECRET" | jq -r '.access_token')
```

2. Register the preview build, then capture its ID.

```bash
TARGET_ID=$(curl -s -X POST https://platform.duku.ai/graphql \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "mutation Upsert($input: UpsertSimulationTargetInput!) { upsertSimulationTarget(input: $input) { id } }",
    "variables": {
      "input": {
        "subjectId": "sms_product_id",
        "buildKey": "github:repo=owner/repo:pr=123",
        "name": "PR #123"
      }
    }
  }' | jq -r '.data.upsertSimulationTarget.id')
```

3. Start the exploration with the build ID, URL, PR metadata, and CI trigger source. `triggerSource: "CI"` is required here because a `url` is passed.

```bash
curl -X POST https://platform.duku.ai/graphql \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d "{
    \"query\": \"mutation StartExploration(\$input: StartExplorationInput!) { startExploration(input: \$input) { id status } }\",
    \"variables\": {
      \"input\": {
        \"targetId\": \"$TARGET_ID\",
        \"url\": \"https://preview.example.com\",
        \"changeRequest\": { \"provider\": \"GITHUB\", \"repository\": \"owner/repo\", \"number\": 123 },
        \"serverManagedComment\": true,
        \"triggerSource\": \"CI\"
      }
    }
  }"
```

### End-to-end cURL example

```bash
DECODED_KEY=$(printf '%s' "$PLATFORM_API_KEY" | base64 --decode)
CLIENT_ID=${DECODED_KEY%%:*}
CLIENT_SECRET=${DECODED_KEY#*:}

TOKEN=$(curl -s -X POST https://auth.duku.ai/realms/duku/protocol/openid-connect/token \
  -d "grant_type=client_credentials" \
  -d "client_id=$CLIENT_ID" \
  -d "client_secret=$CLIENT_SECRET" | jq -r '.access_token')

curl -X POST https://platform.duku.ai/graphql \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "mutation StartExploration($input: StartExplorationInput!) { startExploration(input: $input) { id status executionId warnings } }",
    "variables": {
      "input": {
        "environmentId": "env_your_environment_id", "triggerSource": "CI"
      }
    }
  }'
```

### Schema introspection

Schema introspection is disabled on the production endpoint: `__schema` and `__type` queries fail validation. Write queries against the operations documented here.

### Common errors

| Code                        | Meaning                                                                                                                                                                                                                                                                                                                                  |
| --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `UNAUTHENTICATED`           | Missing or invalid access token                                                                                                                                                                                                                                                                                                          |
| `FORBIDDEN`                 | Insufficient permissions for this operation. Refusals for a feature your organisation does not have carry `extensions.reason`, for example `PREVIEW_DEPLOYMENTS_REQUIRED` when a pull request build is sent to a product without Preview deployments                                                                                     |
| `NOT_FOUND`                 | The resource does not exist, or belongs to another organisation                                                                                                                                                                                                                                                                          |
| `BAD_USER_INPUT`            | Invalid input, including a missing URL when no override was sent and the product has no base URL, such as an environment with nothing deployed or no URL                                                                                                                                                                                 |
| `GRAPHQL_VALIDATION_FAILED` | The query names a field, argument or enum value the API does not have. Nothing ran.                                                                                                                                                                                                                                                      |
| `CONFLICT`                  | The request conflicts with the current state, such as a duplicate or a concurrent change, such as re-sending a `buildKey` for a different commit, or reaching the 10 API keys per user limit, or calls that would start more than the product's 10 runs in any 10 minutes, where each `recordManualRelease` call counts one run per flow |
| `ORG_NOT_LINKED`            | The organisation is not fully provisioned                                                                                                                                                                                                                                                                                                |
| `INTERNAL_SERVER_ERROR`     | An unexpected failure. The message is always `Something went wrong. Please try again.` and `extensions.correlationId` carries an id to quote to support                                                                                                                                                                                  |

Most GraphQL errors are returned with HTTP 200, so check the response body for an `errors` array rather than relying on the status code. A variable with the wrong type or enum value is the exception: it returns HTTP 400. Unexpected errors are masked to `INTERNAL_SERVER_ERROR` with a fixed message; the codes above always carry a specific one.

Three common causes: sending the base64 API key as the Bearer token instead of exchanging it first returns `UNAUTHENTICATED`; naming a product that belongs to another organisation returns `NOT_FOUND`; and getting an enum's casing wrong rejects the whole request. There is no `data`, and the reason is in `errors[]`: with code `GRAPHQL_VALIDATION_FAILED` when the value is written in the query, and with HTTP 400 and no code when it comes from a variable.
