AIGuard SDK for monitoring and logging AI model invocations
Project description
AIGuard Python SDK
Python SDK for monitoring and logging AI model invocations with AIGuard.
Installation
pip install aiguard
Or install from source:
pip install -e /path/to/python-sdk
Usage
Initialize the client
from aiguard import AIGuard
guard = AIGuard(api_key="your-api-key")
Direct API calls
# Start an invocation
invocation = guard.start_invocation({
"eventId": "unique-event-123",
"event": "chat-completion",
"userId": "user-456",
"inputMessage": "Hello, how are you?",
"model": "gpt-4",
"convoId": "conversation-789",
"properties": {"temperature": 0.7}
})
# ... make your AI call ...
# End the invocation
completed = guard.end_invocation({
"eventId": "unique-event-123",
"output": "I am doing well, thank you!"
})
Manual logging
guard.log({
"model": "gpt-4",
"input": [{"role": "user", "content": "Hello"}],
"output": "Hi there!",
"latency": 150,
"tokens": {"prompt": 10, "completion": 5, "total": 15},
"status": "success"
})
Wrap OpenAI client (automatic logging)
from openai import OpenAI
from aiguard import AIGuard
guard = AIGuard(api_key="your-api-key")
client = guard.wrap_openai(OpenAI())
# All chat completion calls are now automatically logged
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "Hello!"}]
)
API Reference
AIGuard(api_key, base_url="http://localhost:5000/api")
Initialize the AIGuard client.
start_invocation(data) -> dict
Start tracking an invocation. Required fields: eventId, event, userId.
end_invocation(data) -> dict
End an invocation. Required field: eventId.
log(data) -> None
Fire-and-forget logging of a model call.
wrap_openai(client) -> client
Wrap an OpenAI client for automatic logging.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aiguard_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: aiguard_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6eac9ea3962e3ce26c8427013df262a69781f1dec52659b57b729345c39fc72d
|
|
| MD5 |
25b48d8b8bc23046267cb7bf3e61bec0
|
|
| BLAKE2b-256 |
7ddaf83f0a7d6854b514e04111988505a39fbadffdb93b1d7bfe87198c70baee
|