Skip to content

Commit 21190bf

Browse files
committed
docs: Update README to showcase built-in automatic tracking (v1.1.0)
- Added prominent section showing trackedGPT(), trackedClaude(), etc. - Showcased middleware pattern with createTrackedClient() - Showcased SDK extensions (TrackedOpenAI, TrackedAnthropic) - Emphasized no exec() needed - direct function imports - Updated features list with automatic tracking - Added link to EXAMPLES.ts file
1 parent a2263bb commit 21190bf

1 file changed

Lines changed: 78 additions & 7 deletions

File tree

README.md

Lines changed: 78 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,16 @@ at stats
3838

3939
> **Demo:** _[Add GIF here showing cost tracking in action]_
4040
41-
## Features
41+
## Features
4242

43-
- **Multi-Provider Support** - OpenAI, Anthropic, Google, Azure, Cohere
44-
- **Automatic Cost Calculation** - Up-to-date pricing for all major models
45-
- **Beautiful Stats** - See usage by provider, model, and time period
46-
- **Local Storage** - All data stored locally in SQLite (privacy-first)
47-
- **Fast & Lightweight** - CLI tool, no GUI overhead
48-
- **JSON Export** - Pipe data to other tools
43+
- **🎯 Automatic Tracking** - Built-in wrappers, middleware, and SDK extensions (NEW in v1.1.0)
44+
- **🌍 Multi-Provider Support** - OpenAI, Anthropic, Google, Azure, Cohere
45+
- **💰 Automatic Cost Calculation** - Up-to-date pricing for all major models
46+
- **📊 Beautiful Stats** - See usage by provider, model, and time period
47+
- **🔒 Local Storage** - All data stored locally in SQLite (privacy-first)
48+
- **⚡ Fast & Lightweight** - CLI tool, no GUI overhead
49+
- **📤 JSON Export** - Pipe data to other tools
50+
- **📝 Programmatic API** - Use in your code without CLI calls
4951

5052
## Installation
5153

@@ -302,6 +304,75 @@ For AI coding tools (Cursor, Claude Code):
302304
at add -p anthropic -m claude-3.5-sonnet -i 15000 -o 8000 -n "2hr coding session"
303305
```
304306

307+
## 🚀 NEW: Built-in Automatic Tracking (v1.1.0+)
308+
309+
The package now includes **ready-to-use automatic tracking functions** - no need for `exec()` or CLI calls!
310+
311+
### Import and Use Directly
312+
313+
```typescript
314+
// ✨ Method 1: Wrapper Functions (Easiest)
315+
import { trackedGPT, trackedClaude, trackedGemini } from 'aitoken-cli/wrappers';
316+
import OpenAI from 'openai';
317+
import Anthropic from '@anthropic-ai/sdk';
318+
319+
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
320+
const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
321+
322+
// Just use trackedGPT() instead of openai.chat.completions.create()
323+
const response = await trackedGPT(openai, {
324+
model: 'gpt-4o',
325+
messages: [{ role: 'user', content: 'Hello!' }]
326+
// Automatically tracked! ✅
327+
});
328+
329+
const claudeResponse = await trackedClaude(anthropic, {
330+
model: 'claude-sonnet-4.5',
331+
max_tokens: 1024,
332+
messages: [{ role: 'user', content: 'Explain TypeScript' }]
333+
// Automatically tracked! ✅
334+
});
335+
```
336+
337+
```typescript
338+
// ✨ Method 2: Middleware Pattern (Zero Code Changes)
339+
import { createTrackedClient } from 'aitoken-cli/middleware';
340+
import OpenAI from 'openai';
341+
342+
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
343+
344+
// Wrap your client once
345+
const trackedOpenAI = createTrackedClient(openai, {
346+
provider: 'openai',
347+
model: 'gpt-4o'
348+
});
349+
350+
// Use it exactly like normal - tracking happens automatically
351+
const response = await trackedOpenAI.chat.completions.create({
352+
model: 'gpt-4o',
353+
messages: [{ role: 'user', content: 'Hello!' }]
354+
});
355+
// Automatically tracked with zero code changes! ✅
356+
```
357+
358+
```typescript
359+
// ✨ Method 3: SDK Extensions (Drop-in Replacement)
360+
import { TrackedOpenAI, TrackedAnthropic } from 'aitoken-cli/extensions';
361+
362+
// Just change the import - everything else stays the same!
363+
const openai = new TrackedOpenAI({
364+
apiKey: process.env.OPENAI_API_KEY
365+
});
366+
367+
const response = await openai.chat.completions.create({
368+
model: 'gpt-4o',
369+
messages: [{ role: 'user', content: 'Hello!' }]
370+
});
371+
// Automatically tracked! ✅
372+
```
373+
374+
**See [EXAMPLES.ts](./EXAMPLES.ts) for 12 complete examples including Express.js, Next.js, and chatbot integrations.**
375+
305376
### Budget Alerts
306377

307378
Check if you're over budget:

0 commit comments

Comments
 (0)