# Azure Integration

You can use GPTBoost with your Azure-OpenAI deployment, and it requires no additional code changes beyond replacing the `azure_endpoint` with the GPTBoost URL. Similar to communicating with OpenAI API, GPTBoost [acts as a proxy](https://docs.gptboost.io/advanced/proxy-overview) between the client and your Azure OpenAI deployment.

To start, make sure you have an active Azure Subscription and that you've activated Azure OpenAI for it. If you haven't done this yet, check on how to [set up Azure OpenAI Services](#set-up-azure-openai-services).

In case, you already have your Azure deployments ready, you can proceed to [add an Azure Key to GPTBoost](#add-your-azure-key-to-gptboost).

#### Set up Azure OpenAI Services

Remember, you'll need Python version 3.7.1 or later to meet the minimum requirements.

1. Start by setting up your [Azure subscription](https://azure.microsoft.com/en-us/free/) - there's a free tier available.
2. Access to Azure OpenAI Services is granted through an application. Apply for access by filling out the form at <https://aka.ms/oai/access>. They'll ask you a few questions, and then you just need to wait for Microsoft to approve your request.&#x20;
3. Deploy the OpenAI model following the official [Azure documentation.](https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/create-resource?pivots=web-portal#deploy-a-model)&#x20;

#### Add your Azure Key to GPTBoost

Setting up the monitoring of your Azure OpenAI model statistics in GPTBoost is pretty straightforward.&#x20;

1. Head over to your GPTBoost account -> OpenAI API Keys.
2. Next, select Add Key.
3. For **Provider** choose Azure OpenAI from the drop-down menu.

<figure><img src="https://733697247-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmvbgcUmdD6m1azzEtXMG%2Fuploads%2FsDlbdnmdnMCBPrtk4EAV%2Fadd_keys_choose_provider_azure.png?alt=media&#x26;token=9964306d-6743-4183-904f-20eac9f6adb5" alt=""><figcaption></figcaption></figure>

4. Fill in your credentials. You'll need the **Azure OpenAI API Key,** the **API version** and **the Azure endpoint.** The Endpoint and Keys can be found in the Resource Management section of your Azure portal. More info on these credentials can be found [here](https://learn.microsoft.com/en-us/azure/ai-services/openai/quickstart?tabs=command-line%2Cpython\&pivots=programming-language-python#retrieve-key-and-endpoint).

<figure><img src="https://733697247-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmvbgcUmdD6m1azzEtXMG%2Fuploads%2FAObpAcHn7B5lEmlJVimB%2Fadd_azure_key.png?alt=media&#x26;token=a06081ff-4171-4e10-b0dc-e37c20046f19" alt=""><figcaption><p>Adding an Azure OpenAi Key in GPTBoost</p></figcaption></figure>

#### Code Examples&#x20;

Once your Azure OpenAI deployment is set and the Azure Key is authorized in GTPBoost, you can start monitoring all requests by replacing the  `azure_endpoint` with the GPTBoost URL.&#x20;

{% tabs %}
{% tab title="Python" %}

```python
# This example is for v1+ of the openai: https://pypi.org/project/openai/
from openai import AzureOpenAI

client = AzureOpenAI(
    # Set GPTBoost API base URL for azure_endpoint
    azure_endpoint = "https://turbo.gptboost.io/v1",
    api_key = "AZURE_OPENAI_KEY",
    api_version = "2023-07-01-preview",
)

message = [
    {
        "role":"user",
        "content":'Write a tagline for an ice cream shop. '
    }
]

deployment_name="gpt-35-turbo-16k"

response = client.chat.completions.create(
    model=deployment_name, 
    messages=message
)

print(response.choices[0].message.content)
```

{% endtab %}

{% tab title="NodeJS" %}

```javascript
import { OpenAIClient, AzureKeyCredential } from "@azure/openai" ;

async function main(){

    const client = new OpenAIClient(
        // Set GPTBoost API base URL for azure_endpoint
        "https://turbo.gptboost.io/v1",
        new AzureKeyCredential("AZURE_OPENAI_KEY"),
        "2023-07-01-preview" //Azure API Version
        );
    
    const messages = [
        { role: "user", content: "Say 'Hello, World'" },
    ];

    
    const { id, created, choices, usage } = await client.getChatCompletions("gpt-35-turbo-16k", messages)
    
    for (const choice of choices) {
        console.log(choice.message.content);
    }
}

main().catch((err) => {
    console.error("The sample encountered an error:", err);
});
```

{% endtab %}
{% endtabs %}
