@tethora/openai
v1.1.0
Published
OpenAI integration for Tethora. Auto-log all chat completions and tool calls to your AI governance platform.
Maintainers
Readme
@tethora/openai
OpenAI integration for Tethora - the AI agent governance and compliance platform.
Wraps your OpenAI client to automatically enforce policies and log all chat completions and tool calls. Actions that violate your policies are blocked before the API call is made.
Install
npm install @tethora/openai tethora-sdk openaiUsage
import OpenAI from 'openai';
import { Tethora } from 'tethora-sdk';
import { wrapOpenAI } from '@tethora/openai';
const tethora = new Tethora({ apiKey: 'your-tethora-api-key' });
const openai = wrapOpenAI(new OpenAI(), {
client: tethora,
sessionId: 'conversation-123', // optional
});
// All calls are now checked against your policies and logged
const response = await openai.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: 'Hello!' }],
});Policy Enforcement
Before each API call, the wrapper checks your Tethora policies. If a policy blocks the action, the OpenAI call is never made and a BlockedError is thrown:
import { BlockedError } from '@tethora/openai';
try {
const response = await openai.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: 'Hello!' }],
});
} catch (err) {
if (err instanceof BlockedError) {
console.log('Blocked by policy:', err.violations);
}
}To disable enforcement and use logging only:
const openai = wrapOpenAI(new OpenAI(), {
client: tethora,
skipCheck: true, // Log only, no policy enforcement
});What Gets Logged
| Event Type | Actions | Data Captured |
|-----------|---------|---------------|
| llm_call | chat.start, chat.complete, chat.error, chat.blocked | Model, message count, temperature, token usage, finish reason, duration |
| tool_call | tool.[name] | Tool name, arguments (for each tool call in the response) |
Configuration
wrapOpenAI(openaiClient, {
client: tethora, // Required: Tethora SDK instance
sessionId: '...', // Optional: group events by session
agentId: '...', // Optional: override default agent ID
skipCheck: false, // Optional: set true to disable policy enforcement
});Links
Licence
MIT
