Upload a Document

Documents are uploaded to a specific schema within a workspace. Each document is scoped to an environment (defaults to production).

Upload a file

Pass a Blob or File object to the SDK:

import { readFileSync } from "node:fs";

const file = new Blob([readFileSync("./invoice.pdf")], {
  type: "application/pdf",
});

const document = await client.documents.create("my-workspace", "invoice", {
  file,
  fileName: "invoice.pdf",
});

console.log(document.id); // "doc_abc123"
console.log(document.pageCount); // 3

Upload text content

For plain text or pre-processed content, you can upload a string directly:

const document = await client.documents.create("my-workspace", "invoice", {
  content: "Invoice #1234\nDate: 2024-03-15\nTotal: $1,250.00",
  fileName: "invoice.txt",
});

Upload with curl

curl -X POST https://api.tracore.io/workspaces/my-workspace/schemas/invoice/documents \
  -H "x-api-key: dsk_your_api_key_here" \
  -F "file=@invoice.pdf"

Environment scoping

Documents are scoped to an environment. Pass the env parameter to target a specific one:

// Upload to the development environment
const document = await client.documents.create("my-workspace", "invoice", {
  file,
  fileName: "invoice.pdf",
  env: "development",
});
# Upload to staging via curl
curl -X POST "https://api.tracore.io/workspaces/my-workspace/schemas/invoice/documents?env=staging" \
  -H "x-api-key: dsk_your_api_key_here" \
  -F "file=@invoice.pdf"

If omitted, the environment defaults to production.

Inline upload and extract

You can upload a document and start extraction in a single request using the extract endpoint. See Extract & Poll for details.