@browserstack/ai-sdk

中文文档
1.0.0-beta.22发布于 2026/10/06SEE LICENSE IN LICENSE.mdTypeScriptESM + CJS近 30 天下载 1.3万

BrowserStack AI SDK for Node.js — LLM observability, evaluation, and tracing

原始使用文档
文档目录9 节
  1. Installation
  2. Quick Start
  3. Auto-Instrumentation
  4. Configuration
  5. Environment Variables
  6. Memory and backpressure
  7. Span attribute limits
  8. Reading the logs
  9. Constructor Options

@browserstack/ai-sdk

A TypeScript/NodeJS SDK for AI application observability, testing, and evaluation.

Requires Node.js >= 18.

Installation

npm install @browserstack/ai-sdk@beta

Quick Start

import { AISDK } from '@browserstack/ai-sdk';

// Initialize the client
const client = new AISDK({
  publicKey: 'your-public-key',
  secretKey: 'your-secret-key',
});

// Create a trace
const trace = client.trace({
  name: 'user_login_flow',
  metadata: {
    testSuite: 'authentication_tests',
    testFile: 'auth.test.js',
  },
  tags: ['auth', 'critical'],
});

// Create spans
const loginSpan = trace.span({
  name: 'navigate_to_login',
  input: { url: '/login' }
});

loginSpan.end({
  output: { pageLoaded: true, loadTime: 250 }
});

// Create events
trace.event({
  name: 'assertion_check',
  metadata: {
    assertion: 'Login button should be visible',
    passed: true,
    expected: 'button visible',
    actual: 'button visible'
  }
});

// Cleanup
await client.flushAsync();
await client.shutdownAsync();

Auto-Instrumentation

Automatically trace LLM calls without code changes:

node --require @browserstack/ai-sdk/instrument app.js

Configuration

The client can be configured using environment variables or constructor options:

Environment Variables

AISDK_PUBLIC_KEY=your_public_key
AISDK_SECRET_KEY=your_secret_key

Memory and backpressure

The SDK holds trace data in memory between your call and a successful delivery. When ingestion is slow or failing, that held data is bounded by a byte budget — once the budget is reached the SDK sheds the oldest traces rather than growing until the process is killed.

VariableDefaultWhat it controls
AISDK_MAX_HELD_BYTES104857600 (100 MB)Total estimated bytes held across the queue and in-flight requests. The one knob to change if you need a different memory ceiling.
AISDK_MAX_QUEUE_SIZE1000Items held before delivery. An independent cap — whichever binds first wins.
AISDK_MAX_SOCKETS30Connection pool size.
AISDK_BATCH_SIZE15Items per request.
AISDK_BATCH_TIMEOUT_MS5000Longest a partial batch waits before being sent.
AISDK_MAX_RETRIES3Retries after a failed attempt, so 4 total attempts.
AISDK_REQUEST_TIMEOUT_MS30000Per-attempt request timeout. 0 disables it entirely.

Sizing your container. AISDK_MAX_HELD_BYTES bounds the SDK's tracked payload bytes, not the process. Expect real RSS of roughly 1.8x the budget — a sustained-failure load test against the 100 MB default settles flat at ~180 MB. Budget for at least 2x on top of your application's own footprint.

Half the budget is reserved for in-flight requests and half for the queue, so a brief slowdown is absorbed rather than shed: queued items can still be delivered when the endpoint recovers, while in-flight ones are pinned until their retries finish.

Set plain byte counts. Suffixes are not parsed — AISDK_MAX_HELD_BYTES=100MB reads as 100 bytes, not 100 megabytes, and 1e6 reads as 1. Values below 64 KB are refused with a [CONFIG_REJECTED] line and the default is used instead.

Span attribute limits

OpenTelemetry defaults to 128 attributes per span, which a request advertising many tools (or a long agentic loop) can approach. The SDK raises this ceiling to 10000 by default — a backstop against an unbounded producer, not a payload guard.

VariableWhat it controls
OTEL_SPAN_ATTRIBUTE_COUNT_LIMITSet to a number to use your own span attribute count limit instead of the SDK's default.
OTEL_ATTRIBUTE_COUNT_LIMITSame override; OpenTelemetry's general (non-span-specific) variable, read when the one above is unset.

Reading the logs

Four lines are printed by default, without AISDK_DEBUG, because they mean trace data is being discarded. Each is rate-limited to one line per minute and carries suppressed=N for the occurrences it stands for.

LineMeaningWhat to do
[BUDGET_SHED]The byte budget was reached; oldest traces dropped.Ingestion is not keeping up. Check endpoint health first — raising the budget only delays this.
[QUEUE_OVERFLOW]The item cap was reached.Raise AISDK_MAX_QUEUE_SIZE, or check endpoint health.
[INFLIGHT_CAP]Dispatch paused because in-flight bytes are at their ceiling.Normal backpressure. Sustained appearances mean ingestion is degraded.
[DROP]A batch was discarded after exhausting its retries.Delivery was never confirmed. The data may still have reached the server — X-Batch-Id lets ingestion dedupe a retried batch — so treat this as unconfirmed, not as certain loss.

Everything else, including per-request diagnostics, requires AISDK_DEBUG=true.

Constructor Options

const client = new AISDK({
  publicKey: 'your_public_key',
  secretKey: 'your_secret_key',
  environment: 'production',
  flushAt: 20,
  flushInterval: 10000,
});

版本与发布记录

@browserstack/ai-sdk 共发布 22 个版本,首次发布于 2026/04/22;过去 12 个月发布了 22 个版本。

版本发布日期距今
1.0.0-beta.22latest2026/10/061 个月前
1.0.0-beta.212026/08/252 个月前
1.0.0-beta.202026/08/112 个月前
1.0.0-beta.192026/08/043 个月前
1.0.0-beta.182026/07/223 个月前
1.0.0-beta.172026/07/213 个月前

关于 @browserstack/ai-sdk 的常见问题

@browserstack/ai-sdk 是什么?

BrowserStack AI SDK for Node.js — LLM observability, evaluation, and tracing

如何安装 @browserstack/ai-sdk?

在项目目录运行 npm install @browserstack/ai-sdk,或使用 pnpm add / yarn add / bun add。

@browserstack/ai-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@browserstack/ai-sdk 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@browserstack/ai-sdk 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@browserstack/ai-sdk 可以商用吗?

@browserstack/ai-sdk 使用 SEE LICENSE IN LICENSE.md 许可。许可条款写在包内的独立文件中,请阅读该文件确认可否商用。以上为概括,不构成法律意见,请以许可原文为准。

@browserstack/ai-sdk 的下载量有多少?

根据 npm 官方下载统计,@browserstack/ai-sdk 在 2026/10/09 – 2026/11/07 这 30 天内被下载 12,834 次,日均约 428 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@browserstack/ai-sdk 还在维护吗?

最新版本 1.0.0-beta.22 发布于 2026/10/06(1 个月前);至今共发布 22 个版本,其中过去 12 个月发布了 22 个;首次发布于 2026/04/22。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。