Add a file to a knowledge base
POST
https://gptunnel.ru/v1/database/file/addSend the text and the databaseId from the knowledge base list. The endpoint queues the file for processing. Save the response’s id and send it as fileId when you check the file’s status.
Request headers
| Parameter | Type | Description |
|---|---|---|
Authorization* | string | API key |
Request parameters
| Parameter | Type | Description |
|---|---|---|
databaseId* | string | Knowledge base ID |
text* | string | File contents as text |
name | string | File name |
chunkSize | number | Chunk size in tokens. Integer from 0 to 32767. The default is 1024, which is also used when you send 0. |
overlapSize | number | Overlap between adjacent chunks in tokens. Integer from 0 to 32767. The default is 128. Set it to 0 to disable overlap. |
splitVariable | string | Text delimiter, up to 12 characters. If this field is nonempty, splitting ignores chunkSize and overlapSize. |
When processing the file, the service raises chunk sizes below 256 tokens to 256 and caps overlap at half the chunk size. With splitVariable, it splits the text at the delimiter first. Longer pieces are then split into chunks of up to 4096 tokens without overlap.
Example request
Section titled “Example request”Set GPTUNNEL_API_KEY to your API key and GPTUNNEL_DATABASE_ID to the ID from the knowledge base list. The cURL example requires version 8.3 or later.
import jsonimport osfrom urllib.request import Request, urlopen
fields = { 'databaseId': os.environ['GPTUNNEL_DATABASE_ID'], 'name': 'Sample document', 'text': 'The sample document code is NORTH-17.',}request = Request( 'https://gptunnel.ru/v1/database/file/add', headers={'Authorization': os.environ['GPTUNNEL_API_KEY'], 'Content-Type': 'application/json'}, method='POST', data=json.dumps(fields).encode('utf-8'),)with urlopen(request, timeout=30) as response: print(json.load(response))curl --fail-with-body \ 'https://gptunnel.ru/v1/database/file/add' \ --header "Authorization: ${GPTUNNEL_API_KEY:?Set GPTUNNEL_API_KEY}" \ --variable '%GPTUNNEL_DATABASE_ID' \ --header 'Content-Type: application/json' \ --expand-data '{"databaseId": "{{GPTUNNEL_DATABASE_ID:json}}", "name": "Sample document", "text": "The sample document code is NORTH-17."}'const key = process.env.GPTUNNEL_API_KEYif (!key) throw new Error('Set GPTUNNEL_API_KEY')const databaseId = process.env.GPTUNNEL_DATABASE_IDif (!databaseId) throw new Error('Set GPTUNNEL_DATABASE_ID')
const url = new URL('https://gptunnel.ru/v1/database/file/add')const response = await fetch(url, { method: 'POST', headers: { Authorization: key, 'Content-Type': 'application/json' }, body: JSON.stringify({ databaseId, name: 'Sample document', text: 'The sample document code is NORTH-17.', }),})if (!response.ok) throw new Error(await response.text())console.log(await response.json())Example response
Section titled “Example response”Identifiers and time are given for example.
{ "id": "66a346f64dcb57627c03d596", "createDate": "2024-07-26T06:49:27.430Z", "status": "idle", "name": "Sample document", "databaseId": "669b1824c0d8dbde07d07d10", "chunkSize": 1024, "overlapSize": 128, "splitVariable": null, "tokenCount": 0, "tokenCost": "0", "error": null, "progress": null, "chunkCount": 0}{ "error": { "message": "Unauthorized", "type": "unauthorized_request_error", "param": null, "code": null }}