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

# Analysis jobs

*What you'll get: how to submit an analysis job, follow its progress, and download its results and masks.*

{% hint style="info" %}
Before you submit a job, upload the files to Biodock, and have an active model (pipeline) in a project you own. In a workspace, any workspace project you can see counts. Models are trained and activated in the app only, and Biodock's own models can't be run through the API.
{% endhint %}

## Submit an analysis job

To submit an analysis job, use the following endpoint. It charges your account just as running the analysis in the app does, and is refused if you don't have enough credits or 400 MB of free storage. A commercial account without a contract is refused with `403` and *"You cannot run AI analysis yet. Please reach out to <sales@biodock.ai>"*.

## Submit analysis job

<mark style="color:green;">`POST`</mark> `https://app.biodock.ai/api/external/analysis-jobs`

#### Headers

| Name                                        | Type   | Description |
| ------------------------------------------- | ------ | ----------- |
| X-API-KEY<mark style="color:red;">\*</mark> | String | API key.    |

#### Request Body

| Name                                            | Type          | Description                                                                                                                |
| ----------------------------------------------- | ------------- | -------------------------------------------------------------------------------------------------------------------------- |
| pipelineId<mark style="color:red;">\*</mark>    | String        | ID of the active pipeline to run. Get it from [List pipelines](https://docs.biodock.ai/public-api/resources/pipelines.md). |
| filesystemIds<mark style="color:red;">\*</mark> | List\[String] | IDs of the files and folders to analyze. A folder includes every file inside it, including in subfolders.                  |
| name                                            | String        | Name of the job. Defaults to a name made from the items you selected.                                                      |

{% tabs %}
{% tab title="200: OK " %}

```javascript
{
    id: "0123456789",
    percentageCompleted: 0,
    status: "PENDING"
}
```

{% endtab %}
{% endtabs %}

## Fetch an analysis job

You can view progress for your analysis job using the following endpoint. Use the `id` the API gave you, not the ID in the app's address bar (see [Find IDs](https://docs.biodock.ai/public-api/authentication.md#find-ids)). Once the job has `SUCCEEDED` or `PARTIALLY_SUCCEEDED`, the response includes download links to the per-object data (`objectsDataCSVUrl`) and the aggregate data (`aggregateDataCSVUrl`) as CSV files. The links work for 24 hours; fetch the job again for new ones.

A job's `status` is one of `PENDING`, `BATCH_PROCESSING`, `FINALIZING`, `SUCCEEDED`, `PARTIALLY_SUCCEEDED`, `FAILED`, `CANCELLED`, `UNDER_REVIEW` or `DEEP_ARCHIVED`.

## Fetch analysis job

<mark style="color:blue;">`GET`</mark> `https://app.biodock.ai/api/external/analysis-jobs/{id}`

#### Path Parameters

| Name                                 | Type   | Description |
| ------------------------------------ | ------ | ----------- |
| id<mark style="color:red;">\*</mark> | String |             |

#### Headers

| Name                                        | Type   | Description |
| ------------------------------------------- | ------ | ----------- |
| X-API-KEY<mark style="color:red;">\*</mark> | String | API key.    |

{% tabs %}
{% tab title="200: OK " %}

```javascript
{
    analysisJob: {
        id: "0123456789",
        percentageCompleted: 100,
        status: "SUCCEEDED",
        objectsDataCSVUrl: "https://...",
        aggregateDataCSVUrl: "https://..."
    }
}
```

{% endtab %}
{% endtabs %}

Fetching a finished job prepares fresh download links each time, so it can take a few seconds. To follow many jobs, list them with a small `limit` and fetch the one you need.

## List analysis jobs

You can view progress for all your analysis jobs using the following endpoint. Jobs come newest first, and jobs in the trash are not included. `count` is the total number of jobs, not the number on this page.

* **In your personal account**, it returns the analysis jobs you ran. Jobs shared with you by someone else are not included.
* **In a workspace**, it returns every analysis in the workspace you can see, including other members' analyses shared with you or with everyone.

## List analysis jobs

<mark style="color:blue;">`GET`</mark> `https://app.biodock.ai/api/external/analysis-jobs`

#### Query Parameters

| Name          | Type   | Description                                                         |
| ------------- | ------ | ------------------------------------------------------------------- |
| limit         | Number | Maximum number of results to return, from 1 to 100. Defaults to 10. |
| startingAfter | String | Pagination cursor: the `id` of the last job on the previous page.   |

#### Headers

| Name                                        | Type   | Description |
| ------------------------------------------- | ------ | ----------- |
| X-API-KEY<mark style="color:red;">\*</mark> | String | API key.    |

{% tabs %}
{% tab title="200: OK " %}

```javascript
{
    results: [{
        id: "0123456789",
        percentageCompleted: 100,
        status: "SUCCEEDED",
        objectsDataCSVUrl: "https://...",
        aggregateDataCSVUrl: "https://..."
    }],
    count: 1
}
```

{% endtab %}
{% endtabs %}

## Download masks

Masks data is not generated by default during an analysis job. If you would like to obtain the masks data for your analysis job, you must first generate the masks data with the following endpoint. The job must have `SUCCEEDED` or `PARTIALLY_SUCCEEDED`. If masks were already generated for the job, you get that request back instead of a new one.

## Submit download masks job

<mark style="color:green;">`POST`</mark> `https://app.biodock.ai/api/external/analysis-jobs/{id}/download-masks`

#### Path Parameters

| Name                                 | Type   | Description |
| ------------------------------------ | ------ | ----------- |
| id<mark style="color:red;">\*</mark> | String |             |

#### Headers

| Name                                        | Type   | Description |
| ------------------------------------------- | ------ | ----------- |
| X-API-KEY<mark style="color:red;">\*</mark> | String | API key.    |

{% tabs %}
{% tab title="200: OK " %}

```javascript
{
    downloadMasksJob: {
        percentageCompleted: 0,
        status: "SUBMITTED"
    }
}
```

{% endtab %}
{% endtabs %}

Once the masks generation has completed, the download link to the masks will be available. You can view the progress and obtain the download link with the following endpoint. `status` is one of `SUBMITTED`, `IN_PROGRESS`, `SUCCEEDED` or `FAILED`, and the `masksZipUrl` link works for 24 hours.

## Fetch download masks job

<mark style="color:blue;">`GET`</mark> `https://app.biodock.ai/api/external/analysis-jobs/{id}/download-masks`

#### Path Parameters

| Name                                 | Type   | Description |
| ------------------------------------ | ------ | ----------- |
| id<mark style="color:red;">\*</mark> | String |             |

#### Headers

| Name                                        | Type   | Description |
| ------------------------------------------- | ------ | ----------- |
| X-API-KEY<mark style="color:red;">\*</mark> | String | API key.    |

{% tabs %}
{% tab title="200: OK " %}

```javascript
{
    downloadMasksJob: {
        percentageCompleted: 100,
        status: "SUCCEEDED",
        masksZipUrl: "https://..."
    }
}
```

{% endtab %}
{% endtabs %}

## Errors

| Response                                                                         | Why                                                                                                 |
| -------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
| `400` *"Cannot create analysis because pipelineId is invalid"*                   | The pipeline isn't an active model you can run.                                                     |
| `400` *"Cannot create analysis because one or more filesystemIds are invalid"*   | A file or folder ID doesn't exist, or isn't yours to analyse.                                       |
| `400` *"Invalid analysis job id"*                                                | The job ID isn't in the right format, for example because it was copied from the app's address bar. |
| `404` *"Analysis job not found"*                                                 | No job with that ID that you can see.                                                               |
| `400` *"Cannot download masks for analysis job that has not succeeded…"*         | The job hasn't `SUCCEEDED` or `PARTIALLY_SUCCEEDED`.                                                |
| `404` *"Download masks job not found"*                                           | Masks haven't been generated for this job yet.                                                      |
| `403` *"You cannot run AI analysis yet. Please reach out to <sales@biodock.ai>"* | A commercial account without a contract.                                                            |

## Sample usage

Submitting an analysis job

```python
import requests

API_KEY = "" # Replace with your api key
FILESYSTEM_IDS = [""] # Replace with your filesystem ids. Add to the list as necessary
PIPELINE_ID = "" # Replace with your pipeline id

URL = "https://app.biodock.ai/api/external/analysis-jobs"
headers = {"X-API-KEY": API_KEY, "Content-Type": "application/json"}
data = {"filesystemIds": FILESYSTEM_IDS, "pipelineId": PIPELINE_ID}

response = requests.post(URL, json=data, headers=headers)
print(response.text)

```

View the progress of a specific analysis job

```python
import requests

API_KEY = "" # Replace with your api key
ANALYSIS_JOB_ID = "" # Replace with your analysis job id

URL = f"https://app.biodock.ai/api/external/analysis-jobs/{ANALYSIS_JOB_ID}"
headers = {"X-API-KEY": API_KEY, "Content-Type": "application/json"}

response = requests.get(URL, headers=headers)
print(response.text)
```

View the progress of all your analysis jobs

```python
import requests

API_KEY = "" # Replace with your api key

URL = "https://app.biodock.ai/api/external/analysis-jobs"
headers = {"X-API-KEY": API_KEY, "Content-Type": "application/json"}

response = requests.get(URL, headers=headers)
print(response.text)
```

Generate masks data for an analysis job

```python
import requests

API_KEY = "" # Replace with your api key
ANALYSIS_JOB_ID = "" # Replace with your analysis job id

URL = f"https://app.biodock.ai/api/external/analysis-jobs/{ANALYSIS_JOB_ID}/download-masks"
headers = {"X-API-KEY": API_KEY, "Content-Type": "application/json"}

response = requests.post(URL, headers=headers)
print(response.text)
```

View the progress of masks generation

```python
import requests

API_KEY = "" # Replace with your api key
ANALYSIS_JOB_ID = "" # Replace with your analysis job id

URL = f"https://app.biodock.ai/api/external/analysis-jobs/{ANALYSIS_JOB_ID}/download-masks"
headers = {"X-API-KEY": API_KEY, "Content-Type": "application/json"}

response = requests.get(URL, headers=headers)
print(response.text)
```


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.biodock.ai/public-api/resources/analysis-jobs.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
