Skip to content

OpenAI SDK

Wrap an OpenAI Assistants API run in a TapPass session. Every run emits a structured audit event with correlation IDs. Every server-side governance decision surfaces as a typed exception.

pip install 'tappass[openai]'
from openai import OpenAI
from tappass.integrations.openai import guard_openai_run
client = OpenAI()
with guard_openai_run(
client,
assistant_id="asst_...",
tappass_url="https://tappass.example.com",
api_key="tp_...",
) as session:
thread = client.beta.threads.create()
run = session.create_and_poll_run(thread.id, "Summarize Q4")
print(session.audit_url)
from tappass.integrations.openai import guard_openai_run_async
async with guard_openai_run_async(
client,
assistant_id="asst_...",
tappass_url=...,
api_key="tp_...",
) as session:
thread = await client.beta.threads.create()
run = await session.create_and_poll_run(thread.id, "Summarize Q4")

For client.chat.completions.create(...) without the Assistants API, use env-var passthrough instead — no SDK import needed:

export OPENAI_BASE_URL=https://tappass.example.com/v1
export OPENAI_API_KEY=tp_...

Every chat completion now routes through the governance pipeline transparently.

from tappass import GovernanceDecision, PolicyBlockError
try:
with guard_openai_run(client, assistant_id="asst_...",
tappass_url=..., api_key="tp_...") as session:
session.create_and_poll_run(thread_id, "Show all SSNs")
except PolicyBlockError as e:
print(f"Blocked by {e.blocked_by}: {e.reason}")
print(f"See {e.audit_url}")
except GovernanceDecision as e:
print(f"Governance: {e}")

The 0.5 env-var-only story for Assistants runs is replaced by guard_openai_run for full correlation and typed decisions. See the migration guide.