
Company News
Socket Joins New OpenJS Program to Fund Node.js Security Work
Socket is joining the OpenJS Security Stewardship Program to fund Node.js vulnerability research, maintainer remediation, and security releases.
@haiec/openai
Advanced tools
OpenAI SDK wrapper with automatic usage tracking and cost calculation for HAIEC AI Inventory
OpenAI SDK wrapper with automatic usage tracking and cost calculation for HAIEC AI Inventory.
npm install @haiec/openai openai
import TrackedOpenAI from '@haiec/openai';
const client = new TrackedOpenAI({
apiKey: process.env.OPENAI_API_KEY!,
haiecApiKey: process.env.HAIEC_API_KEY!,
});
const response = await client.chat.completions.create({
model: 'gpt-4-turbo',
messages: [{ role: 'user', content: 'Hello!' }],
});
console.log(response.choices[0].message.content);
const client = new TrackedOpenAI({
apiKey: 'sk-...', // Your OpenAI API key
haiecApiKey: 'haiec_...', // Your HAIEC API key
haiecEndpoint: 'https://haiec.com/api/v1/inventory/usage/log', // Optional: Custom endpoint
organizationId: 'org-...', // Optional: OpenAI organization ID
});
const client = new TrackedOpenAI({
apiKey: process.env.OPENAI_API_KEY!,
haiecApiKey: process.env.HAIEC_API_KEY!,
haiecEndpoint: 'https://your-haiec-instance.com/api/v1/inventory/usage/log',
});
| Model | Input Cost (per 1M tokens) | Output Cost (per 1M tokens) |
|---|---|---|
| gpt-4-turbo | $10.00 | $30.00 |
| gpt-4 | $30.00 | $60.00 |
| gpt-4-32k | $60.00 | $120.00 |
| gpt-3.5-turbo | $0.50 | $1.50 |
| gpt-3.5-turbo-16k | $3.00 | $4.00 |
Pricing is automatically updated based on OpenAI's latest rates.
For each API call, the following data is logged to HAIEC:
openaigpt-4-turbochat.completionsIf usage tracking fails, the error is logged to console but your OpenAI API call continues normally:
try {
const response = await client.chat.completions.create({...});
// Your response is returned even if tracking fails
} catch (error) {
// Only OpenAI API errors are thrown
}
This wrapper maintains 100% compatibility with the official OpenAI SDK. All methods and parameters work exactly the same.
MIT
FAQs
OpenAI SDK wrapper with automatic usage tracking and cost calculation for HAIEC AI Inventory
The npm package @haiec/openai receives a total of 1 weekly downloads. As such, @haiec/openai popularity was classified as not popular.
We found that @haiec/openai demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.

Company News
Socket is joining the OpenJS Security Stewardship Program to fund Node.js vulnerability research, maintainer remediation, and security releases.

Security News
Two compromised GitHub Actions were re-enabled with malicious tags intact, exposing thousands of downstream repositories to Mini Shai-Hulud.

Research
/Security News
A malicious Firefox extension fetches its payload after installation to evade detection, steal Google session cookies, and automate account takeover.