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.
Install
Section titled “Install”pip install 'tappass[openai]'Govern an Assistants run
Section titled “Govern an Assistants run”from openai import OpenAIfrom 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)Async variant
Section titled “Async variant”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")Zero-code gateway (chat completions)
Section titled “Zero-code gateway (chat completions)”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/v1export OPENAI_API_KEY=tp_...Every chat completion now routes through the governance pipeline transparently.
Handling governance decisions
Section titled “Handling governance decisions”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}")Migrating from 0.5
Section titled “Migrating from 0.5”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.