> ## 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](/integrations/auto-instrumentation) 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`.
</Note>

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](/integrations/overview#how-the-proxy-picks-a-provider)).

<CodeGroup>
  ```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!"}]}'
  ```
</CodeGroup>

To keep the OpenAI key out of your application, [store it as a provider key](/gateway/provider-keys) 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 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
```

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

## Azure OpenAI

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


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