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

# Azure OpenAI

> Azure OpenAI is a great alternative to accessing the best models including GPT-4 and more in your private environments. The Prisma AIRS AI Gateway provides complete support for Azure OpenAI.

With the AI Gateway, you can take advantage of features like fast AI gateway access, observability, prompt management, and more, all while ensuring the secure management of your LLM API keys through [Model Catalog](/docs/aigw/product/model-catalog).

## Using Azure OpenAI with the AI Gateway

The AI Gateway provides a consistent API to interact with models from various providers. To integrate Azure OpenAI with the AI Gateway:

# Creating Your Azure OpenAI Integration

<Note>
  This integration is for all OpenAI models deployed on either Azure OpenAI or Azure AI Foundry.
</Note>

Integrate Azure OpenAI models with the AI Gateway to centrally manage your AI models and deployments. This guide walks you through setting up the integration using API key authentication.

## Prerequisites

Before creating your integration, you'll need:

* An active [Azure account](https://ai.azure.com)
* Access to your Azure portal
* A model deployment on Azure (e.g., GPT-4, GPT-4o-mini)

## Step 1: Start Creating Your Integration

Navigate to the Integrations page in Strata Cloud Manager and select **Azure OpenAI** as your provider.

## Step 2: Configure Integration Details

Fill in the basic information for your integration:

* **Name**: A descriptive name for this integration (e.g., "Azure OpenAI Production")
* **Short Description**: Optional context about this integration's purpose
* **Slug**: A unique identifier used in API calls (e.g., "azure-openai-prod")

## Step 3: Set Up Authentication

The AI Gateway supports three authentication methods for Azure OpenAI. For most use cases, we recommend using the **Default (API Key)** method.

### Gather Your Azure Credentials

From your Azure portal, you'll need to collect:

### Enter Credentials in the AI Gateway

1. Navigate to your model deployment in Azure
2. Click on the deployment to view details
3. Copy the **API Key** from the authentication section

<Note>
  We recommend importing your Azure details (resource name, deployment details, API version) directly from your Target URI. Simply copy the target URL and import it.
</Note>

4. **Azure Resource Name**: Get Your resource Name from Azure

<Accordion title="Find Your Azure Resource Name">
  Your  Azure resource Name is different from your Project Name. Here's how you can find it:
</Accordion>

4. Note the **API Version** and enter it in the given field
5. **Alias Name**: A gateway-specific field for accessing the model - name it as you prefer
6. **Foundation Model**: Select a foundation model from the list that matches your deployment. This helps the AI Gateway track costs and metrics. If your model isn't listed, choose a similar model type to begin with.

## Adding Multiple Models to Your Azure OpenAI Integration

You can deploy multiple models through a single Azure OpenAI integration by adding multiple deployments under the same integration.

Follow the same steps as above for each additional model deployment.

### 1. Install the OpenAI SDK

Add the OpenAI SDK to your application to interact with Azure OpenAI's API through the AI Gateway.

<Tabs>
  <Tab title="NodeJS">
    ```sh theme={"system"}
    npm install openai --save
    ```
  </Tab>

  <Tab title="Python">
    ```sh theme={"system"}
    pip install openai
    ```
  </Tab>
</Tabs>

### 2. Initialize the AI Gateway with the Azure

Set up the AI Gateway with your Azure Integration as part of the initialization configuration. You can create a [provider](/docs/aigw/product/model-catalog) for Azure in Strata Cloud Manager.

### **3. Invoke Chat Completions with Azure OpenAI**

Use the AI Gateway instance to send requests to your Azure deployments. You can also override the provider slug directly in the API call if needed.

## Managing Azure OpenAI Prompts

You can manage all prompts to Azure OpenAI in the Prompt Library. All the current models of OpenAI are supported and you can easily start testing different prompts.

Once you're ready with your prompt, call the `POST /v1/prompts/{promptId}/completions` endpoint to use it in your application.

## Image Generation

The AI Gateway supports multiple modalities for Azure OpenAI and you can make image generation requests through AI Gateway the same way as making completion calls.

The AI Gateway's fast AI gateway captures the information about the request on Strata Cloud Manager. On your logs screen, you'd be able to see this request with the request and response.

Log view for an image generation request on Azure OpenAI

More information on image generation is available in the API Reference.

***

## Azure Government Cloud

<Note>
  Integration is identical to global Azure OpenAI. Set a Custom Host that points to Azure Government and ensure the path ends with `/openai` (remove any params after `/openai`).
</Note>

### Steps

1. In the AI Gateway, create or edit your Azure OpenAI provider.
2. Open "Advanced Options".
3. Set "Custom Host" to:
   ```text theme={"system"}
   https://{your-azure-resource-name}.openai.azure.us/openai
   ```

<Note>
  You need to set the Custom Host to the Azure Government endpoint and ensure the path ends with the first `/openai` (remove any params after `/openai`).
</Note>

4. Save and use normally in SDKs and via the gateway.

For Azure Government vs global differences and endpoints, see: [Compare Azure Government and global Azure](https://learn.microsoft.com/en-us/azure/azure-government/compare-azure-government-global-azure).

***

## Making Requests Without Model Catalog

Here's how you can pass your Azure OpenAI details & secrets directly without using the Model Catalog feature.

### Key Mapping

In a typical Azure OpenAI request,

```sh theme={"system"}
curl https://{YOUR_RESOURCE_NAME}.openai.azure.com/openai/deployments/{YOUR_DEPLOYMENT_NAME}/chat/completions?api-version={API_VERSION} \
  -H "Content-Type: application/json" \
  -H "api-key: {YOUR_API_KEY}" \
  -d '{
    "model": "gpt-4o",
    "messages": [
      {
        "role": "system",
        "content": "You are a helpful assistant"
      },
      {
        "role": "user",
        "content": "what is a portkey?"
      }
    ]
}'
```

| Parameter             | Node SDK                            | Python SDK                           | REST Headers                  |
| --------------------- | ----------------------------------- | ------------------------------------ | ----------------------------- |
| AZURE RESOURCE NAME   | azureResourceName                   | azure\_resource\_name                | x-portkey-azure-resource-name |
| AZURE DEPLOYMENT NAME | azureDeploymentId                   | azure\_deployment\_id                | x-portkey-azure-deployment-id |
| API VERSION           | azureApiVersion                     | azure\_api\_version                  | x-portkey-azure-api-version   |
| AZURE API KEY         | Authorization: "Bearer + {API_KEY}" | Authorization = "Bearer + {API_KEY}" | Authorization                 |
| AZURE MODEL NAME      | azureModelName                      | azure\_model\_name                   | x-portkey-azure-model-name    |

### Example

<Tabs>
  <Tab title="cURL">
    ```sh theme={"system"}
    curl https://aigw.portkey.ai/v1/chat/completions \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $AZURE_OPENAI_API_KEY" \
      -H "x-portkey-api-key: $PORTKEY_API_KEY" \
      -H "x-portkey-provider: azure-openai" \
      -H "x-portkey-azure-resource-name: $AZURE_RESOURCE_NAME" \
      -H "x-portkey-azure-deployment-id: $AZURE_DEPLOYMENY_ID" \
      -H "x-portkey-azure-model-name: $AZURE_MODEL_NAME" \
      -H "x-portkey-azure-api-version: $AZURE_API_VERSION" \
      -d '{
        "model": "gpt-4o",
        "messages": [{"role": "user","content": "Hello!"}]
      }'
    ```
  </Tab>
</Tabs>

### How to Pass JWT (JSON Web Tokens)

If you have configured fine-grained access for Azure OpenAI and need to use `JSON web token (JWT)` in the `Authorization` header instead of the regular `API Key`, you can use the `forwardHeaders` parameter to do this.

## Next Steps

You'll find more information in the relevant sections:

1. [Add metadata to your requests](/docs/aigw/product/observability/metadata)
2. [Add gateway configs to your Azure OpenAI requests](/docs/aigw/product/ai-gateway/configs)
3. [Tracing Azure OpenAI requests](/docs/aigw/product/observability/traces)
4. [Setup a fallback from OpenAI to Azure OpenAI APIs](/docs/aigw/product/ai-gateway/fallbacks)


## Related topics

- [Gateway Config Object](/docs/aigw/api-reference/inference-api/config-object.md)
- [Langsmith](/docs/aigw/integrations/tracing-providers/langsmith.md)
- [Langfuse](/docs/aigw/integrations/tracing-providers/langfuse.md)
- [Microsoft Azure](/docs/aigw/integrations/cloud/azure.md)
- [Azure AI Foundry](/docs/aigw/integrations/llms/azure-foundry.md)
