> ## Documentation Index
> Fetch the complete documentation index at: https://docs.inviolet.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenAI SDK

> Wrap openai with Inviolet so every function-call tool execution is gated.

Wrap `openai` with Inviolet so every function-call tool execution goes through
the gateway.

## Install

```bash theme={"dark"}
npm install @inviolet/agent-sdk-openai @inviolet/agent-sdk-core
```

## Use (Chat Completions)

```ts theme={"dark"}
import OpenAI from 'openai'
import { Inviolet } from '@inviolet/agent-sdk-core'
import { wrapOpenAI } from '@inviolet/agent-sdk-openai'

const inviolet = new Inviolet({
  gatewayUrl: process.env.INVIOLET_GATEWAY_URL!,
  apiKey: process.env.INVIOLET_API_KEY!,
  agentId: 'support-copilot',
})

const openai = wrapOpenAI(new OpenAI(), {
  inviolet,
  intentId: 'intents:customer_support_lookup',
  actor: 'alice@example.com',
  audience: 'postgres-prod',
})

const completion = await openai.chat.completions.create({
  model: 'gpt-4o-mini',
  messages: [{ role: 'user', content: 'Look up Bob Smith' }],
  tools: [/* your function defs */],
})
```

## Use (Assistants API)

```ts theme={"dark"}
const run = await openai.beta.threads.runs.create(threadId, {
  assistant_id: assistantId,
})
// Tool calls inside the run are gated automatically.
```

## What the wrapper does

Identical to the Anthropic wrapper: mints a mandate, intercepts every tool
call, calls `inviolet.guard()`, returns a tool result on deny so the model can
pivot.
