Train

Using the training endpoint is relevant if you want to programmatically index your content, for instance in a GitHub action. If you don't need this level of automation, we recommend that you use the Markprompt dashboard, which offers simple tools such as GitHub sync to make the process easy and setup-free.

Train content

1POST https://api.markprompt.com/train

Creates and indexes embeddings for your content.

The endpoint accepts two types of payloads:

  • A JSON payload.
  • A file payload, for uploading a zip file or a plain text file.

Request body (JSON)

In the case of a JSON payload, the content type header must be application/json. The JSON payload must be of the form:

KeyTypeDescription
filesarray

A set of objects with the keys: id a unique identifier for your file, for instance its path in a file system; content the textual content of the file.

Example request:

1curl https://api.markprompt.com/train \
2  -X POST \
3  -H "Authorization: Bearer <TOKEN>" \
4  -H "Content-Type: application/json" \
5  -H "X-Markprompt-API-Version: 2024-03-23" \
6  -d '{
7    "files": [
8      { "path": "file_path_1", "content": "..." },
9      { "path": "file_path_2", "content": "..." },
10    ]
11  }'

Request body (file)

In the case of a file payload, the content type header must be application/zip or application/octet-stream.

Example request:

1curl "https://api.markprompt.com/train" \
2  -X POST \
3  -H "Authorization: Bearer <TOKEN>" \
4  -H "Content-Type: application/zip" \
5  -H "X-Markprompt-API-Version: 2024-03-23" \
6  --data-binary @data.zip

Here is an example in JavaScript that reads a file from disk and sends it to the /train endpoint:

1const fs = require('fs');
2
3const file = fs.createReadStream('data.zip');
4
5await fetch('https://api.markprompt.com/train', {
6  method: 'POST',
7  body: file,
8  headers: {
9    Authorization: 'Bearer <TOKEN>',
10    'Content-Type': 'application/zip',
11    'X-Markprompt-API-Version': '2024-03-23',
12  },
13});

Request headers

  • Authorization

    The authorization header, carrying the bearer token.

  • Content-Type

    The content type of the payload. Currently supported values are application/json, application/zip and application/octet-stream.

  • x-markprompt-force-retrain

    By default, if a file has been trained, sending it again with the same content will not retrain the file. If for some reason you want to force a retraining, you can pass a long this header with the value set to true.