Context.ai
  • What is Context.ai?
  • List of Trackable Metrics
  • Product Analytics
    • Overview
    • Topic Categorisation
      • LLM Topics
    • User Engagement Tracking
    • Foreign Language Support
    • PII Filtering
    • Custom Metadata Filtering
    • Backfill Analytics Data
    • Custom Events
    • API Ingestion Methods
      • Log Conversation
      • [deprecated] Upsert Conversation
      • Thread Conversation
      • Patch Thread Message
      • API Resources
        • Chat Message
        • [deprecated] Tool Message
        • Custom Event
        • Metadata
        • Conversation
        • Thread
    • Embedded API
      • Multi-Tenancy
      • Conversations
        • Series Data
  • Integrations
    • Getting Started
    • Python SDK
    • Javascript SDK
    • LangChain Plugin
    • Haystack Plugin
    • Authorization
Powered by GitBook
On this page
  • Installation
  • Usage
  • Typescript Example
  • Javascript Example

Was this helpful?

  1. Integrations

Javascript SDK

PreviousPython SDKNextLangChain Plugin

Last updated 9 months ago

Was this helpful?

Our Javascript SDK makes it straightforward to integrate with Context.ai.

Installation

Install the Context Javascript SDK with NPM:

npm install @contextco/context-node

Usage

The Javascript SDK needs to be authenticated with your Context.ai API Key. You can generate this key from the (if you have not yet sent any transcripts to Context.ai), or from the 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";

const options: ContextAPIOptionalParams = {
  credential: new Credential(process.env.CONTEXT_TOKEN),
};
const c = new ContextAPI(options);

await c.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 }
      ],
    }
  }
})

await c.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";

const options = {
  credential: new Credential(process.env.CONTEXT_TOKEN),
};
const c = new ContextAPI(options);

await c.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 }
      ],
    }
  }
})

Github:

onboarding page
settings page
https://github.com/contextco/context-node/tree/main