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

# OpenAI

> Use Averta OpenAI wrappers to protect Responses API and Chat Completions calls.

The Averta OpenAI wrappers keep the native OpenAI SDK shape intact.

After wrapping, you still call the native OpenAI methods. Averta adds decisions around supported request, tool, stream, and output paths.

<CodeGroup>
  ```typescript TypeScript theme={null}
  import OpenAI from "openai";
  import { wrapOpenAI } from "@averta-security/sdk-openai";

  let client = new OpenAI({
    apiKey: process.env.OPENAI_API_KEY!,
  });

  client = wrapOpenAI(client);
  ```

  ```python Python theme={null}
  import os

  from openai import OpenAI
  from averta_openai import wrap_openai

  client = wrap_openai(OpenAI(api_key=os.environ["OPENAI_API_KEY"]))
  ```
</CodeGroup>

## Supported Surfaces

| Surface                                          | JavaScript | Python                |
| ------------------------------------------------ | ---------- | --------------------- |
| `responses.create(...)`                          | Yes        | Yes                   |
| `responses.create({ stream: true, ... })`        | Yes        | Yes, as `stream=True` |
| `responses.stream(...)`                          | Yes        | Yes                   |
| `chat.completions.create(...)`                   | Yes        | Yes                   |
| `chat.completions.create({ stream: true, ... })` | Yes        | Yes, as `stream=True` |

Unsupported helpers under guarded Python namespaces fail closed. Provider surfaces not listed here are outside Averta coverage; JavaScript and Python clients may keep their native behavior there unless you add separate enforcement.

## What Averta Checks

Depending on the call shape, the wrapper can:

* evaluate request input before it reaches OpenAI
* filter tools when policy returns `restrict_tools`
* evaluate model-requested tool calls before your app executes them
* evaluate tool results before they go back to the model
* evaluate non-streaming final output and request a rewrite when policy allows it
* evaluate streaming text as it is produced

## Current Limits

* Rich media support is limited to Data URL images for supported image MIME types.
* Chat Completions streaming supports one streamed text choice.
* Responses streaming supports one output text stream per response.
* Output rewrites are supported for non-streaming calls.
* Streaming output rewrite is not supported and fails closed.

## Reading Path

Start with the quickstart, then read the page for the OpenAI surface your agent uses.

<CardGroup cols={2}>
  <Card title="Quickstart" icon="rocket" href="/openai/quickstart">
    Wrap an OpenAI client and run a guarded request.
  </Card>

  <Card title="Responses API" icon="message" href="/openai/responses-api">
    Guard `responses.create(...)` and Responses tool loops.
  </Card>

  <Card title="Chat Completions" icon="messages" href="/openai/chat-completions">
    Guard `chat.completions.create(...)` calls.
  </Card>

  <Card title="Tools" icon="toolbox" href="/openai/tools">
    Understand request-time tool exposure filtering.
  </Card>

  <Card title="Output checks" icon="file-shield" href="/openai/output-checks">
    Understand final-answer checks and rewrites.
  </Card>
</CardGroup>
