Dashboard|

Quickstart

Send your app's traces to Cencori with one import and your project's API key.

This takes a few minutes. By the end, every model call your app makes shows up in Observability → Traces.

1. Get a key

In your project, open API Keys and create a secret key (it starts with csk_). Publishable keys can't send traces: anyone can read them out of a browser or app.

Add it to your server's environment:

CENCORI_API_KEY=csk_...

If your app already calls models through Cencori, it already has this key. Use the same one.

2. Install

npm install cencori

You need version 1.18 or later. Node.js 18 or later; for now there's no Python package (see Python).

3. Add one line

Import cencori/observe before anything else in your server, so it's in place before your AI libraries load:

// server.ts: the first line
import 'cencori/observe';
 
import OpenAI from 'openai';
// ...the rest of your app, unchanged

That's all for a Node.js server built as CommonJS: an Express, Fastify or NestJS app compiled by TypeScript to CommonJS, or plain require. Every OpenAI and Anthropic call is now traced.

Next.js, Vite, other bundlers, and ESM apps load your modules in a way the line above can't see into. Pass it the client you use, where you create it:

// lib/ai.ts
import OpenAI from 'openai';
import { observe } from 'cencori/observe';
 
observe({ openai: OpenAI });
 
export const openai = new OpenAI();

observe({ anthropic: Anthropic }) does the same for Anthropic. It's safe to call more than once, and harmless in apps that didn't need it. Not sure which kind of app you have? Do this; it works in both.

For the Vercel AI SDK and LangChain, see Frameworks.

4. Make a call and look

Run your app and make a request that calls a model. Within a few seconds the run appears in Observability → Traces.

Nothing there? Run with CENCORI_OBSERVE_DEBUG=1 and Cencori logs each batch it sends, or why it couldn't:

CENCORI_OBSERVE_DEBUG=1 node server.js
# [cencori] observe: sent 3 span(s)
You seeIt means
Nothing at allNo traced calls happened. In a bundled or ESM app, pass your client to observe() (step 3).
CENCORI_API_KEY is not setThe key isn't in the environment of the process making the calls.
Cencori refused ... (401)The key is wrong or revoked.
Cencori refused ... (403)It's a publishable key. Use a secret one.
... spans this month are used upYour plan's monthly allowance is spent. See Plans and limits.

Serverless functions

Traces are sent in batches every few seconds, so a function that returns and freezes can take its last batch with it. Send them before it ends:

import { flush } from 'cencori/observe';
 
// Next.js route handler: after the response is sent
import { after } from 'next/server';
after(() => flush());
 
// Elsewhere: before you return
await flush();

On long-running servers there's nothing to do: batches go out on their own, and what's left is sent when the process exits normally.

Turning it off

Set CENCORI_OBSERVE=false and cencori/observe does nothing, without any change to your code. Useful in tests and local development.

Next