Documentation
GPTree SDK
Track the environmental impact of your AI applications with just a few lines of code.
Installation
npm install @gptree/sdkQuick Start
Basic Usage
Wrap your AI provider client to automatically track all API calls.
import { GPTree } from '@gptree/sdk'
import OpenAI from 'openai'
// Initialize GPTree with your API key
const gptree = new GPTree({
apiKey: process.env.GPTREE_API_KEY
})
// Wrap your OpenAI client
const openai = gptree.wrap(new OpenAI())
// Use OpenAI as normal - all calls are automatically tracked
const response = await openai.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: 'Hello!' }]
})Manual Tracking
Track Custom Events
Send telemetry data directly when using unsupported providers.
import { GPTree } from '@gptree/sdk'
const gptree = new GPTree({
apiKey: process.env.GPTREE_API_KEY
})
// Track a single event
await gptree.track({
model: 'gpt-4',
prompt_tokens: 150,
completion_tokens: 50,
latency_ms: 1200
})
// Track batch events
await gptree.trackBatch([
{ model: 'gpt-4', prompt_tokens: 100, completion_tokens: 50 },
{ model: 'claude-3-sonnet', prompt_tokens: 200, completion_tokens: 100 }
])REST API
Direct API Access
Use the REST API directly from any language or platform.
POST /api/telemetry
Record a telemetry event for your project.
curl -X POST https://your-app.vercel.app/api/telemetry \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4",
"prompt_tokens": 150,
"completion_tokens": 50,
"latency_ms": 1200
}'GET /api/telemetry
Retrieve telemetry events for your project.
curl https://your-app.vercel.app/api/telemetry?limit=100 \
-H "Authorization: Bearer YOUR_API_KEY"Public Widget
Embed Your Impact
Display your environmental metrics on your website.
Badge Image
Add a simple badge to show your tracked carbon footprint.
<img
src="https://your-app.vercel.app/badge/your-project-slug"
alt="Carbon Footprint Badge"
/>Full Widget
Embed a detailed impact widget with iframe.
<iframe
src="https://your-app.vercel.app/widget/your-project-slug"
width="400"
height="300"
style="border: none; border-radius: 12px;"
/>Supported Models
OpenAI GPT-4
OpenAI GPT-3.5
Claude 3 Opus
Claude 3 Sonnet
Claude 3 Haiku
Gemini Pro
Gemini Ultra
Llama 2/3
Mistral
Mixtral
Unknown models use default energy estimates. Contact us to add specific model data.