TypeScript SDK
import { Orchata } from '@orchata-ai/sdk';
const client = new Orchata({ apiKey: 'oai_your_api_key' });
// Create or update - idempotent operation
const { document, created } = await client.documents.upsert({
spaceId: 'space_123',
filename: 'to-do.md',
content: '# To-Do List\n\n- [x] First task\n- [ ] Second task'
});
console.log(created ? 'Created new document' : 'Updated existing document');curl --request PUT \
--url https://api.orchata.ai/api/documents \
--header 'Content-Type: application/json' \
--header 'Oai-Api-Key: <api-key>' \
--data '
{
"spaceId": "space_123",
"filename": "my-notes.md",
"content": "# My Notes\n\nSome content...",
"metadata": {}
}
'import requests
url = "https://api.orchata.ai/api/documents"
payload = {
"spaceId": "space_123",
"filename": "my-notes.md",
"content": "# My Notes
Some content...",
"metadata": {}
}
headers = {
"Oai-Api-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {'Oai-Api-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
spaceId: 'space_123',
filename: 'my-notes.md',
content: '# My Notes\n\nSome content...',
metadata: {}
})
};
fetch('https://api.orchata.ai/api/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.orchata.ai/api/documents",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'spaceId' => 'space_123',
'filename' => 'my-notes.md',
'content' => '# My Notes
Some content...',
'metadata' => [
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"Oai-Api-Key: <api-key>"
],
]);
$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.orchata.ai/api/documents"
payload := strings.NewReader("{\n \"spaceId\": \"space_123\",\n \"filename\": \"my-notes.md\",\n \"content\": \"# My Notes\\n\\nSome content...\",\n \"metadata\": {}\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Oai-Api-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://api.orchata.ai/api/documents")
.header("Oai-Api-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"spaceId\": \"space_123\",\n \"filename\": \"my-notes.md\",\n \"content\": \"# My Notes\\n\\nSome content...\",\n \"metadata\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.orchata.ai/api/documents")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Oai-Api-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"spaceId\": \"space_123\",\n \"filename\": \"my-notes.md\",\n \"content\": \"# My Notes\\n\\nSome content...\",\n \"metadata\": {}\n}"
response = http.request(request)
puts response.read_body{
"document": {
"id": "<string>",
"orgId": "<string>",
"spaceId": "<string>",
"filename": "<string>",
"mimeType": "<string>",
"fileSize": "<string>",
"storageUrl": "<string>",
"status": "<string>",
"errorMessage": "<string>",
"embeddingModel": "<string>",
"indexingType": "<string>",
"createdAt": "2023-11-07T05:31:56Z",
"updatedAt": "2023-11-07T05:31:56Z",
"metadata": "<unknown>"
},
"created": true
}Documents
Upsert Document
Create or update a document by filename. If a document with the given filename exists in the space, updates it. Otherwise creates a new document. Embeddings are generated synchronously - the document is immediately queryable.
PUT
/
api
/
documents
TypeScript SDK
import { Orchata } from '@orchata-ai/sdk';
const client = new Orchata({ apiKey: 'oai_your_api_key' });
// Create or update - idempotent operation
const { document, created } = await client.documents.upsert({
spaceId: 'space_123',
filename: 'to-do.md',
content: '# To-Do List\n\n- [x] First task\n- [ ] Second task'
});
console.log(created ? 'Created new document' : 'Updated existing document');curl --request PUT \
--url https://api.orchata.ai/api/documents \
--header 'Content-Type: application/json' \
--header 'Oai-Api-Key: <api-key>' \
--data '
{
"spaceId": "space_123",
"filename": "my-notes.md",
"content": "# My Notes\n\nSome content...",
"metadata": {}
}
'import requests
url = "https://api.orchata.ai/api/documents"
payload = {
"spaceId": "space_123",
"filename": "my-notes.md",
"content": "# My Notes
Some content...",
"metadata": {}
}
headers = {
"Oai-Api-Key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {'Oai-Api-Key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
spaceId: 'space_123',
filename: 'my-notes.md',
content: '# My Notes\n\nSome content...',
metadata: {}
})
};
fetch('https://api.orchata.ai/api/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.orchata.ai/api/documents",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'spaceId' => 'space_123',
'filename' => 'my-notes.md',
'content' => '# My Notes
Some content...',
'metadata' => [
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"Oai-Api-Key: <api-key>"
],
]);
$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.orchata.ai/api/documents"
payload := strings.NewReader("{\n \"spaceId\": \"space_123\",\n \"filename\": \"my-notes.md\",\n \"content\": \"# My Notes\\n\\nSome content...\",\n \"metadata\": {}\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Oai-Api-Key", "<api-key>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.put("https://api.orchata.ai/api/documents")
.header("Oai-Api-Key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"spaceId\": \"space_123\",\n \"filename\": \"my-notes.md\",\n \"content\": \"# My Notes\\n\\nSome content...\",\n \"metadata\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.orchata.ai/api/documents")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Oai-Api-Key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"spaceId\": \"space_123\",\n \"filename\": \"my-notes.md\",\n \"content\": \"# My Notes\\n\\nSome content...\",\n \"metadata\": {}\n}"
response = http.request(request)
puts response.read_body{
"document": {
"id": "<string>",
"orgId": "<string>",
"spaceId": "<string>",
"filename": "<string>",
"mimeType": "<string>",
"fileSize": "<string>",
"storageUrl": "<string>",
"status": "<string>",
"errorMessage": "<string>",
"embeddingModel": "<string>",
"indexingType": "<string>",
"createdAt": "2023-11-07T05:31:56Z",
"updatedAt": "2023-11-07T05:31:56Z",
"metadata": "<unknown>"
},
"created": true
}Authorizations
Body
application/json
Upsert document request
The ID of the space
Example:
"space_123"
Filename to create or update
Required string length:
1 - 255Example:
"my-notes.md"
The document content (max 10MB)
Required string length:
1 - 10000000Example:
"# My Notes\n\nSome content..."
Optional metadata to attach to the document
Show child attributes
Show child attributes
Was this page helpful?
⌘I