@aui-x/prism

中文文档
0.0.5发布于 2026/03/10SEE LICENSE IN LICENSETypeScriptESM + CJS零依赖近 30 天下载 1.6万

LLM tracing SDK for auix — AI SDK middleware + manual tracing

原始使用文档
文档目录15 节
  1. Install
  2. Quick Start
  3. AI SDK (recommended)
  4. OpenAI
  5. Anthropic
  6. Manual Tracing
  7. API
  8. new AuixPrism(config)
  9. prismAISDK(tracer, model, options?)
  10. prismOpenAI(tracer, client, options?)
  11. prismAnthropic(tracer, client, options?)
  12. tracer.startTrace(options)
  13. trace.startSpan(options)
  14. tracer.destroy()
  15. License

@auix/prism

LLM tracing SDK for auix — collect LLM traces with zero friction.

Supports Vercel AI SDK, OpenAI, Anthropic, and manual tracing.

Install

npm install @auix/prism

Peer dependencies (install only what you use):

  • ai (>=6.0.0) + @ai-sdk/provider (>=2.0.0) — for AI SDK integration
  • openai (>=4.0.0) — for OpenAI integration
  • @anthropic-ai/sdk (>=0.30.0) — for Anthropic integration

Quick Start

prismAISDK wraps any AI SDK model and automatically captures traces, token usage, latency, and tool calls. It creates a root trace internally and returns { model, end }:

import { AuixPrism, prismAISDK } from "@auix/prism";
import { openai } from "@ai-sdk/openai";
import { generateText } from "ai";

const tracer = new AuixPrism({ apiKey: "your-api-key" });

const traced = prismAISDK(tracer, openai("gpt-4o"), {
  name: "my-chat",
  tags: ["production"],
  endUserId: "[email protected]",
  metadata: { threadId: "t_123" },
});

const { text, usage } = await generateText({
  model: traced.model,
  prompt: "Hello!",
});

// Token usage is captured automatically from spans — just call end():
await traced.end();

// Or pass explicit values to override:
await traced.end({
  output: text,
  totalTokens: usage.totalTokens,
  inputTokens: usage.inputTokens,
  outputTokens: usage.outputTokens,
});

Multi-step tool use is handled correctly — each LLM call becomes a child span under the root trace, and token usage is automatically aggregated:

import { streamText, stepCountIs } from "ai";

const traced = prismAISDK(tracer, openai("gpt-4o"), {
  name: "agent",
  tags: ["chat"],
});

const result = streamText({
  model: traced.model,
  prompt: "What's the weather?",
  tools: { /* ... */ },
  stopWhen: stepCountIs(6),
});

for await (const chunk of result.textStream) {
  process.stdout.write(chunk);
}

await traced.end();

OpenAI

prismOpenAI returns a proxied client that traces chat.completions.create calls:

import { AuixPrism, prismOpenAI } from "@auix/prism";
import OpenAI from "openai";

const tracer = new AuixPrism({ apiKey: "your-api-key" });
const client = prismOpenAI(tracer, new OpenAI(), {
  name: "my-chat",
  tags: ["production"],
});

const response = await client.chat.completions.create({
  model: "gpt-4o",
  messages: [{ role: "user", content: "Hello!" }],
});

Anthropic

prismAnthropic returns a proxied client that traces messages.create calls:

import { AuixPrism, prismAnthropic } from "@auix/prism";
import Anthropic from "@anthropic-ai/sdk";

const tracer = new AuixPrism({ apiKey: "your-api-key" });
const client = prismAnthropic(tracer, new Anthropic(), {
  name: "my-chat",
  tags: ["production"],
});

const response = await client.messages.create({
  model: "claude-sonnet-4-20250514",
  max_tokens: 1024,
  messages: [{ role: "user", content: "Hello!" }],
});

Manual Tracing

For full control over trace structure:

import { AuixPrism } from "@auix/prism";

const tracer = new AuixPrism({ apiKey: "your-api-key" });

const trace = tracer.startTrace({
  name: "rag-pipeline",
  metadata: { userId: "u_123" },
});

const span = trace.startSpan({
  name: "vector-search",
  type: "retrieval",
  input: { query: "How do I reset my password?" },
});

span.end({ output: { results: 5 }, status: "completed" });

trace.end({ output: "Here's how to reset...", status: "completed" });

await tracer.destroy();

API

new AuixPrism(config)

OptionTypeDefaultDescription
apiKeystringrequiredYour auix API key
baseUrlstring"https://api.auix.dev"API endpoint
sessionIdstring—Group traces under a session
transport(events) => Promise<void>—Custom transport (bypasses HTTP)
onFlushError(error) => void—Called when flush fails after retry

prismAISDK(tracer, model, options?)

Returns { model, end }. The model is a wrapped AI SDK model. Call end(opts?) after the generation completes to finalize the root trace.

OptionTypeDescription
namestringTrace name (defaults to model ID)
tagsstring[]Tags for filtering
metadataRecord<string, unknown>Arbitrary metadata
endUserIdstringEnd user identifier

prismOpenAI(tracer, client, options?)

Returns a proxied OpenAI client. Same options as prismAISDK plus parentTraceId for nesting under an existing trace.

prismAnthropic(tracer, client, options?)

Returns a proxied Anthropic client. Same options as prismOpenAI.

tracer.startTrace(options)

Returns a TraceHandle for manual tracing.

trace.startSpan(options)

Creates a child span. type can be "llm", "tool", "retrieval", or "custom".

tracer.destroy()

Flushes pending events and stops the background timer. Call this when done tracing.

License

Proprietary — see LICENSE.

版本与发布记录

@aui-x/prism 共发布 5 个版本,首次发布于 2026/02/20;过去 12 个月发布了 5 个版本。

版本发布日期距今
0.0.5latest2026/03/107 个月前
0.0.42026/02/208 个月前
0.0.32026/02/208 个月前
0.0.22026/02/208 个月前
0.0.12026/02/208 个月前

关于 @aui-x/prism 的常见问题

@aui-x/prism 是什么?

LLM tracing SDK for auix — AI SDK middleware + manual tracing

如何安装 @aui-x/prism?

在项目目录运行 npm install @aui-x/prism,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:ai(>=6.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@aui-x/prism 支持 TypeScript 吗?

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

@aui-x/prism 支持 ESM 还是 CommonJS?

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

@aui-x/prism 可以商用吗?

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

@aui-x/prism 的下载量有多少?

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

@aui-x/prism 还在维护吗?

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