canopy-sdk
v0.1.1
Published
Drop-in SDK for the Canopy proxy. Routes OpenAI and Anthropic calls through Canopy for cost observability.
Maintainers
Readme
promptlens
Plug-in LLM cost tracking for production apps. One env var, two lines of code.
Install
npm install canopy-sdk openaiUsage
import OpenAI from "openai";
import { promptlensOpenAI } from "canopy-sdk";
const openai = new OpenAI(
promptlensOpenAI({
apiKey: process.env.OPENAI_API_KEY!,
feature: "my-feature", // optional — appears in dashboard
})
);
// All completions are logged automatically
await openai.chat.completions.create({
model: "gpt-4o-mini",
messages: [{ role: "user", content: "Hello" }],
});# Only new secret — from Canopy dashboard → API Keys
export PROMPTLENS_KEY=pl_live_...Anthropic
import Anthropic from "@anthropic-ai/sdk";
import { promptlensAnthropic } from "canopy-sdk";
const anthropic = new Anthropic(
promptlensAnthropic({ apiKey: process.env.ANTHROPIC_API_KEY! })
);Self-hosted proxy
promptlensOpenAI({
apiKey: process.env.OPENAI_API_KEY!,
baseUrl: "https://promptlens.mycompany.com",
});Or set PROMPTLENS_BASE_URL in the environment.
Lower-level API
If you prefer spreading config yourself:
import { createOpenAIConfig, resolvePromptLensConfig } from "canopy-sdk";
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY!,
...createOpenAIConfig(resolvePromptLensConfig()),
});vs TokenGuard
TokenGuard is a browser extension that optimizes chat usage. Canopy is for teams that call OpenAI/Anthropic from code and need spend broken down by feature and prompt template.
