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/sdkConfigure 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_workspaces → listWorkspaces). 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
| Method | HTTP | Purpose |
|---|---|---|
ask | POST /api/v1/ask | Grounded Q&A over your corpus |
search | POST /api/v1/search | Hybrid / vision search |
filesCreate / filesList / filesRetrieve | Files API | Upload and inspect documents |
parse / parseRetrieve | POST / GET /api/v1/parse | Document parse jobs |
extract / extractRetrieve | POST / GET /api/v1/extract | Structured extraction jobs |
listWorkspaces / createWorkspace / getWorkspace | Workspaces | Scope and manage workspaces |
tagsList / addTags / deleteTags | Tags | Organize content with tags |
ontologyTemplatesList / ontologyConceptsCreate / ontologyRelationsCreate | Ontology | Concepts, relations, and graph filters |
For every parameter and response field, see the API reference or the Reference page.