TypeScript

Get Started

Use the official @context212/sdk client in Node.js and TypeScript apps.

@context212/sdk is the official TypeScript client for Context212. It ships typed SDK functions plus request and response models.

Install

npm install @context212/sdk

Configure the client

Set the base URL and bearer token once on the shared client:

import { client } from "@context212/sdk";

client.setConfig({
  baseUrl: "https://api.context212.com",
  headers: {
    Authorization: `Bearer ${process.env.C212_API_KEY}`,
  },
});

The default base URL is https://api.context212.com.

See Authentication for how API keys work.

Call an endpoint

SDK method names are camelCase versions of the API operation IDs (for example list_workspaceslistWorkspaces). Core endpoints such as Ask and Search use short names (ask, search).

import { ask, search } from "@context212/sdk";

const { data, error } = await ask({
  body: {
    query: "What is the vacation policy?",
    workspace_id: [42],
    max_results: 5,
  },
});

if (error) throw error;
console.log(data.answer);

const searchResult = await search({
  body: {
    query: "vacation policy",
    workspace_id: [42],
    max_results: 3,
  },
});

for (const result of searchResult.data?.results ?? []) {
  console.log(result.content?.slice(0, 120));
}

Each call returns { data, error, ... } unless you opt into throw-on-error via the generic ThrowOnError flag on the options type.

Common methods

MethodHTTPPurpose
askPOST /api/v1/askGrounded Q&A over your corpus
searchPOST /api/v1/searchHybrid / vision search
filesCreate / filesList / filesRetrieveFiles APIUpload and inspect documents
parse / parseRetrievePOST / GET /api/v1/parseDocument parse jobs
extract / extractRetrievePOST / GET /api/v1/extractStructured extraction jobs
listWorkspaces / createWorkspace / getWorkspaceWorkspacesScope and manage workspaces
tagsList / addTags / deleteTagsTagsOrganize content with tags
ontologyTemplatesList / ontologyConceptsCreate / ontologyRelationsCreateOntologyConcepts, relations, and graph filters

For every parameter and response field, see the API reference or the Reference page.

On this page