Quickstart

Get a search result in under 5 minutes.

Get your API key

Create one from the API Keys section of the console and copy it. You will not see it again. Then set it as an environment variable:

export C212_API_KEY=your_api_key_here

See Authentication for more on key management.

Upload a document

import { readFileSync } from "node:fs";

const headers = {
  Authorization: `Bearer ${process.env.C212_API_KEY}`,
};

const form = new FormData();
form.append("workspace_id", "42");
form.append("file", new Blob([readFileSync("handbook.pdf")]), "handbook.pdf");

const response = await fetch("https://api.context212.com/api/v1/files", {
  method: "POST",
  headers,
  body: form,
});
const file = await response.json();
console.log(`Uploaded: ${file.id}, status: ${file.status}`);
// → Uploaded: 12345, status: pending

Indexing takes a few seconds. Check the file until status is embedded:

const fileId = file.id;
const r = await fetch(`https://api.context212.com/api/v1/files/${fileId}`, {
  headers,
});
const data = await r.json();
console.log(data.status); // → embedded

Search it

const response = await fetch("https://api.context212.com/api/v1/search", {
  method: "POST",
  headers: { ...headers, "Content-Type": "application/json" },
  body: JSON.stringify({
    query: "What is the vacation policy at Context212?",
    workspace_id: [42],
    max_results: 3,
  }),
});
const data = await response.json();
for (const result of data.results) {
  console.log(`[p.${result.source.page_start}${result.source.page_end}, score=${result.score.toFixed(2)}]`);
  console.log(result.content.slice(0, 120));
  console.log();
}
[p.4–4, score=0.94]
Employees are entitled to 25 days of paid leave per year...

[p.4–4, score=0.87]
Unused vacation days carry over up to a maximum of 10 days...

[p.7–7, score=0.71]
Public holidays are in addition to the annual leave entitlement...

Three API calls: upload, wait, search. That's the full pipeline.

On this page