Skip to main content

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.

Metadata

Release files for aiguard-sdk-python 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for aiguard-sdk-python 0.1.0
File Interpreter ABI Platform
aiguard_sdk_python-0.1.0-py3-none-any.whl Python 3 none any Details

Release files / aiguard_sdk_python-0.1.0-py3-none-any.whl

Download URL aiguard_sdk_python-0.1.0-py3-none-any.whl
Size 4.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0c152ff4086acf27ab098c0e3c7818e8f6dd16fc85b5d4c829797cc607efa1df
BLAKE2b-256 checksum
How to use checksums
f7bcd4f57ceabb2d6f9e18786bf731541c85a3f04c671d089d248b287baeda16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Security for aiguard-sdk-python 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page