Frameworks
Tracing OpenAI, Anthropic, LangChain, the Vercel AI SDK and Next.js apps, and Python.
cencori/observe traces the libraries below. Each section shows only what differs from the Quickstart.
Each model call records the model and provider, the messages and reply, token counts, latency, errors and an estimated cost.
OpenAI and Anthropic
Nothing to add in a Node.js server. In Next.js, other bundled apps and ESM apps, pass the client classes you use:
import OpenAI from 'openai';
import Anthropic from '@anthropic-ai/sdk';
import { observe } from 'cencori/observe';
observe({ openai: OpenAI, anthropic: Anthropic });This also covers providers you reach with the OpenAI SDK pointed at another baseURL: Groq, Together, OpenRouter, Ollama, the Cencori gateway.
Vercel AI SDK
The AI SDK writes its own traces when you turn them on for a call. With cencori/observe loaded, they go to Cencori:
import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
const { text } = await generateText({
model: openai('gpt-4o-mini'),
prompt: 'Summarize this ticket',
experimental_telemetry: { isEnabled: true },
});Add experimental_telemetry: { isEnabled: true } to each generateText, streamText, generateObject or streamObject call you want traced. Give a call a name with functionId, and attach a user or anything else with metadata:
experimental_telemetry: {
isEnabled: true,
functionId: 'summarize-ticket',
metadata: { userId: user.id, sessionId: chat.id },
},Cencori reads userId and sessionId from there as the trace's user and session.
Next.js
Load cencori/observe when the server starts, from instrumentation.ts at the root of your project (or in src/):
// instrumentation.ts
export async function register() {
if (process.env.NEXT_RUNTIME === 'nodejs') {
await import('cencori/observe');
}
}That's enough for the Vercel AI SDK. For the OpenAI and Anthropic SDKs, also pass the client class where you create your client, because Next.js bundles them:
// lib/ai.ts
import OpenAI from 'openai';
import { observe } from 'cencori/observe';
observe({ openai: OpenAI });
export const openai = new OpenAI();Route handlers on Vercel and other serverless hosts should send their traces before the function ends:
import { after } from 'next/server';
import { flush } from 'cencori/observe';
export async function POST(req: Request) {
const answer = await openai.chat.completions.create({ /* ... */ });
after(() => flush());
return Response.json(answer);
}Tracing runs in the Node.js runtime. Routes on the Edge runtime aren't traced.
LangChain
LangChain's OpenAI and Anthropic chat models call those SDKs underneath, so their model calls are traced with no extra setup. To see the chains, agents, tools and retrievers around them, add LangChain's instrumentation:
npm install @arizeai/openinference-instrumentation-langchaincencori/observe picks it up on its own in a Node.js server. In bundled and ESM apps, pass LangChain's callback manager too:
import * as CallbackManagerModule from '@langchain/core/callbacks/manager';
import { observe } from 'cencori/observe';
observe({ langchain: CallbackManagerModule });It isn't installed with cencori because it brings LangChain's core with it, which apps that don't use LangChain shouldn't have to download.
Python
There's no cencori Python observe yet. Until there is, send traces with OpenTelemetry and the OpenInference instrumentations, using your Cencori key:
pip install opentelemetry-sdk opentelemetry-exporter-otlp-proto-http openinference-instrumentation-openaiimport os
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchSpanProcessor
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from openinference.instrumentation.openai import OpenAIInstrumentor
provider = TracerProvider()
provider.add_span_processor(BatchSpanProcessor(OTLPSpanExporter(
endpoint="https://api.cencori.com/v1/traces",
headers={"Authorization": f"Bearer {os.environ['CENCORI_API_KEY']}"},
)))
trace.set_tracer_provider(provider)
OpenAIInstrumentor().instrument(tracer_provider=provider)OpenInference has instrumentations for Anthropic, LangChain, LlamaIndex, CrewAI, DSPy, Bedrock, Mistral and more: install the one you need and call its instrument() the same way. See OpenTelemetry for what else Cencori accepts.

