Node.js SDK Overview

View as Markdown

Node.js SDK

TypeScript SDK for the MeshAPI AI model gateway — an OpenAI-compatible API that proxies to OpenRouter with multi-tenant key management, rate limiting, and prompt templates.

Supports Node.js 18+ with full TypeScript strict-mode types, native fetch, and streaming via AsyncIterable.

Installation

$npm install meshapi-node-sdk
$# or
$pnpm add meshapi-node-sdk
$# or
$yarn add meshapi-node-sdk

Quick Start

1import { MeshAPI } from "meshapi-node-sdk";
2
3const client = new MeshAPI({
4 baseUrl: "https://api.yourdomain.com",
5 token: "rsk_01JXXXXXXXXXXXXXXXXXXXXXXXXX", // data-plane API key
6});

Authentication

All requests require a Mesh API key (prefixed with rsk_).

1const client = new MeshAPI({
2 baseUrl: "https://api.yourdomain.com",
3 token: "rsk_01JXXXXXXXXXXXXXXXXXXXXXXXXX",
4});

This key provides access to all endpoints, including completions, models, templates, images, and batch jobs.

Configuration Options

1const client = new MeshAPI({
2 baseUrl: "https://api.yourdomain.com", // required
3 token: "rsk_...", // required
4 timeoutMs: 30_000, // default: 60_000 (60s)
5 signal: myAbortController.signal, // optional global AbortSignal
6 fetch: customFetch, // optional fetch override (for mocking/polyfills)
7});

TypeScript

The SDK ships full .d.ts declarations. Key types:

1import type {
2 ChatCompletionParams,
3 ChatCompletionResponse,
4 ChatCompletionChunk,
5 ChatMessage,
6 ModelInfo,
7 TemplateSummary,
8 CreateTemplateParams,
9 MeshAPIConfig,
10} from "meshapi-node-sdk";