Drop-in, compliance-instrumented wrapper around the official OpenAI Python SDK.
Project description
vaxelia-ai-openai
A drop-in, compliance-instrumented wrapper around the official
OpenAI Python SDK. Every non-streaming
chat.completions.create call is logged to your tenant's decision-log endpoint
via vaxelia-ai-core — with its resilient,
encrypted-on-disk buffer — so an AI decision is never silently lost. Every other
method of the OpenAI SDK passes straight through to the real client untouched.
openai is a regular dependency of this package, so the wrapper is a true
single-install drop-in: you do not install the OpenAI SDK separately.
Install
pip install vaxelia-ai-openai
Requires Python >= 3.9.
The one-line swap
Change your import — keep everything else:
- from openai import OpenAI
+ from vaxelia_ai_openai import OpenAI
Usage
import os
from vaxelia_ai_openai import OpenAI
client = OpenAI(
api_key=os.environ["OPENAI_API_KEY"],
# Optional compliance block. Every field falls back to an env var (below),
# so you can also pass nothing here and configure entirely from the env.
compliance={
"ai_system_id": os.environ.get("VAXELIA_AI_SYSTEM_ID"),
"tenant_api_url": os.environ.get("VAXELIA_TENANT_API_URL"),
"api_key": os.environ.get("VAXELIA_API_KEY"),
"buffer_key": os.environ.get("VAXELIA_BUFFER_KEY"),
},
)
# Identical to the official SDK. The decision is logged for you.
completion = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Summarize the attached contract."}],
)
With env vars set, the compliance block can be omitted entirely:
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
The compliance argument accepts either a vaxelia_ai_core.ReporterConfig or a
plain dict with the same field names.
Reaching the raw client
For methods this wrapper does not instrument, the underlying OpenAI client is
available at client.raw, and every other attribute/method (models,
embeddings, responses, with_options, …) delegates to the real client
automatically. On the chat resource, every member other than
completions.create (completions.parse, completions.stream,
with_raw_response, …) delegates directly to the real resource.
Configuration & environment variables
The compliance block is a ReporterConfig from vaxelia-ai-core. Every field
is optional and falls back to a matching environment variable (12-factor):
compliance field |
Environment variable | Description |
|---|---|---|
ai_system_id |
VAXELIA_AI_SYSTEM_ID |
Registered AI system identifier. |
tenant_api_url |
VAXELIA_TENANT_API_URL |
Full decision-log POST endpoint URL. |
api_key |
VAXELIA_API_KEY |
Bearer token for the tenant API. |
buffer_key |
VAXELIA_BUFFER_KEY |
32-byte AES-256-GCM key, base64-encoded. Required to buffer. |
For the encrypted disk buffer, the fail-closed buffer-key rule, retention, and
backoff behaviour, see the
vaxelia-ai-core README. Note: when buffering is
enabled (the default) and no valid 32-byte buffer key is resolvable,
construction raises (MissingBufferKeyError / InvalidBufferKeyError) —
this wrapper surfaces that error rather than swallow it. To run without a disk
buffer, set compliance.buffering_enabled = False.
What gets logged
On each instrumented chat.completions.create call, one decision envelope is
reported:
| Field | Source |
|---|---|
aiSystemId |
compliance.ai_system_id / VAXELIA_AI_SYSTEM_ID |
modelUsed |
the response's model, falling back to the request model |
input |
the chat.completions.create request kwargs |
output |
the provider response (via model_dump()), or on failure {"error": ...} |
status |
completed on success, failed when the provider call raises |
decidedAt |
ISO-8601 timestamp at the moment of the call |
Reporter-error ordering (no silent drops)
The provider response is always obtained first; only then is the decision
logged. If vaxelia-ai-core cannot deliver the decision and cannot durably
buffer it, it raises (DecisionNotRecordedError) — and this wrapper lets that
error surface to your caller. This is deliberate: the whole point of the
compliance layer is that a recorded decision is never silently dropped. If you
prefer delivery failures to be buffered instead of raised, keep buffering enabled
(the default) with a valid buffer key — transient failures (network, 5xx, 429)
are then retried with backoff and buffered to encrypted disk for later flush.
On a failed provider call, the failed decision is reported first (capturing
only the error message, never the raw exception, which may carry request bodies
or credentials), and then the original provider exception is re-raised unchanged.
Scope & limitations
- Streaming is not instrumented in v1. A call with
stream=Truepasses straight through to the real client uninstrumented, so streaming usage never breaks — but no decision is logged for it yet. Streaming compliance capture is a planned enhancement. - The async
AsyncOpenAIclient is out of scope for v1. Only the synchronousOpenAIclient is instrumented; an async sibling is a planned follow-up. - Only
chat.completions.createis instrumented. All other SDK methods delegate to the real client; reachclient.rawfor the underlying object when needed.
Development
# From sdks/python, with the shared venv:
.venv/bin/pip install -e vaxelia-ai-core
.venv/bin/pip install -e vaxelia-ai-openai
.venv/bin/python -m pytest vaxelia-ai-openai
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 Distribution
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 vaxelia_ai_openai-0.1.0.tar.gz.
File metadata
- Download URL: vaxelia_ai_openai-0.1.0.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41fd8e729fdc9392ac1d58987eb1f4b7e0b3335660f19ca759082fdbb746d802
|
|
| MD5 |
cfad239957b86828927fc435c3c02d17
|
|
| BLAKE2b-256 |
4ed6a15e35c425ff97f6679be686df3926348bcea8209818a71d9ccc0ada439e
|
File details
Details for the file vaxelia_ai_openai-0.1.0-py3-none-any.whl.
File metadata
- Download URL: vaxelia_ai_openai-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e84377ff4a03a07d9ab78c8099343bce2e309b05c06987011dbbf1de1613f7b
|
|
| MD5 |
d30ea2f62fa9804161caff519d862670
|
|
| BLAKE2b-256 |
c1a094c3710daff3585b9ca1805e0faeca49a14a0b9037cfd235681f4fcdd5e7
|