> ## 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.

# Azure OpenAI

> Scan Azure OpenAI deployments through the PromptGuard proxy by naming the deployment and the resource

## 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`.

Name your deployment in the model id under the `azure/` namespace, and your Azure OpenAI resource in the `X-Azure-Resource` header. PromptGuard builds the Azure URL from the two, `https://<resource>.openai.azure.com/openai/deployments/<deployment>/chat/completions`, and sends your key as the `api-key` header Azure expects. A request in the `azure/` namespace without `X-Azure-Resource` is refused with a `400` whose error code is [`missing_header`](https://docs.promptguard.co/production/error-handling#error-code-reference), and nothing is sent to Azure.

Use the plain OpenAI client, not `AzureOpenAI`: the Azure client builds the deployment URL itself, and PromptGuard needs the request on its own route to do that for you.

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

client = OpenAI(
    base_url="https://api.promptguard.co/api/v1",
    api_key=os.environ["AZURE_OPENAI_API_KEY"],  # forwarded to Azure as api-key
    default_headers={
        "X-API-Key": os.environ["PROMPTGUARD_API_KEY"],
        "X-Azure-Resource": "my-openai-resource",  # the <resource> in <resource>.openai.azure.com
    },
)

response = client.chat.completions.create(
    model="azure/my-gpt-deployment",  # azure/<your deployment name>
    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.AZURE_OPENAI_API_KEY, // forwarded to Azure as api-key
  defaultHeaders: {
    'X-API-Key': process.env.PROMPTGUARD_API_KEY,
    'X-Azure-Resource': 'my-openai-resource',
  },
});

const response = await client.chat.completions.create({
  model: 'azure/my-gpt-deployment',
  messages: [{ role: 'user', content: 'Hello!' }],
});
```

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

The deployment name keeps your spelling; only the `azure/` namespace is matched without regard to case. PromptGuard calls Azure with `api-version=2024-02-15-preview`.

To keep the Azure key out of your application, [store it as a provider key](https://docs.promptguard.co/gateway/provider-keys.md) under `azure_openai`. You still send `X-Azure-Resource` on each request.

## Auto-instrumentation

The Python and Node `openai` patches cover `AzureOpenAI` as well, because it shares the OpenAI client's chat completions resource. See [auto-instrumentation](https://docs.promptguard.co/integrations/auto-instrumentation.md).

## Next steps

> [card] [OpenAI](https://docs.promptguard.co/integrations/providers/openai.md)
>
> Chat Completions and Responses through the proxy

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

> [card] [Routing rules](https://docs.promptguard.co/gateway/routing-rules.md)
>
> Rewrite the upstream provider or model per request


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