Quickstart
Send your first workload from Python or Node.js.
Choose your runtime below. Both SDKs send the same workload, model, token, latency, cache, and privacy-safe prompt-template metadata to SpendLens.
1. Create a SpendLens key
Create a test key under Dashboard → API keys. Use test keys locally and live keys in production.
Copy an existing project name or slug from Dashboard → Projects into SPENDLENS_PROJECT. SpendLens does not create projects from SDK traffic.
SPENDLENS_API_KEY=sli_test_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
SPENDLENS_PROJECT=shopping-assistant
SPENDLENS_API_BASE_URL=https://spendlensai.dev/backend
SPENDLENS_PROMPT_SAMPLING=template_only
SPENDLENS_DISABLE=0Your application or runtime must load local .env files. Production secrets should come from your deployment platform.
2. Choose your SDK
Python quickstart
pip install spendlensaiimport spendlensaifrom openai import OpenAI client = OpenAI() @spendlensai.observe(workload="customer-support-reply")def generate_reply(message: str): return client.chat.completions.create( model="gpt-4o", messages=[ {"role": "system", "content": "Give concise billing help."}, {"role": "user", "content": message}, ], )Your functional change: two lines. Import SpendLens and add the decorator. Your OpenAI client and request remain unchanged.
Node.js / TypeScript quickstart
npm install spendlensai openai
# Anthropic users can install @anthropic-ai/sdk instead of openai.import OpenAI from "openai";import { observe, track } from "spendlensai"; const openai = track(new OpenAI()); const generateReply = observe("customer-support-reply", async (message) => openai.chat.completions.create({ model: "gpt-4o", messages: [ { role: "system", content: "Give concise billing help." }, { role: "user", content: message } ] }));Your functional change: one import, one client wrapper, and one workload wrapper. The provider request inside remains the same and still goes directly to OpenAI.
3. Run one request and open the dashboard
Call the observed function once, allow a few seconds for the background batch to flush, then open the dashboard. Short scripts should call client.flush() in Python or await client.flush() in Node.js before exit.
If the project name or slug is incorrect, the provider request still succeeds, but SpendLens drops the telemetry and logs a project-not-found warning.
4. Optional: prove a model change in staging
Once SpendLens has enough workload data, open Model recommendations to see the top three policy-approved candidates. Turn on Compare Mode for that workload. Candidate calls run in your staging application with your provider keys and report aggregate cost, speed and reliability. Optional quality evaluation runs separately on SpendLens infrastructure using a redacted template and safe generated data.
This step is optional. Initial cost visibility works without comparison provider keys.
See the five-step Compare Mode flow →Privacy defaults
template_only sends reusable OpenAI system/developer instructions or Anthropic system content. It does not send user messages or model responses. Set SPENDLENS_PROMPT_SAMPLING=off for metadata-only tracking.
Supported calls
| Provider | Python | Node.js |
|---|---|---|
| OpenAI | chat.completions.create, responses.create | chat.completions.create, responses.create |
| Anthropic | messages.create | messages.create |
Direct REST calls and arbitrary HTTP traffic are not automatically captured. SpendLens never proxies provider traffic.