curl --request POST \
--url https://api.contextual.ai/v1/datastores/{datastore_id}/documents \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: multipart/form-data' \
--form file='@example-file' \
--form 'metadata={
"custom_metadata": {
"field1": "value1",
"field2": "value2"
}
}' \
--form 'configuration={
"parsing": {
"figure_caption_mode": "custom",
"figure_captioning_prompt": "Generate a detailed caption for each figure."
}
}'import requests
url = "https://api.contextual.ai/v1/datastores/{datastore_id}/documents"
files = { "file": ("example-file", open("example-file", "rb")) }
payload = {
"metadata": "{
\"custom_metadata\": {
\"field1\": \"value1\",
\"field2\": \"value2\"
}
}",
"configuration": "{
\"parsing\": {
\"figure_caption_mode\": \"custom\",
\"figure_captioning_prompt\": \"Generate a detailed caption for each figure.\"
}
}"
}
headers = {"Authorization": "Bearer <token>"}
response = requests.post(url, data=payload, files=files, headers=headers)
print(response.text)const form = new FormData();
form.append('file', '<string>');
form.append('metadata', '{
"custom_metadata": {
"field1": "value1",
"field2": "value2"
}
}');
form.append('configuration', '{
"parsing": {
"figure_caption_mode": "custom",
"figure_captioning_prompt": "Generate a detailed caption for each figure."
}
}');
const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};
options.body = form;
fetch('https://api.contextual.ai/v1/datastores/{datastore_id}/documents', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.contextual.ai/v1/datastores/{datastore_id}/documents",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"metadata\"\r\n\r\n{\r\n \"custom_metadata\": {\r\n \"field1\": \"value1\",\r\n \"field2\": \"value2\"\r\n }\r\n}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"configuration\"\r\n\r\n{\r\n \"parsing\": {\r\n \"figure_caption_mode\": \"custom\",\r\n \"figure_captioning_prompt\": \"Generate a detailed caption for each figure.\"\r\n }\r\n}\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: multipart/form-data"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.contextual.ai/v1/datastores/{datastore_id}/documents"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"metadata\"\r\n\r\n{\r\n \"custom_metadata\": {\r\n \"field1\": \"value1\",\r\n \"field2\": \"value2\"\r\n }\r\n}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"configuration\"\r\n\r\n{\r\n \"parsing\": {\r\n \"figure_caption_mode\": \"custom\",\r\n \"figure_captioning_prompt\": \"Generate a detailed caption for each figure.\"\r\n }\r\n}\r\n-----011000010111000001101001--")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.contextual.ai/v1/datastores/{datastore_id}/documents")
.header("Authorization", "Bearer <token>")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"metadata\"\r\n\r\n{\r\n \"custom_metadata\": {\r\n \"field1\": \"value1\",\r\n \"field2\": \"value2\"\r\n }\r\n}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"configuration\"\r\n\r\n{\r\n \"parsing\": {\r\n \"figure_caption_mode\": \"custom\",\r\n \"figure_captioning_prompt\": \"Generate a detailed caption for each figure.\"\r\n }\r\n}\r\n-----011000010111000001101001--")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.contextual.ai/v1/datastores/{datastore_id}/documents")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"metadata\"\r\n\r\n{\r\n \"custom_metadata\": {\r\n \"field1\": \"value1\",\r\n \"field2\": \"value2\"\r\n }\r\n}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"configuration\"\r\n\r\n{\r\n \"parsing\": {\r\n \"figure_caption_mode\": \"custom\",\r\n \"figure_captioning_prompt\": \"Generate a detailed caption for each figure.\"\r\n }\r\n}\r\n-----011000010111000001101001--"
response = http.request(request)
puts response.read_body{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}Ingest Document
Ingest a document into a given Datastore.
Ingestion is an asynchronous task. Returns a document id which can be used to track the status of the ingestion job through calls to the GET /datastores/{datastore_id}/documents/{document_id}/metadata API.
This id can also be used to delete the document through the DELETE /datastores/{datastore_id}/documents/{document_id} API.
file must be a PDF, HTML, DOC(X), PPT(X), PNG, JPG, or JPEG file. The filename must end with one of the following extensions: .pdf, .html, .htm, .mhtml, .doc, .docx, .ppt, .pptx, .png, .jpg, .jpeg.
curl --request POST \
--url https://api.contextual.ai/v1/datastores/{datastore_id}/documents \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: multipart/form-data' \
--form file='@example-file' \
--form 'metadata={
"custom_metadata": {
"field1": "value1",
"field2": "value2"
}
}' \
--form 'configuration={
"parsing": {
"figure_caption_mode": "custom",
"figure_captioning_prompt": "Generate a detailed caption for each figure."
}
}'import requests
url = "https://api.contextual.ai/v1/datastores/{datastore_id}/documents"
files = { "file": ("example-file", open("example-file", "rb")) }
payload = {
"metadata": "{
\"custom_metadata\": {
\"field1\": \"value1\",
\"field2\": \"value2\"
}
}",
"configuration": "{
\"parsing\": {
\"figure_caption_mode\": \"custom\",
\"figure_captioning_prompt\": \"Generate a detailed caption for each figure.\"
}
}"
}
headers = {"Authorization": "Bearer <token>"}
response = requests.post(url, data=payload, files=files, headers=headers)
print(response.text)const form = new FormData();
form.append('file', '<string>');
form.append('metadata', '{
"custom_metadata": {
"field1": "value1",
"field2": "value2"
}
}');
form.append('configuration', '{
"parsing": {
"figure_caption_mode": "custom",
"figure_captioning_prompt": "Generate a detailed caption for each figure."
}
}');
const options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};
options.body = form;
fetch('https://api.contextual.ai/v1/datastores/{datastore_id}/documents', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.contextual.ai/v1/datastores/{datastore_id}/documents",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"metadata\"\r\n\r\n{\r\n \"custom_metadata\": {\r\n \"field1\": \"value1\",\r\n \"field2\": \"value2\"\r\n }\r\n}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"configuration\"\r\n\r\n{\r\n \"parsing\": {\r\n \"figure_caption_mode\": \"custom\",\r\n \"figure_captioning_prompt\": \"Generate a detailed caption for each figure.\"\r\n }\r\n}\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: multipart/form-data"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.contextual.ai/v1/datastores/{datastore_id}/documents"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"metadata\"\r\n\r\n{\r\n \"custom_metadata\": {\r\n \"field1\": \"value1\",\r\n \"field2\": \"value2\"\r\n }\r\n}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"configuration\"\r\n\r\n{\r\n \"parsing\": {\r\n \"figure_caption_mode\": \"custom\",\r\n \"figure_captioning_prompt\": \"Generate a detailed caption for each figure.\"\r\n }\r\n}\r\n-----011000010111000001101001--")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.contextual.ai/v1/datastores/{datastore_id}/documents")
.header("Authorization", "Bearer <token>")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"metadata\"\r\n\r\n{\r\n \"custom_metadata\": {\r\n \"field1\": \"value1\",\r\n \"field2\": \"value2\"\r\n }\r\n}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"configuration\"\r\n\r\n{\r\n \"parsing\": {\r\n \"figure_caption_mode\": \"custom\",\r\n \"figure_captioning_prompt\": \"Generate a detailed caption for each figure.\"\r\n }\r\n}\r\n-----011000010111000001101001--")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.contextual.ai/v1/datastores/{datastore_id}/documents")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"metadata\"\r\n\r\n{\r\n \"custom_metadata\": {\r\n \"field1\": \"value1\",\r\n \"field2\": \"value2\"\r\n }\r\n}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"configuration\"\r\n\r\n{\r\n \"parsing\": {\r\n \"figure_caption_mode\": \"custom\",\r\n \"figure_captioning_prompt\": \"Generate a detailed caption for each figure.\"\r\n }\r\n}\r\n-----011000010111000001101001--"
response = http.request(request)
puts response.read_body{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}{
"detail": [
{
"loc": [
"<string>"
],
"msg": "<string>",
"type": "<string>"
}
]
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Path Parameters
Datastore ID of the datastore in which to ingest the document
Body
File to ingest.
Metadata request in stringified JSON format. custom_metadata is a flat dictionary containing one or more key-value pairs, where each value must be a primitive type (str, bool, float, or int). The default maximum metadata fields that can be used is 15, contact support@contextual.ai if more is needed. The combined size of the metadata must not exceed 2 KB when encoded as JSON. The strings with date format must stay in date format or be avoided if not in date format. The custom_metadata.url or link field is automatically included in returned attributions during query time, if provided.
**Example Request Body (as returned by `json.dumps`):**
```json
"{{
\"custom_metadata\": {{
\"topic\": \"science\",
\"difficulty\": 3
}}
}}"
```
{
"custom_metadata": { "field1": "value1", "field2": "value2" }
}
Overrides the datastore's default configuration for this specific document. This allows applying optimized settings tailored to the document's characteristics without changing the global datastore configuration.
{
"parsing": {
"figure_caption_mode": "custom",
"figure_captioning_prompt": "Generate a detailed caption for each figure."
}
}
Response
Successful Response
Response body from POST /data/documents
ID of the document being ingested
Was this page helpful?