SDK Installation Guide
Get started with HAIEC AI usage tracking in under 60 seconds
Prerequisites
- Node.js 18+
Required for npm package installation
- HAIEC Account
Sign up at haiec.com to get your API key
- OpenAI or Anthropic API Key
Your existing provider API key
OpenAI SDK Installation
Step 1: Install the Package
npm install @haiec/openai openaiThis installs both the HAIEC wrapper and the official OpenAI SDK (peer dependency)
Step 2: Update Your Code
// Before
import OpenAI from 'openai';
const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
// After
import TrackedOpenAI from '@haiec/openai';
const client = new TrackedOpenAI({
apiKey: process.env.OPENAI_API_KEY,
haiecApiKey: process.env.HAIEC_API_KEY,
});
Step 3: Add Environment Variables
# .env
OPENAI_API_KEY=sk-...
HAIEC_API_KEY=haiec_...
Step 4: Test It
// Make a test call
const response = await client.chat.completions.create({
model: 'gpt-4-turbo',
messages: [{ role: 'user', content: 'Hello!' }],
});
// Usage automatically logged to HAIEC!
Check your HAIEC dashboard to see the logged request
Anthropic (Claude) SDK Installation
Step 1: Install the Package
npm install @haiec/anthropic @anthropic-ai/sdkStep 2: Update Your Code
// Before
import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
// After
import TrackedAnthropic from '@haiec/anthropic';
const client = new TrackedAnthropic({
apiKey: process.env.ANTHROPIC_API_KEY,
haiecApiKey: process.env.HAIEC_API_KEY,
});
Troubleshooting
API calls not showing in dashboard?
- •Verify your HAIEC_API_KEY is correct
- •Check browser console for errors
- •Ensure you're using TrackedOpenAI/TrackedAnthropic, not the original SDK
TypeScript errors?
The SDK is fully typed and 100% compatible with the official SDKs. If you see type errors:
npm install --save-dev @types/nodePerformance concerns?
The SDK adds less than 10ms overhead per request. Logging is asynchronous and won't block your API calls.
Next Steps
- View your usage dashboard
See real-time costs and analytics
- Set up budget alerts
Get notified when spending exceeds thresholds
- Export compliance reports
Generate audit-ready evidence