> For the complete documentation index, see [llms.txt](https://k-ai.gitbook.io/knowledge-ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://k-ai.gitbook.io/knowledge-ai/sources-and-ingestion/instance-api/orchestrator.md).

# Orchestrator

The Orchestrator endpoints drive document indexation: starting jobs, tracking their status, and managing re-indexation.

Authenticated with `instance-id` + `api-key` headers — see [Instance API keys](/knowledge-ai/authentication/api-keys.md).

***

## POST /api/orchestrator/differential-indexation

Relaunch partial indexation. All documents that have been created, updated, or deleted in the Document Repository since the last indexation will be reindexed or removed from the K-AI index. Runtime varies with the size of the repository and the complexity of the documents involved.

{% openapi src="/files/ggZwaT7KDX2BbCKblljY" path="/api/orchestrator/differential-indexation" method="post" %}
[instance-api.yaml](https://3937809777-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F85gF5n5kGsNQKMPwm2VR%2Fuploads%2Fgit-blob-8f3d896df32794f28ab6f557a94cbd117983f7c2%2Finstance-api.yaml?alt=media)
{% endopenapi %}

{% tabs %}
{% tab title="curl" %}

```bash
curl -X POST https://api.kai-studio.ai/api/orchestrator/differential-indexation \
  -H "instance-id: <YOUR_INSTANCE_ID>" \
  -H "api-key: <YOUR_API_KEY>"
```

{% endtab %}

{% tab title="Python" %}

```python
import httpx

response = httpx.post(
    "https://api.kai-studio.ai/api/orchestrator/differential-indexation",
    headers={
        "instance-id": "<YOUR_INSTANCE_ID>",
        "api-key": "<YOUR_API_KEY>",
    },
)
response.raise_for_status()
print(response.json())
```

{% endtab %}

{% tab title="TypeScript" %}

```ts
const response = await fetch(
  "https://api.kai-studio.ai/api/orchestrator/differential-indexation",
  {
    method: "POST",
    headers: {
      "instance-id": "<YOUR_INSTANCE_ID>",
      "api-key": "<YOUR_API_KEY>",
    },
  },
);
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(await response.json());
```

{% endtab %}
{% endtabs %}

***

## POST /api/orchestrator/reindex-document

Reindex a single document. If the document has been deleted from the Document Repository, it will be removed from the index. If it has been updated, it will be reindexed with the new content.

{% openapi src="/files/ggZwaT7KDX2BbCKblljY" path="/api/orchestrator/reindex-document" method="post" %}
[instance-api.yaml](https://3937809777-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F85gF5n5kGsNQKMPwm2VR%2Fuploads%2Fgit-blob-8f3d896df32794f28ab6f557a94cbd117983f7c2%2Finstance-api.yaml?alt=media)
{% endopenapi %}

{% tabs %}
{% tab title="curl" %}

```bash
curl -X POST https://api.kai-studio.ai/api/orchestrator/reindex-document \
  -H "instance-id: <YOUR_INSTANCE_ID>" \
  -H "api-key: <YOUR_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{"id": "doc_abc123"}'
```

{% endtab %}

{% tab title="Python" %}

```python
import httpx

response = httpx.post(
    "https://api.kai-studio.ai/api/orchestrator/reindex-document",
    headers={
        "instance-id": "<YOUR_INSTANCE_ID>",
        "api-key": "<YOUR_API_KEY>",
    },
    json={"id": "doc_abc123"},
)
response.raise_for_status()
print(response.json())
```

{% endtab %}

{% tab title="TypeScript" %}

```ts
const response = await fetch(
  "https://api.kai-studio.ai/api/orchestrator/reindex-document",
  {
    method: "POST",
    headers: {
      "instance-id": "<YOUR_INSTANCE_ID>",
      "api-key": "<YOUR_API_KEY>",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ id: "doc_abc123" }),
  },
);
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(await response.json());
```

{% endtab %}
{% endtabs %}

***

## POST /api/orchestrator/retry-documents-parsing-error

Launch a task to retry indexation for all documents currently in a parsing-error state. Useful after fixing upstream issues (corrupted files replaced, parser updated, etc).

{% openapi src="/files/ggZwaT7KDX2BbCKblljY" path="/api/orchestrator/retry-documents-parsing-error" method="post" %}
[instance-api.yaml](https://3937809777-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F85gF5n5kGsNQKMPwm2VR%2Fuploads%2Fgit-blob-8f3d896df32794f28ab6f557a94cbd117983f7c2%2Finstance-api.yaml?alt=media)
{% endopenapi %}

***

## POST /api/orchestrator/count-back-tasks

Count all registered background tasks — both in-progress and waiting to be launched — grouped by agent (task type) name. Useful for monitoring indexation workload.

{% openapi src="/files/ggZwaT7KDX2BbCKblljY" path="/api/orchestrator/count-back-tasks" method="post" %}
[instance-api.yaml](https://3937809777-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F85gF5n5kGsNQKMPwm2VR%2Fuploads%2Fgit-blob-8f3d896df32794f28ab6f557a94cbd117983f7c2%2Finstance-api.yaml?alt=media)
{% endopenapi %}

{% tabs %}
{% tab title="curl" %}

```bash
curl -X POST https://api.kai-studio.ai/api/orchestrator/count-back-tasks \
  -H "instance-id: <YOUR_INSTANCE_ID>" \
  -H "api-key: <YOUR_API_KEY>"
```

{% endtab %}

{% tab title="Python" %}

```python
import httpx

response = httpx.post(
    "https://api.kai-studio.ai/api/orchestrator/count-back-tasks",
    headers={
        "instance-id": "<YOUR_INSTANCE_ID>",
        "api-key": "<YOUR_API_KEY>",
    },
)
response.raise_for_status()
print(response.json())
```

{% endtab %}

{% tab title="TypeScript" %}

```ts
const response = await fetch(
  "https://api.kai-studio.ai/api/orchestrator/count-back-tasks",
  {
    method: "POST",
    headers: {
      "instance-id": "<YOUR_INSTANCE_ID>",
      "api-key": "<YOUR_API_KEY>",
    },
  },
);
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(await response.json());
```

{% endtab %}
{% endtabs %}

The response is a flat map of agent name to active-or-pending task count, e.g. `{"PartialIndexingAgent": 1, "RemoveDocumentAgent": 3}`.

***

## POST /api/orchestrator/count-tasks-for-doc

Count in-progress and pending background tasks for a specific document, grouped by agent name.

{% openapi src="/files/ggZwaT7KDX2BbCKblljY" path="/api/orchestrator/count-tasks-for-doc" method="post" %}
[instance-api.yaml](https://3937809777-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F85gF5n5kGsNQKMPwm2VR%2Fuploads%2Fgit-blob-8f3d896df32794f28ab6f557a94cbd117983f7c2%2Finstance-api.yaml?alt=media)
{% endopenapi %}

***

## POST /api/orchestrator/check-kb-credentials

Verify that all configured Document Repository credentials are valid. If every credential passes validation, the indexation pipeline is automatically reactivated. If a check task already exists with status CREATED, its `launch_after_date` is moved to now instead of creating a duplicate.

{% openapi src="/files/ggZwaT7KDX2BbCKblljY" path="/api/orchestrator/check-kb-credentials" method="post" %}
[instance-api.yaml](https://3937809777-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F85gF5n5kGsNQKMPwm2VR%2Fuploads%2Fgit-blob-8f3d896df32794f28ab6f557a94cbd117983f7c2%2Finstance-api.yaml?alt=media)
{% endopenapi %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://k-ai.gitbook.io/knowledge-ai/sources-and-ingestion/instance-api/orchestrator.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
