Our Javascript SDK makes it straightforward to integrate with Context.ai.
Installation
Install the Context Javascript SDK with NPM:
npminstall@contextco/context-node
Usage
The Javascript SDK needs to be authenticated with your Context.ai API Key. You can generate this key from the onboarding page (if you have not yet sent any transcripts to Context.ai), or from the settings page if you are already integrated.
Once you have your API key, you can start sending requests immediately using one of the example code snippets below. The SDK is usable in Javascript and Typescript applications.
Typescript Example
import { ContextAPI, ContextAPIOptionalParams, KnownMessageRole, Credential } from"@contextco/context-node";constoptions:ContextAPIOptionalParams= { credential:newCredential(process.env.CONTEXT_TOKEN),};constc=newContextAPI(options);awaitc.log.conversation({ body: { conversation: { messages: [ { message:"You are a helpful assistant.", role:KnownMessageRole.System, rating:0 }, { message:"Hi, how are you doing?", role:KnownMessageRole.User, rating:0 }, { message:"I'm doing super well, how are you?", role:KnownMessageRole.Assistant, rating:1 } ], } }})awaitc.log.conversationThread({ body: { conversation: { id:"c_vay3wb34br39gkoq", messages: [ { message:"You are a very helpful assistant.", role:KnownMessageRole.System, rating:0 }, { message:"Hi there, how are you doing?", role:KnownMessageRole.User, rating:0 }, { message:"I'm doing super well, how are you?", role:KnownMessageRole.Assistant, rating:1 } ], } }});
Javascript Example
import { ContextAPI, KnownMessageRole, Credential } from"@contextco/context-node";constoptions= { credential:newCredential(process.env.CONTEXT_TOKEN),};constc=newContextAPI(options);awaitc.log.conversation({ body: { conversation: { messages: [ { message:"You are a helpful assistant.", role:KnownMessageRole.System, rating:0 }, { message:"Hi, how are you doing?", role:KnownMessageRole.User, rating:0 }, { message:"I'm doing super well, how are you?", role:KnownMessageRole.Assistant, rating:1 } ], } }})