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

# OpenAI

> Scan OpenAI Chat Completions and Responses API traffic through the PromptGuard proxy or the SDK auto-instrumentation

Two ways in: point the OpenAI client at the proxy, or call `init()` and keep the client as it is ([auto-instrumentation](https://docs.promptguard.co/integrations/auto-instrumentation.md) patches the `openai` package in Python and Node).

## Proxy

> [!NOTE]
>
> **Proxy Base URL:** `https://api.promptguard.co/api/v1`
>
> Point your LLM SDK's `base_url` / `baseURL` to this endpoint. Your existing provider API key goes in the `Authorization` header as usual; add your PromptGuard key via `X-API-Key`.

The proxy serves the Chat Completions route (`/chat/completions`) and the Responses API route (`/responses`) for OpenAI models. It sends a model to OpenAI when its id starts with `gpt-`, `o1`, `o3`, `o4`, `o5` or `chatgpt-`, among the other OpenAI families, and that id is not claimed by a more specific provider first ([how the proxy picks a provider](https://docs.promptguard.co/integrations/overview.md#how-the-proxy-picks-a-provider)).

```python Python theme={"system"}
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.promptguard.co/api/v1",
    api_key=os.environ["OPENAI_API_KEY"],  # forwarded to OpenAI
    default_headers={"X-API-Key": os.environ["PROMPTGUARD_API_KEY"]},
)

response = client.chat.completions.create(
    model="gpt-5-nano",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)
```

```typescript Node.js theme={"system"}
import OpenAI from 'openai';

const client = new OpenAI({
  baseURL: 'https://api.promptguard.co/api/v1',
  apiKey: process.env.OPENAI_API_KEY, // forwarded to OpenAI
  defaultHeaders: { 'X-API-Key': process.env.PROMPTGUARD_API_KEY },
});

const response = await client.chat.completions.create({
  model: 'gpt-5-nano',
  messages: [{ role: 'user', content: 'Hello!' }],
});
console.log(response.choices[0].message.content);
```

```bash cURL theme={"system"}
curl https://api.promptguard.co/api/v1/chat/completions \
  -H "X-API-Key: $PROMPTGUARD_API_KEY" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "gpt-5-nano", "messages": [{"role": "user", "content": "Hello!"}]}'
```

The body is OpenAI's reply, unchanged; the Python and Node.js samples print its text. PromptGuard's verdict comes back in response headers. From a run against our staging environment (`curl -i`):

```text theme={"system"}
x-promptguard-event-id: 4f90bc38-10d4-44a4-9b51-c5ffd1560ef6
x-promptguard-decision: allow
x-promptguard-confidence: 1.0
x-promptguard-model-used: gpt-5-nano
```

The [response headers](https://docs.promptguard.co/api-reference/introduction.md#response-headers) section lists every one.

To keep the OpenAI key out of your application, [store it as a provider key](https://docs.promptguard.co/gateway/provider-keys.md) under `openai`. PromptGuard then sends the stored key and ignores the `Authorization` header you send.

For a GPT-5 model the proxy renames `max_tokens` to `max_completion_tokens`, the only name OpenAI accepts for that family, so older client code keeps working.

## Auto-instrumentation

```python Python theme={"system"}
import promptguard
promptguard.init()  # reads PROMPTGUARD_API_KEY

from openai import OpenAI
client = OpenAI()  # talks to OpenAI directly; each call is scanned first
```

```typescript Node.js theme={"system"}
import { init } from 'promptguard-sdk';
import OpenAI from 'openai';

init(); // reads PROMPTGUARD_API_KEY
const client = new OpenAI(); // talks to OpenAI directly; each call is scanned first
```

Which OpenAI calls are scanned, and which are not, is listed on the [auto-instrumentation](https://docs.promptguard.co/integrations/auto-instrumentation.md) page.

## Azure OpenAI

Azure-hosted OpenAI deployments use their own namespace and headers: see [Azure OpenAI](https://docs.promptguard.co/integrations/providers/azure-openai.md).

## Next steps

> [card] [Streaming](https://docs.promptguard.co/guides/streaming.md)
>
> How streamed responses are buffered, scanned and released

> [card] [Auto-instrumentation](https://docs.promptguard.co/integrations/auto-instrumentation.md)
>
> Which provider calls `init()` patches, and which it does not

> [card] [Provider keys](https://docs.promptguard.co/gateway/provider-keys.md)
>
> Store your provider credentials once, forwarded server-side


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.