Membit’s JavaScript/TypeScript SDK provides a simple, strongly-typed interface to the Membit API. Add intelligent search and content discovery directly to your apps with first-class TypeScript support and automatic type inference.

Installing

npm i @bandprotocol/membit
Discover trending topics and clusters of related content. Ideal for understanding what’s trending and grouping related discussions.

Usage

const { membit } = require("@bandprotocol/membit");

// Step 1. Instantiate the Membit client
const client = membit({ apiKey: "<your-api-key>" });

// Step 2. Execute a cluster search query
const clusters = await client.cluster_search("artificial intelligence", {
  limit: 3,
});

// Step 3. Done! You've performed a Membit Cluster Search
console.log(clusters);

Membit Cluster Info

Fetch detailed information about a specific cluster. Use this to dive deeper into topics discovered via cluster search.

Usage

const { membit } = require("@bandprotocol/membit");

// Step 1. Instantiate the Membit client
const client = membit({ apiKey: "<your-api-key>" });

// Step 2. Get detailed cluster information
const clusterInfo = await client.cluster_info("AI Learning Resources", {
  limit: 5,
  format: "json",
});

// Step 3. Print cluster details
console.log("Cluster Info:", clusterInfo);

Membit Post Search

Search for individual posts across the Membit corpus. Perfect for finding specific content and examples.

Usage

const { membit } = require("@bandprotocol/membit");

// Step 1. Instantiate the Membit client
const client = membit({ apiKey: "<your-api-key>" });

// Step 2. Search for posts
const posts = await client.post_search("machine learning", {
  limit: 10,
  format: "json",
});

// Step 3. Process the results
console.log("Found posts:", posts);

TypeScript Benefits

Method Overloads

// TypeScript automatically infers return types
const jsonData = await client.cluster_search("query"); // Record<string, any>
const textData = await client.cluster_search("query", { format: "llm" }); // string

Format Options

FormatReturn TypeUse CaseTypeScript Type
”json”Record<string, any>Structured data for further processingObject
”llm”stringHuman-readable text for direct displayString

Configuration Options

import { membit, MembitClientOptions } from "@bandprotocol/membit";

const client = membit({
  apiKey: "<your-api-key>", // Required (or set MEMBIT_API_KEY env var)
  apiBaseURL: "https://custom.api", // Optional (defaults to Membit API)
});

// All methods support these options (showing defaults)
const result = await client.cluster_search("query", {
  limit: 10, // number (default: 10)
  format: "json", // "json" | "llm" (default: "json")
  timeout: 60, // seconds (default: 60)
});

Default Parameters

All search methods use these defaults when options are not specified:
  • limit: 10 — Maximum number of results to return
  • format: “json” — Return structured data as objects
  • timeout: 60 — Request timeout in seconds

Environment Variables

You can set your API key via environment variable:
export MEMBIT_API_KEY="<your-api-key>"
If apiKey is not provided in the client options, the SDK will automatically use MEMBIT_API_KEY.

Examples

See the examples/ directory for more comprehensive usage:
  • examples/basic-usage.ts — Complete workflow with realistic API usage