Skip to main content
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');
{
  "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

Oai-Api-Key
string
header
required

Body

application/json

Upsert document request

spaceId
string
required

The ID of the space

Example:

"space_123"

filename
string
required

Filename to create or update

Required string length: 1 - 255
Example:

"my-notes.md"

content
string
required

The document content (max 10MB)

Required string length: 1 - 10000000
Example:

"# My Notes\n\nSome content..."

metadata
object

Optional metadata to attach to the document

Response

Document created or updated successfully

document
object
required
created
boolean
required

Whether a new document was created (true) or existing updated (false)