@avanor/sdk-openai
v0.1.2
Published
Avanor SDK — OpenAI + Anthropic auto-instrumentation
Maintainers
Readme
@avanor/sdk-openai
Avanor SDK — OpenAI + Anthropic auto-instrumentation.
Monkey-patches your OpenAI or Anthropic client in place so every LLM call
emits an llm.call span with OTel GenAI semconv attributes (gen_ai.*).
Install
npm install @avanor/sdk @avanor/sdk-openaiAdd openai or @anthropic-ai/sdk to your dependencies if they aren't already.
OpenAI quickstart
import OpenAI from 'openai';
import { Avanor } from '@avanor/sdk';
import { instrumentOpenAI } from '@avanor/sdk-openai';
Avanor.init({
apiKey: process.env.AVANOR_API_KEY!,
environment: process.env.NODE_ENV ?? 'dev',
service: 'broker-portal',
});
const openai = instrumentOpenAI(new OpenAI());
// use as normal — every chat.completions.create call is instrumented
const result = await openai.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: 'Hi' }],
});Anthropic quickstart
import Anthropic from '@anthropic-ai/sdk';
import { Avanor } from '@avanor/sdk';
import { instrumentAnthropic } from '@avanor/sdk-openai';
Avanor.init({ /* ... */ });
const anthropic = instrumentAnthropic(new Anthropic());
const result = await anthropic.messages.create({
model: 'claude-opus-4-7',
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hi' }],
});Attributes captured per call
| Attribute | Value |
|---|---|
| gen_ai.provider.name | 'openai' or 'anthropic' |
| gen_ai.operation.name | 'chat.completions.create', 'messages.create', etc. |
| gen_ai.request.model | The model arg (e.g., 'gpt-4o') |
| gen_ai.usage.input_tokens | From the response usage field |
| gen_ai.usage.output_tokens | From the response usage field |
| gen_ai.response.id | The provider's response id |
Zero false-positive guarantee
The monkey-patch is OBSERVATION ONLY. The wrapped method returns the exact same value as the original — no wrapping, no transformation, no extra fields. Your downstream code does not care that the SDK is in the loop.
Docs
https://docs.avanor.ai/sdk/recipes/express-openai
License
Avanor Source License v1 (BSL-modeled, 4-year Apache 2.0 sunset) — see LICENSE.
