> ## Documentation Index
> Fetch the complete documentation index at: https://hobbyist-e43fa225.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Speech to text with Whisper

> Learn how to use the Azure OpenAI Whisper model for speech to text conversion.

export const ZonePivot = ({group, options = [], defaultValue, label = "Choose an experience"}) => {
  const values = options.map(option => option.id);
  const optionKey = options.map(option => `${option.id}:${option.title}`).join("|");
  const [activePivot, setActivePivot] = useState(defaultValue || values[0]);
  const slugify = value => value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
  const resolvePivot = () => {
    if (typeof window === "undefined") return defaultValue || values[0];
    const params = new URLSearchParams(window.location.search);
    const requested = params.get("pivots");
    if (requested) {
      const requestedIds = requested.split(",").map(value => value.trim()).filter(Boolean);
      const match = requestedIds.find(id => values.includes(id));
      if (match) return match;
    }
    const hash = window.location.hash.replace(/^#/, "");
    if (hash) {
      const match = options.find(option => option.id === hash || slugify(option.title) === hash);
      if (match) return match.id;
    }
    try {
      const stored = window.localStorage.getItem(`foundry-zone-pivot:${group}`);
      if (values.includes(stored)) return stored;
    } catch {
      return defaultValue || values[0];
    }
    return defaultValue || values[0];
  };
  const publishPivotChange = value => {
    if (typeof window === "undefined") return;
    window.dispatchEvent(new CustomEvent("foundry-zone-pivot-change", {
      detail: {
        group,
        value
      }
    }));
  };
  const syncTableOfContents = () => {
    if (typeof window === "undefined") return;
    window.requestAnimationFrame(() => {
      const toc = document.getElementById("table-of-contents-content");
      if (!toc) return;
      const links = Array.from(toc.querySelectorAll('a[href^="#"]'));
      for (const link of links) {
        const item = link.closest("li");
        const rawId = link.getAttribute("href")?.slice(1);
        if (!item || !rawId) continue;
        let id = rawId;
        try {
          id = decodeURIComponent(rawId);
        } catch {}
        item.style.display = document.getElementById(id) ? "" : "none";
      }
    });
  };
  useEffect(() => {
    const resolvedPivot = resolvePivot();
    setActivePivot(resolvedPivot);
    publishPivotChange(resolvedPivot);
    window.setTimeout(syncTableOfContents, 0);
  }, [group, defaultValue, values.join("|"), optionKey]);
  const selectPivot = value => {
    setActivePivot(value);
    if (typeof window !== "undefined") {
      try {
        window.localStorage.setItem(`foundry-zone-pivot:${group}`, value);
      } catch {}
      const url = new URL(window.location.href);
      const current = url.searchParams.get("pivots");
      const preserved = current ? current.split(",").map(id => id.trim()).filter(id => id && !values.includes(id)) : [];
      url.searchParams.set("pivots", [...preserved, value].join(","));
      window.history.replaceState(null, "", `${url.pathname}${url.search}${url.hash}`);
    }
    publishPivotChange(value);
    window.setTimeout(syncTableOfContents, 0);
  };
  if (options.length < 2) return null;
  return <div className="not-prose my-6 border-b border-slate-200 pb-3 dark:border-slate-800">
      <div className="mb-2 text-xs font-semibold uppercase tracking-wide text-slate-500 dark:text-slate-400">
        {label}
      </div>
      <div className="flex flex-wrap gap-2" role="tablist" aria-label={label}>
        {options.map(option => {
    const selected = option.id === activePivot;
    return <button key={option.id} type="button" role="tab" aria-selected={selected} onClick={() => selectPivot(option.id)} className={`rounded-md border px-3 py-1.5 text-sm font-medium transition ${selected ? "border-slate-900 bg-slate-900 text-white shadow-sm dark:border-slate-100 dark:bg-slate-100 dark:text-slate-950" : "border-slate-200 bg-white text-slate-700 hover:border-slate-400 hover:text-slate-950 dark:border-slate-700 dark:bg-slate-950 dark:text-slate-200 dark:hover:border-slate-500"}`}>
              {option.title}
            </button>;
  })}
      </div>
    </div>;
};

export const ZoneContent = ({group, value, options = [], values = [], defaultValue, children}) => {
  const optionKey = options.map(option => `${option.id}:${option.title}`).join("|");
  const [activePivot, setActivePivot] = useState(defaultValue || values[0]);
  const slugify = value => value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "");
  const resolvePivot = () => {
    if (typeof window === "undefined") return defaultValue || values[0];
    const params = new URLSearchParams(window.location.search);
    const requested = params.get("pivots");
    if (requested) {
      const requestedIds = requested.split(",").map(value => value.trim()).filter(Boolean);
      const match = requestedIds.find(id => values.includes(id));
      if (match) return match;
    }
    const hash = window.location.hash.replace(/^#/, "");
    if (hash) {
      const match = options.find(option => option.id === hash || slugify(option.title) === hash);
      if (match) return match.id;
    }
    try {
      const stored = window.localStorage.getItem(`foundry-zone-pivot:${group}`);
      if (values.includes(stored)) return stored;
    } catch {
      return defaultValue || values[0];
    }
    return defaultValue || values[0];
  };
  useEffect(() => {
    setActivePivot(resolvePivot());
  }, [group, defaultValue, values.join("|"), optionKey]);
  useEffect(() => {
    const onPivotChange = event => {
      if (event.detail?.group === group && values.includes(event.detail.value)) {
        setActivePivot(event.detail.value);
      }
    };
    window.addEventListener("foundry-zone-pivot-change", onPivotChange);
    return () => window.removeEventListener("foundry-zone-pivot-change", onPivotChange);
  }, [group, values.join("|")]);
  if (activePivot !== value) return null;
  return <>{children}</>;
};

In this quickstart, you transcribe speech to text using the [Azure OpenAI Whisper model](../../../ai-services/speech-service/whisper-overview). The Whisper model can transcribe human speech in numerous languages and translate other languages into English.

<Tip>
  This quickstart takes approximately 10-15 minutes to complete.
</Tip>

<ZonePivot group="programming-language-dotnet__programming-language-javascript__programming-language-powershell__programming-language-python__programming-language-typescript__rest-api" options={[{"id": "rest-api", "title": "REST API"}, {"id": "programming-language-python", "title": "Python"}, {"id": "programming-language-dotnet", "title": "C#"}, {"id": "programming-language-javascript", "title": "JavaScript"}, {"id": "programming-language-typescript", "title": "TypeScript"}, {"id": "programming-language-powershell", "title": "PowerShell"}]} defaultValue="rest-api" />

<ZoneContent group="programming-language-dotnet__programming-language-javascript__programming-language-powershell__programming-language-python__programming-language-typescript__rest-api" value="rest-api" options={[{"id": "rest-api", "title": "REST API"}, {"id": "programming-language-python", "title": "Python"}, {"id": "programming-language-dotnet", "title": "C#"}, {"id": "programming-language-javascript", "title": "JavaScript"}, {"id": "programming-language-typescript", "title": "TypeScript"}, {"id": "programming-language-powershell", "title": "PowerShell"}]} values={["rest-api", "programming-language-python", "programming-language-dotnet", "programming-language-javascript", "programming-language-typescript", "programming-language-powershell"]} defaultValue="rest-api">
  ## Prerequisites

  * An Azure subscription - [Create one for free](https://azure.microsoft.com/pricing/purchase-options/azure-account?cid=msft_learn).
  * An Azure OpenAI resource with a speech to text model deployed in a [supported region](../../foundry-models/concepts/models-sold-directly-by-azure). For more information, see [Create a resource and deploy a model with Azure OpenAI](https://learn.microsoft.com/en-us/azure/foundry-classic/openai/how-to/create-resource).
  * Be sure that you are assigned at least the [Cognitive Services Contributor](https://learn.microsoft.com/en-us/azure/foundry-classic/openai/how-to/role-based-access-control#cognitive-services-contributor) role for the Azure OpenAI resource.
  * A sample audio file. You can get sample audio, such as *wikipediaOcelot.wav*, from the [Azure Speech in Foundry Tools SDK repository at GitHub](https://github.com/Azure-Samples/cognitive-services-speech-sdk/tree/master/sampledata/audiofiles).

  ## Setup

  ### Retrieve key and endpoint

  To successfully make a call against Azure OpenAI, you need an *endpoint* and a *key*.

  | Variable name           | Value                                                                                                                                                                                                                                                                                          |
  | ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
  | `AZURE_OPENAI_ENDPOINT` | The service endpoint can be found in the **Keys & Endpoint** section when examining your resource from the Azure portal. Alternatively, you can find the endpoint via the **Deployments** page in Microsoft Foundry portal. An example endpoint is: `https://docs-test-001.openai.azure.com/`. |
  | `AZURE_OPENAI_API_KEY`  | This value can be found in the **Keys & Endpoint** section when examining your resource from the Azure portal. You can use either `KEY1` or `KEY2`.                                                                                                                                            |

  Go to your resource in the Azure portal. The **Endpoint and Keys** can be found in the **Resource Management** section. Copy your endpoint and access key as you need both for authenticating your API calls. You can use either `KEY1` or `KEY2`. Always having two keys allows you to securely rotate and regenerate keys without causing a service disruption.

  <Frame>
    <img src="https://mintcdn.com/hobbyist-e43fa225/GyZK-7AhMNNNRP9N/images/endpoint.png?fit=max&auto=format&n=GyZK-7AhMNNNRP9N&q=85&s=f149c0fce072f6a86bc6ff5e05ddebf5" alt="Screenshot of the overview UI for an Azure OpenAI resource in the Azure portal with the endpoint & access keys location circled in red." width="1270" height="667" data-path="images/endpoint.png" />
  </Frame>

  ### Environment variables

  Create and assign persistent environment variables for your key and endpoint.

  <CodeGroup>
    ```CMD Command Line theme={null}
        setx AZURE_OPENAI_API_KEY "REPLACE_WITH_YOUR_KEY_VALUE_HERE" 
    ```

    ```CMD Command Line theme={null}
        setx AZURE_OPENAI_ENDPOINT "REPLACE_WITH_YOUR_ENDPOINT_HERE" 
    ```

    ```powershell PowerShell theme={null}
        [System.Environment]::SetEnvironmentVariable('AZURE_OPENAI_API_KEY', 'REPLACE_WITH_YOUR_KEY_VALUE_HERE', 'User')
    ```

    ```powershell PowerShell theme={null}
        [System.Environment]::SetEnvironmentVariable('AZURE_OPENAI_ENDPOINT', 'REPLACE_WITH_YOUR_ENDPOINT_HERE', 'User')
    ```

    ```Bash Bash theme={null}
        echo export AZURE_OPENAI_API_KEY="REPLACE_WITH_YOUR_KEY_VALUE_HERE" >> /etc/environment && source /etc/environment
    ```

    ```Bash Bash theme={null}
        echo export AZURE_OPENAI_ENDPOINT="REPLACE_WITH_YOUR_ENDPOINT_HERE" >> /etc/environment && source /etc/environment
    ```
  </CodeGroup>

  ## Create a REST API request and response

  In a bash shell, run the following command. You need to replace `YourDeploymentName` with the deployment name you chose when you deployed the Whisper model. The deployment name isn't necessarily the same as the model name. Entering the model name results in an error unless you chose a deployment name that's identical to the underlying model name.

  ```bash theme={null}
  curl $AZURE_OPENAI_ENDPOINT/openai/deployments/YourDeploymentName/audio/transcriptions?api-version=2024-02-01 \
   -H "api-key: $AZURE_OPENAI_API_KEY" \
   -H "Content-Type: multipart/form-data" \
   -F file="@./wikipediaOcelot.wav"
  ```

  The first line of the preceding command with an example endpoint would appear as follows:

  ```bash theme={null}
  curl https://aoai-docs.openai.azure.com/openai/deployments/{YourDeploymentName}/audio/transcriptions?api-version=2024-02-01 \
  ```

  <Info>
    For production, store and access your credentials using a secure method, such as [Azure Key Vault](https://learn.microsoft.com/azure/key-vault/general/overview). For more information, see [credential security](../../../ai-services/security-features).
  </Info>

  ## Verify the output

  The response contains a `text` field with the complete transcription of your audio file. You should see output similar to the example below. If you encounter errors:

  * Verify your deployment name matches exactly
  * Check that your audio file path is correct
  * Ensure your API key and endpoint are valid

  ## Output

  ```bash theme={null}
  {"text":"The ocelot, Lepardus paradalis, is a small wild cat native to the southwestern United States, Mexico, and Central and South America. This medium-sized cat is characterized by solid black spots and streaks on its coat, round ears, and white neck and undersides. It weighs between 8 and 15.5 kilograms, 18 and 34 pounds, and reaches 40 to 50 centimeters 16 to 20 inches at the shoulders. It was first described by Carl Linnaeus in 1758. Two subspecies are recognized, L. p. paradalis and L. p. mitis. Typically active during twilight and at night, the ocelot tends to be solitary and territorial. It is efficient at climbing, leaping, and swimming. It preys on small terrestrial mammals such as armadillo, opossum, and lagomorphs."}
  ```
</ZoneContent>

<ZoneContent group="programming-language-dotnet__programming-language-javascript__programming-language-powershell__programming-language-python__programming-language-typescript__rest-api" value="programming-language-python" options={[{"id": "rest-api", "title": "REST API"}, {"id": "programming-language-python", "title": "Python"}, {"id": "programming-language-dotnet", "title": "C#"}, {"id": "programming-language-javascript", "title": "JavaScript"}, {"id": "programming-language-typescript", "title": "TypeScript"}, {"id": "programming-language-powershell", "title": "PowerShell"}]} values={["rest-api", "programming-language-python", "programming-language-dotnet", "programming-language-javascript", "programming-language-typescript", "programming-language-powershell"]} defaultValue="rest-api">
  ## Prerequisites

  * An Azure subscription. You can [create one for free](https://azure.microsoft.com/pricing/purchase-options/azure-account?cid=msft_learn).
  * An Azure OpenAI resource with a speech to text model deployed in a [supported region](../../foundry-models/concepts/models-sold-directly-by-azure). For more information, see [Create a resource and deploy a model with Azure OpenAI](https://learn.microsoft.com/en-us/azure/foundry-classic/openai/how-to/create-resource).
  * [Python 3.8 or later](https://www.python.org)
  * The [Azure CLI](https://learn.microsoft.com/cli/azure/install-azure-cli).
  * A sample audio file. You can get sample audio, such as *wikipediaOcelot.wav*, from the [Azure Speech in Foundry Tools SDK repository at GitHub](https://github.com/Azure-Samples/cognitive-services-speech-sdk/tree/master/sampledata/audiofiles).

  ## Setup

  ### Retrieve key and endpoint

  To successfully make a call against Azure OpenAI, you need an *endpoint* and a *key*.

  | Variable name           | Value                                                                                                                                                                                                                                                                                          |
  | ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
  | `AZURE_OPENAI_ENDPOINT` | The service endpoint can be found in the **Keys & Endpoint** section when examining your resource from the Azure portal. Alternatively, you can find the endpoint via the **Deployments** page in Microsoft Foundry portal. An example endpoint is: `https://docs-test-001.openai.azure.com/`. |
  | `AZURE_OPENAI_API_KEY`  | This value can be found in the **Keys & Endpoint** section when examining your resource from the Azure portal. You can use either `KEY1` or `KEY2`.                                                                                                                                            |

  Go to your resource in the Azure portal. The **Endpoint and Keys** can be found in the **Resource Management** section. Copy your endpoint and access key as you'll need both for authenticating your API calls. You can use either `KEY1` or `KEY2`. Always having two keys allows you to securely rotate and regenerate keys without causing a service disruption.

  <Frame>
    <img src="https://mintcdn.com/hobbyist-e43fa225/GyZK-7AhMNNNRP9N/images/endpoint.png?fit=max&auto=format&n=GyZK-7AhMNNNRP9N&q=85&s=f149c0fce072f6a86bc6ff5e05ddebf5" alt="Screenshot of the overview UI for an Azure OpenAI resource in the Azure portal with the endpoint & access keys location circled in red." width="1270" height="667" data-path="images/endpoint.png" />
  </Frame>

  ### Environment variables

  Create and assign persistent environment variables for your key and endpoint.

  <CodeGroup>
    ```CMD Command Line theme={null}
        setx AZURE_OPENAI_API_KEY "REPLACE_WITH_YOUR_KEY_VALUE_HERE" 
    ```

    ```CMD Command Line theme={null}
        setx AZURE_OPENAI_ENDPOINT "REPLACE_WITH_YOUR_ENDPOINT_HERE"
    ```

    ```powershell PowerShell theme={null}
        [System.Environment]::SetEnvironmentVariable('AZURE_OPENAI_API_KEY', 'REPLACE_WITH_YOUR_KEY_VALUE_HERE', 'User')
    ```

    ```powershell PowerShell theme={null}
        [System.Environment]::SetEnvironmentVariable('AZURE_OPENAI_ENDPOINT', 'REPLACE_WITH_YOUR_ENDPOINT_HERE', 'User')
    ```

    ```Bash Bash theme={null}
        echo export AZURE_OPENAI_API_KEY="REPLACE_WITH_YOUR_KEY_VALUE_HERE" >> /etc/environment && source /etc/environment
    ```

    ```Bash Bash theme={null}
        echo export AZURE_OPENAI_ENDPOINT="REPLACE_WITH_YOUR_ENDPOINT_HERE" >> /etc/environment && source /etc/environment
    ```
  </CodeGroup>

  <Info>
    **Passwordless authentication is recommended**

    For passwordless authentication, you need to:

    1. Use the `azure-identity` package (`pip install azure-identity`).
    2. Assign the `Cognitive Services User` role to your user account. This can be done in the Azure portal under **Access control (IAM)** > **Add role assignment**.
    3. Sign in with the Azure CLI such as `az login`.
  </Info>

  ## Create a Python environment

  Create a new directory for your project and navigate to it from a terminal or command prompt.

  ```Bash theme={null}
  mkdir whisper-quickstart; cd whisper-quickstart
  ```

  Create and activate a virtual environment for this project.

  <CodeGroup>
    ```powershell Windows theme={null}
        python -m venv .venv
        .venv\Scripts\activate
    ```

    ```Bash macOS/Linux theme={null}
        python3 -m venv .venv
        source .venv/bin/activate
    ```
  </CodeGroup>

  Install the OpenAI Python client library with:

  <Tabs>
    <Tab title="OpenAI Python 1.x">
      ```console theme={null}
      pip install openai
      ```
    </Tab>

    <Tab title="OpenAI Python 0.28.1">
      <Note>
        The OpenAI Python library version `0.28.1` is deprecated. We recommend using `1.x`. Consult our [migration guide](https://learn.microsoft.com/en-us/azure/foundry-classic/openai/how-to/migration) for information on moving from `0.28.1` to `1.x`.
      </Note>

      ```console theme={null}
      pip install openai==0.28.1
      ```
    </Tab>
  </Tabs>

  ## Create the Python app

  1. Create a new Python file called *quickstart.py*. Then open it up in your preferred editor or IDE.

  2. Replace the contents of *quickstart.py* with the following code. Modify the code to add your deployment name:

  <CodeGroup>
    ```python OpenAI Python 1.x theme={null}
            import os
            from openai import AzureOpenAI

            client = AzureOpenAI(
                api_key=os.getenv("AZURE_OPENAI_API_KEY"),  
                api_version="2024-02-01",
                azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
            )

            deployment_id = "YOUR-DEPLOYMENT-NAME-HERE" #This will correspond to the custom name you chose for your deployment when you deployed a model."
            audio_test_file = "./wikipediaOcelot.wav"

            result = client.audio.transcriptions.create(
                file=open(audio_test_file, "rb"),            
                model=deployment_id
            )

            print(result)
    ```

    ```python OpenAI Python 0.28.1 theme={null}
            import openai
            import time
            import os

            openai.api_key = os.getenv("AZURE_OPENAI_API_KEY")
            openai.api_base = os.getenv("AZURE_OPENAI_ENDPOINT")  # your endpoint should look like the following https://YOUR_RESOURCE_NAME.openai.azure.com/
            openai.api_type = "azure"
            openai.api_version = "2024-02-01"

            model_name = "whisper"
            deployment_id = "YOUR-DEPLOYMENT-NAME-HERE" #This will correspond to the custom name you chose for your deployment when you deployed a model."
            audio_language="en"

            audio_test_file = "./wikipediaOcelot.wav"

            result = openai.Audio.transcribe(
                        file=open(audio_test_file, "rb"),            
                        model=model_name,
                        deployment_id=deployment_id
                    )

            print(result)
    ```
  </CodeGroup>

  Run the application using the `python` command on your quickstart file:

  ```python theme={null}
  python quickstart.py
  ```

  <Info>
    For production, store and access your credentials using a secure method, such as [Azure Key Vault](https://learn.microsoft.com/azure/key-vault/general/overview). For more information, see [credential security](../../../ai-services/security-features).
  </Info>

  ## Verify the output

  The response contains a `text` field with the complete transcription of your audio file. You should see output similar to the example below. If you encounter errors:

  * Verify your deployment name matches exactly
  * Check that your audio file path is correct
  * Ensure your API key and endpoint are valid

  ## Output

  ```python theme={null}
  {"text":"The ocelot, Lepardus paradalis, is a small wild cat native to the southwestern United States, Mexico, and Central and South America. This medium-sized cat is characterized by solid black spots and streaks on its coat, round ears, and white neck and undersides. It weighs between 8 and 15.5 kilograms, 18 and 34 pounds, and reaches 40 to 50 centimeters 16 to 20 inches at the shoulders. It was first described by Carl Linnaeus in 1758. Two subspecies are recognized, L. p. paradalis and L. p. mitis. Typically active during twilight and at night, the ocelot tends to be solitary and territorial. It is efficient at climbing, leaping, and swimming. It preys on small terrestrial mammals such as armadillo, opossum, and lagomorphs."}
  ```
</ZoneContent>

<ZoneContent group="programming-language-dotnet__programming-language-javascript__programming-language-powershell__programming-language-python__programming-language-typescript__rest-api" value="programming-language-dotnet" options={[{"id": "rest-api", "title": "REST API"}, {"id": "programming-language-python", "title": "Python"}, {"id": "programming-language-dotnet", "title": "C#"}, {"id": "programming-language-javascript", "title": "JavaScript"}, {"id": "programming-language-typescript", "title": "TypeScript"}, {"id": "programming-language-powershell", "title": "PowerShell"}]} values={["rest-api", "programming-language-python", "programming-language-dotnet", "programming-language-javascript", "programming-language-typescript", "programming-language-powershell"]} defaultValue="rest-api">
  ## Prerequisites

  * An Azure subscription. You can [create one for free](https://azure.microsoft.com/pricing/purchase-options/azure-account?cid=msft_learn).
  * An Azure OpenAI resource with a speech to text model deployed in a [supported region](../../foundry-models/concepts/models-sold-directly-by-azure). For more information, see [Create a resource and deploy a model with Azure OpenAI](https://learn.microsoft.com/en-us/azure/foundry-classic/openai/how-to/create-resource).
  * [The .NET 8.0 SDK](https://dotnet.microsoft.com/en-us/download)

  ### Microsoft Entra ID prerequisites

  For the recommended keyless authentication with Microsoft Entra ID, you need to:

  * Install the [Azure CLI](https://learn.microsoft.com/cli/azure/install-azure-cli) used for keyless authentication with Microsoft Entra ID.
  * Assign the `Cognitive Services User` role to your user account. You can assign roles in the Azure portal under **Access control (IAM)** > **Add role assignment**.

  ## Setup

  1. Create a new folder `whisper-quickstart` and go to the quickstart folder with the following command:

     ```shell theme={null}
     mkdir whisper-quickstart && cd whisper-quickstart
     ```

  2. Create a new console application with the following command:

     ```shell theme={null}
     dotnet new console
     ```

  3. Install the [OpenAI .NET client library](https://www.nuget.org/packages/Azure.AI.OpenAI/) with the [dotnet add package](https://learn.microsoft.com/dotnet/core/tools/dotnet-add-package) command:

     ```console theme={null}
     dotnet add package Azure.AI.OpenAI
     ```

  4. For the **recommended** keyless authentication with Microsoft Entra ID, install the [Azure.Identity](https://www.nuget.org/packages/Azure.Identity) package with:

     ```console theme={null}
     dotnet add package Azure.Identity
     ```

  5. For the **recommended** keyless authentication with Microsoft Entra ID, sign in to Azure with the following command:

     ```console theme={null}
     az login
     ```

  ## Retrieve resource information

  You need to retrieve the following information to authenticate your application with your Azure OpenAI resource:

  <Tabs>
    <Tab title="Microsoft Entra ID">
      | Variable name                  | Value                                                                                                                                                                                                     |
      | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
      | `AZURE_OPENAI_ENDPOINT`        | This value can be found in the **Keys and Endpoint** section when examining your resource from the Azure portal.                                                                                          |
      | `AZURE_OPENAI_DEPLOYMENT_NAME` | This value will correspond to the custom name you chose for your deployment when you deployed a model. This value can be found under **Resource Management** > **Model Deployments** in the Azure portal. |

      Learn more about [keyless authentication](https://learn.microsoft.com/azure/ai-services/authentication) and [setting environment variables](https://learn.microsoft.com/azure/ai-services/cognitive-services-environment-variables).
    </Tab>

    <Tab title="API key">
      | Variable name                  | Value                                                                                                                                                                                                     |
      | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
      | `AZURE_OPENAI_ENDPOINT`        | This value can be found in the **Keys and Endpoint** section when examining your resource from the Azure portal.                                                                                          |
      | `AZURE_OPENAI_API_KEY`         | This value can be found in the **Keys and Endpoint** section when examining your resource from the Azure portal. You can use either `KEY1` or `KEY2`.                                                     |
      | `AZURE_OPENAI_DEPLOYMENT_NAME` | This value will correspond to the custom name you chose for your deployment when you deployed a model. This value can be found under **Resource Management** > **Model Deployments** in the Azure portal. |

      Learn more about [finding API keys](https://learn.microsoft.com/azure/ai-services/cognitive-services-environment-variables) and [setting environment variables](https://learn.microsoft.com/azure/ai-services/cognitive-services-environment-variables).
    </Tab>
  </Tabs>

  ## Run the quickstart

  The sample code in this quickstart uses Microsoft Entra ID for the recommended keyless authentication. If you prefer to use an API key, you can replace the `DefaultAzureCredential` object with an `AzureKeyCredential` object.

  <CodeGroup>
    ```csharp Microsoft Entra ID theme={null}
        AzureOpenAIClient openAIClient = new AzureOpenAIClient(new Uri(endpoint), new DefaultAzureCredential()); 
    ```

    ```csharp API key theme={null}
        AzureOpenAIClient openAIClient = new AzureOpenAIClient(new Uri(endpoint), new AzureKeyCredential(key));
    ```
  </CodeGroup>

  <Note>
    You can get sample audio files, such as *wikipediaOcelot.wav*, from the [Azure Speech in Foundry Tools SDK repository at GitHub](https://github.com/Azure-Samples/cognitive-services-speech-sdk/tree/master/sampledata/audiofiles).
  </Note>

  To run the quickstart, follow these steps:

  1. Replace the contents of `Program.cs` with the following code and update the placeholder values with your own.

     ```csharp theme={null}
     using Azure;
     using Azure.AI.OpenAI;
     using Azure.Identity; // Required for Passwordless auth


     string deploymentName = "whisper";

     string endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? "https://<your-resource-name>.openai.azure.com/";
     string key = Environment.GetEnvironmentVariable("AZURE_OPENAI_API_KEY") ?? "<your-key>";

     // Use the recommended keyless credential instead of the AzureKeyCredential credential.
     AzureOpenAIClient openAIClient = new AzureOpenAIClient(new Uri(endpoint), new DefaultAzureCredential()); 
     //AzureOpenAIClient openAIClient = new AzureOpenAIClient(new Uri(endpoint), new AzureKeyCredential(key));

     var audioFilePath = "<audio file path>"

     var audioClient = openAIClient.GetAudioClient(deploymentName);

     var result = await audioClient.TranscribeAudioAsync(audioFilePath);

     Console.WriteLine("Transcribed text:");
     foreach (var item in result.Value.Text)
     {
         Console.Write(item);
     }
     ```

  2. Run the application using the `dotnet run` command or the run button at the top of Visual Studio:

     ```dotnetcli theme={null}
     dotnet run
     ```

  ## Verify the output

  The transcription returns a response with a `Text` property containing the complete transcription of your audio file. You should see output similar to the example below. If you encounter errors:

  * Verify your deployment name matches exactly
  * Check that your audio file path is correct
  * Ensure your API key and endpoint are valid

  ## Output

  If you are using the sample audio file, you should see the following text printed out in the console:

  ```text theme={null}
  The ocelot, Lepardus paradalis, is a small wild cat native to the southwestern United States, 
  Mexico, and Central and South America. This medium-sized cat is characterized by solid 
  black spots and streaks on its coat, round ears...
  ```
</ZoneContent>

<ZoneContent group="programming-language-dotnet__programming-language-javascript__programming-language-powershell__programming-language-python__programming-language-typescript__rest-api" value="programming-language-javascript" options={[{"id": "rest-api", "title": "REST API"}, {"id": "programming-language-python", "title": "Python"}, {"id": "programming-language-dotnet", "title": "C#"}, {"id": "programming-language-javascript", "title": "JavaScript"}, {"id": "programming-language-typescript", "title": "TypeScript"}, {"id": "programming-language-powershell", "title": "PowerShell"}]} values={["rest-api", "programming-language-python", "programming-language-dotnet", "programming-language-javascript", "programming-language-typescript", "programming-language-powershell"]} defaultValue="rest-api">
  [Source code](https://github.com/openai/openai-node) | [Package (npm)](https://www.npmjs.com/package/openai) | [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/openai/openai/samples)

  ## Prerequisites

  * An Azure subscription - [Create one for free](https://azure.microsoft.com/pricing/purchase-options/azure-account?cid=msft_learn)
  * [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)
  * [Azure CLI](https://learn.microsoft.com/cli/azure/install-azure-cli) used for passwordless authentication in a local development environment, create the necessary context by signing in with the Azure CLI.
  * An Azure OpenAI resource with a speech to text model deployed in a [supported region](../../foundry-models/concepts/models-sold-directly-by-azure). For more information, see [Create a resource and deploy a model with Azure OpenAI](https://learn.microsoft.com/en-us/azure/foundry-classic/openai/how-to/create-resource).

  ### Microsoft Entra ID prerequisites

  For the recommended keyless authentication with Microsoft Entra ID, you need to:

  * Install the [Azure CLI](https://learn.microsoft.com/cli/azure/install-azure-cli) used for keyless authentication with Microsoft Entra ID.
  * Assign the `Cognitive Services User` role to your user account. You can assign roles in the Azure portal under **Access control (IAM)** > **Add role assignment**.

  ## Setup

  1. Create a new folder `synthesis-quickstart` and go to the quickstart folder with the following command:

     ```shell theme={null}
     mkdir synthesis-quickstart && cd synthesis-quickstart
     ```

  2. Create the `package.json` with the following command:

     ```shell theme={null}
     npm init -y
     ```

  3. Install the OpenAI client library for JavaScript with:

     ```console theme={null}
     npm install openai
     ```

  4. For the **recommended** passwordless authentication:

     ```console theme={null}
     npm install @azure/identity
     ```

  ## Retrieve resource information

  You need to retrieve the following information to authenticate your application with your Azure OpenAI resource:

  <Tabs>
    <Tab title="Microsoft Entra ID">
      | Variable name                  | Value                                                                                                                                                                                                     |
      | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
      | `AZURE_OPENAI_ENDPOINT`        | This value can be found in the **Keys and Endpoint** section when examining your resource from the Azure portal.                                                                                          |
      | `AZURE_OPENAI_DEPLOYMENT_NAME` | This value will correspond to the custom name you chose for your deployment when you deployed a model. This value can be found under **Resource Management** > **Model Deployments** in the Azure portal. |

      Learn more about [keyless authentication](https://learn.microsoft.com/azure/ai-services/authentication) and [setting environment variables](https://learn.microsoft.com/azure/ai-services/cognitive-services-environment-variables).
    </Tab>

    <Tab title="API key">
      | Variable name                  | Value                                                                                                                                                                                                     |
      | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
      | `AZURE_OPENAI_ENDPOINT`        | This value can be found in the **Keys and Endpoint** section when examining your resource from the Azure portal.                                                                                          |
      | `AZURE_OPENAI_API_KEY`         | This value can be found in the **Keys and Endpoint** section when examining your resource from the Azure portal. You can use either `KEY1` or `KEY2`.                                                     |
      | `AZURE_OPENAI_DEPLOYMENT_NAME` | This value will correspond to the custom name you chose for your deployment when you deployed a model. This value can be found under **Resource Management** > **Model Deployments** in the Azure portal. |

      Learn more about [finding API keys](https://learn.microsoft.com/azure/ai-services/cognitive-services-environment-variables) and [setting environment variables](https://learn.microsoft.com/azure/ai-services/cognitive-services-environment-variables).
    </Tab>
  </Tabs>

  <Danger>
    To use the recommended keyless authentication with the SDK, make sure that the `AZURE_OPENAI_API_KEY` environment variable isn't set.
  </Danger>

  ## Create a sample application

  <Tabs>
    <Tab title="Microsoft Entra ID">
      1. Create the `index.js` file with the following code:

         ```javascript theme={null}
         const { createReadStream } = require("fs");
         const { AzureOpenAI } = require("openai");
         const { DefaultAzureCredential, getBearerTokenProvider } = require("@azure/identity");

         // You will need to set these environment variables or edit the following values
         const audioFilePath = "<audio file path>";
         const endpoint = process.env.AZURE_OPENAI_ENDPOINT || "Your endpoint";

         // Required Azure OpenAI deployment name and API version
         const apiVersion = process.env.OPENAI_API_VERSION || "2024-08-01-preview";
         const deploymentName = process.env.AZURE_OPENAI_DEPLOYMENT_NAME || "whisper";

         // keyless authentication    
         const credential = new DefaultAzureCredential();
         const scope = "https://ai.azure.com/.default";
         const azureADTokenProvider = getBearerTokenProvider(credential, scope);

         function getClient() {
           return new AzureOpenAI({
             endpoint,
             azureADTokenProvider,
             apiVersion,
             deployment: deploymentName,
           });
         }

         export async function main() {
           console.log("== Transcribe Audio Sample ==");

           const client = getClient();
           const result = await client.audio.transcriptions.create({
             model: "",
             file: createReadStream(audioFilePath),
           });

           console.log(`Transcription: ${result.text}`);
         }

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

      2. Sign in to Azure with the following command:

         ```shell theme={null}
         az login
         ```

      3. Run the JavaScript file.

         ```shell theme={null}
         node index.js
         ```
    </Tab>

    <Tab title="API key">
      1. Create the `index.js` file with the following code:

         ```javascript theme={null}
         import { createReadStream } from "fs";
         import { AzureOpenAI } from "openai";

         // You will need to set these environment variables or edit the following values
         const audioFilePath = "<audio file path>";
         const endpoint = process.env.AZURE_OPENAI_ENDPOINT || "Your endpoint";
         const apiKey = process.env.AZURE_OPENAI_API_KEY || "Your API key";

         // Required Azure OpenAI deployment name and API version
         const apiVersion = "2024-08-01-preview";
         const deploymentName = "whisper";

         function getClient(): AzureOpenAI {
           return new AzureOpenAI({
             endpoint,
             apiKey,
             apiVersion,
             deployment: deploymentName,
           });
         }

         export async function main() {
           console.log("== Transcribe Audio Sample ==");

           const client = getClient();
           const result = await client.audio.transcriptions.create({
             model: "",
             file: createReadStream(audioFilePath),
           });

           console.log(`Transcription: ${result.text}`);
         }

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

      2. Sign in to Azure with the following command:

         ```shell theme={null}
         az login
         ```

      3. Run the JavaScript file.

         ```shell theme={null}
         node index.js
         ```
    </Tab>
  </Tabs>

  You can get sample audio files, such as *wikipediaOcelot.wav*, from the [Azure Speech in Foundry Tools SDK repository at GitHub](https://github.com/Azure-Samples/cognitive-services-speech-sdk/tree/master/sampledata/audiofiles).

  ## Output

  ```json theme={null}
  {"text":"The ocelot, Lepardus paradalis, is a small wild cat native to the southwestern United States, Mexico, and Central and South America. This medium-sized cat is characterized by solid black spots and streaks on its coat, round ears, and white neck and undersides. It weighs between 8 and 15.5 kilograms, 18 and 34 pounds, and reaches 40 to 50 centimeters 16 to 20 inches at the shoulders. It was first described by Carl Linnaeus in 1758. Two subspecies are recognized, L. p. paradalis and L. p. mitis. Typically active during twilight and at night, the ocelot tends to be solitary and territorial. It is efficient at climbing, leaping, and swimming. It preys on small terrestrial mammals such as armadillo, opossum, and lagomorphs."}
  ```
</ZoneContent>

<ZoneContent group="programming-language-dotnet__programming-language-javascript__programming-language-powershell__programming-language-python__programming-language-typescript__rest-api" value="programming-language-typescript" options={[{"id": "rest-api", "title": "REST API"}, {"id": "programming-language-python", "title": "Python"}, {"id": "programming-language-dotnet", "title": "C#"}, {"id": "programming-language-javascript", "title": "JavaScript"}, {"id": "programming-language-typescript", "title": "TypeScript"}, {"id": "programming-language-powershell", "title": "PowerShell"}]} values={["rest-api", "programming-language-python", "programming-language-dotnet", "programming-language-javascript", "programming-language-typescript", "programming-language-powershell"]} defaultValue="rest-api">
  [Source code](https://github.com/openai/openai-node) | [Package (npm)](https://www.npmjs.com/package/openai) | [Samples](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/openai/openai/samples)

  ## Prerequisites

  * An Azure subscription - [Create one for free](https://azure.microsoft.com/pricing/purchase-options/azure-account?cid=msft_learn)
  * [LTS versions of Node.js](https://github.com/nodejs/release#release-schedule)
  * [TypeScript](https://www.typescriptlang.org/download/)
  * [Azure CLI](https://learn.microsoft.com/cli/azure/install-azure-cli) used for passwordless authentication in a local development environment, create the necessary context by signing in with the Azure CLI.
  * An Azure OpenAI resource with a speech to text model deployed in a [supported region](../../foundry-models/concepts/models-sold-directly-by-azure). For more information, see [Create a resource and deploy a model with Azure OpenAI](https://learn.microsoft.com/en-us/azure/foundry-classic/openai/how-to/create-resource).

  ### Microsoft Entra ID prerequisites

  For the recommended keyless authentication with Microsoft Entra ID, you need to:

  * Install the [Azure CLI](https://learn.microsoft.com/cli/azure/install-azure-cli) used for keyless authentication with Microsoft Entra ID.
  * Assign the `Cognitive Services User` role to your user account. You can assign roles in the Azure portal under **Access control (IAM)** > **Add role assignment**.

  ## Set up

  1. Create a new folder `whisper-quickstart` and go to the quickstart folder with the following command:

     ```shell theme={null}
     mkdir whisper-quickstart && cd whisper-quickstart
     ```

  2. Create the `package.json` with the following command:

     ```shell theme={null}
     npm init -y
     ```

  3. Update the `package.json` to ECMAScript with the following command:

     ```shell theme={null}
     npm pkg set type=module
     ```

  4. Install the OpenAI client library for JavaScript with:

     ```console theme={null}
     npm install openai
     ```

  5. For the **recommended** passwordless authentication:

     ```console theme={null}
     npm install @azure/identity
     ```

  ## Retrieve resource information

  You need to retrieve the following information to authenticate your application with your Azure OpenAI resource:

  <Tabs>
    <Tab title="Microsoft Entra ID">
      | Variable name                  | Value                                                                                                                                                                                                     |
      | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
      | `AZURE_OPENAI_ENDPOINT`        | This value can be found in the **Keys and Endpoint** section when examining your resource from the Azure portal.                                                                                          |
      | `AZURE_OPENAI_DEPLOYMENT_NAME` | This value will correspond to the custom name you chose for your deployment when you deployed a model. This value can be found under **Resource Management** > **Model Deployments** in the Azure portal. |

      Learn more about [keyless authentication](https://learn.microsoft.com/azure/ai-services/authentication) and [setting environment variables](https://learn.microsoft.com/azure/ai-services/cognitive-services-environment-variables).
    </Tab>

    <Tab title="API key">
      | Variable name                  | Value                                                                                                                                                                                                     |
      | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
      | `AZURE_OPENAI_ENDPOINT`        | This value can be found in the **Keys and Endpoint** section when examining your resource from the Azure portal.                                                                                          |
      | `AZURE_OPENAI_API_KEY`         | This value can be found in the **Keys and Endpoint** section when examining your resource from the Azure portal. You can use either `KEY1` or `KEY2`.                                                     |
      | `AZURE_OPENAI_DEPLOYMENT_NAME` | This value will correspond to the custom name you chose for your deployment when you deployed a model. This value can be found under **Resource Management** > **Model Deployments** in the Azure portal. |

      Learn more about [finding API keys](https://learn.microsoft.com/azure/ai-services/cognitive-services-environment-variables) and [setting environment variables](https://learn.microsoft.com/azure/ai-services/cognitive-services-environment-variables).
    </Tab>
  </Tabs>

  <Danger>
    To use the recommended keyless authentication with the SDK, make sure that the `AZURE_OPENAI_API_KEY` environment variable isn't set.
  </Danger>

  ## Create a sample application

  <Tabs>
    <Tab title="Microsoft Entra ID">
      1. Create the `index.ts` file with the following code:

         ```typescript theme={null}
         import { createReadStream } from "fs";
         import { AzureOpenAI } from "openai";
         import { DefaultAzureCredential, getBearerTokenProvider } from "@azure/identity";

         // You will need to set these environment variables or edit the following values
         const audioFilePath = "<audio file path>";
         const endpoint = process.env.AZURE_OPENAI_ENDPOINT || "Your endpoint";

         // Required Azure OpenAI deployment name and API version
         const apiVersion = process.env.OPENAI_API_VERSION || "2024-08-01-preview";
         const deploymentName = process.env.AZURE_OPENAI_DEPLOYMENT_NAME || "whisper";

         // keyless authentication    
         const credential = new DefaultAzureCredential();
         const scope = "https://ai.azure.com/.default";
         const azureADTokenProvider = getBearerTokenProvider(credential, scope);

         function getClient(): AzureOpenAI {
           return new AzureOpenAI({
             endpoint,
             azureADTokenProvider,
             apiVersion,
             deployment: deploymentName,
           });
         }

         export async function main() {
           console.log("== Transcribe Audio Sample ==");

           const client = getClient();
           const result = await client.audio.transcriptions.create({
             model: "",
             file: createReadStream(audioFilePath),
           });

           console.log(`Transcription: ${result.text}`);
         }

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

      2. Create the `tsconfig.json` file to transpile the TypeScript code and copy the following code for ECMAScript.

         ```json theme={null}
         {
             "compilerOptions": {
               "module": "NodeNext",
               "target": "ES2022", // Supports top-level await
               "moduleResolution": "NodeNext",
               "skipLibCheck": true, // Avoid type errors from node_modules
               "strict": true // Enable strict type-checking options
             },
             "include": ["*.ts"]
         }
         ```

      3. Transpile from TypeScript to JavaScript.

         ```shell theme={null}
         tsc
         ```

      4. Sign in to Azure with the following command:

         ```shell theme={null}
         az login
         ```

      5. Run the code with the following command:

         ```shell theme={null}
         node index.js
         ```
    </Tab>

    <Tab title="API key">
      1. Create the `index.ts` file with the following code:

         ```typescript theme={null}
         import { createReadStream } from "fs";
         import { AzureOpenAI } from "openai";

         // You will need to set these environment variables or edit the following values
         const audioFilePath = "<audio file path>";
         const endpoint = process.env.AZURE_OPENAI_ENDPOINT || "Your endpoint";
         const apiKey = process.env.AZURE_OPENAI_API_KEY || "Your API key";

         // Required Azure OpenAI deployment name and API version
         const apiVersion = process.env.OPENAI_API_VERSION || "2024-08-01-preview";
         const deploymentName = process.env.AZURE_OPENAI_DEPLOYMENT_NAME || "whisper";

         function getClient(): AzureOpenAI {
           return new AzureOpenAI({
             endpoint,
             apiKey,
             apiVersion,
             deployment: deploymentName,
           });
         }

         export async function main() {
           console.log("== Transcribe Audio Sample ==");

           const client = getClient();
           const result = await client.audio.transcriptions.create({
             model: "",
             file: createReadStream(audioFilePath),
           });

           console.log(`Transcription: ${result.text}`);
         }

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

      2. Create the `tsconfig.json` file to transpile the TypeScript code and copy the following code for ECMAScript.

         ```json theme={null}
         {
             "compilerOptions": {
               "module": "NodeNext",
               "target": "ES2022", // Supports top-level await
               "moduleResolution": "NodeNext",
               "skipLibCheck": true, // Avoid type errors from node_modules
               "strict": true // Enable strict type-checking options
             },
             "include": ["*.ts"]
         }
         ```

      3. Transpile from TypeScript to JavaScript.

         ```shell theme={null}
         tsc
         ```

      4. Run the code with the following command:

         ```shell theme={null}
         node index.js
         ```
    </Tab>
  </Tabs>

  You can get sample audio files, such as *wikipediaOcelot.wav*, from the [Azure Speech in Foundry Tools SDK repository at GitHub](https://github.com/Azure-Samples/cognitive-services-speech-sdk/tree/master/sampledata/audiofiles).

  ## Output

  ```json theme={null}
  {"text":"The ocelot, Lepardus paradalis, is a small wild cat native to the southwestern United States, Mexico, and Central and South America. This medium-sized cat is characterized by solid black spots and streaks on its coat, round ears, and white neck and undersides. It weighs between 8 and 15.5 kilograms, 18 and 34 pounds, and reaches 40 to 50 centimeters 16 to 20 inches at the shoulders. It was first described by Carl Linnaeus in 1758. Two subspecies are recognized, L. p. paradalis and L. p. mitis. Typically active during twilight and at night, the ocelot tends to be solitary and territorial. It is efficient at climbing, leaping, and swimming. It preys on small terrestrial mammals such as armadillo, opossum, and lagomorphs."}
  ```
</ZoneContent>

<ZoneContent group="programming-language-dotnet__programming-language-javascript__programming-language-powershell__programming-language-python__programming-language-typescript__rest-api" value="programming-language-powershell" options={[{"id": "rest-api", "title": "REST API"}, {"id": "programming-language-python", "title": "Python"}, {"id": "programming-language-dotnet", "title": "C#"}, {"id": "programming-language-javascript", "title": "JavaScript"}, {"id": "programming-language-typescript", "title": "TypeScript"}, {"id": "programming-language-powershell", "title": "PowerShell"}]} values={["rest-api", "programming-language-python", "programming-language-dotnet", "programming-language-javascript", "programming-language-typescript", "programming-language-powershell"]} defaultValue="rest-api">
  ## Prerequisites

  * An Azure subscription - [Create one for free](https://azure.microsoft.com/pricing/purchase-options/azure-account?cid=msft_learn)
  * <a href="https://aka.ms/installpowershell" target="_blank">You can use either the latest version, PowerShell 7, or Windows PowerShell 5.1.</a>
  * An Azure OpenAI resource with a speech to text model deployed in a [supported region](../../foundry-models/concepts/models-sold-directly-by-azure). For more information, see [Create a resource and deploy a model with Azure OpenAI](https://learn.microsoft.com/en-us/azure/foundry-classic/openai/how-to/create-resource).

  ## Set up

  ### Retrieve key and endpoint

  To successfully make a call against Azure OpenAI, you need an *endpoint* and a *key*.

  | Variable name           | Value                                                                                                                                                                                                                                                                                          |
  | ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
  | `AZURE_OPENAI_ENDPOINT` | The service endpoint can be found in the **Keys & Endpoint** section when examining your resource from the Azure portal. Alternatively, you can find the endpoint via the **Deployments** page in Microsoft Foundry portal. An example endpoint is: `https://docs-test-001.openai.azure.com/`. |
  | `AZURE_OPENAI_API_KEY`  | This value can be found in the **Keys & Endpoint** section when examining your resource from the Azure portal. You can use either `KEY1` or `KEY2`.                                                                                                                                            |

  Go to your resource in the Azure portal. The **Endpoint and Keys** can be found in the **Resource Management** section. Copy your endpoint and access key as you'll need both for authenticating your API calls. You can use either `KEY1` or `KEY2`. Always having two keys allows you to securely rotate and regenerate keys without causing a service disruption.

  <Frame>
    <img src="https://mintcdn.com/hobbyist-e43fa225/GyZK-7AhMNNNRP9N/images/endpoint.png?fit=max&auto=format&n=GyZK-7AhMNNNRP9N&q=85&s=f149c0fce072f6a86bc6ff5e05ddebf5" alt="Screenshot of the overview UI for an Azure OpenAI resource in the Azure portal with the endpoint & access keys location circled in red." width="1270" height="667" data-path="images/endpoint.png" />
  </Frame>

  ### Environment variables

  Create and assign persistent environment variables for your key and endpoint.

  <CodeGroup>
    ```CMD Command Line theme={null}
        setx AZURE_OPENAI_API_KEY "REPLACE_WITH_YOUR_KEY_VALUE_HERE" 
    ```

    ```CMD Command Line theme={null}
        setx AZURE_OPENAI_ENDPOINT "REPLACE_WITH_YOUR_ENDPOINT_HERE" 
    ```

    ```powershell PowerShell theme={null}
        [System.Environment]::SetEnvironmentVariable('AZURE_OPENAI_API_KEY', 'REPLACE_WITH_YOUR_KEY_VALUE_HERE', 'User')
    ```

    ```powershell PowerShell theme={null}
        [System.Environment]::SetEnvironmentVariable('AZURE_OPENAI_ENDPOINT', 'REPLACE_WITH_YOUR_ENDPOINT_HERE', 'User')
    ```

    ```Bash Bash theme={null}
        echo export AZURE_OPENAI_API_KEY="REPLACE_WITH_YOUR_KEY_VALUE_HERE" >> /etc/environment && source /etc/environment
    ```

    ```Bash Bash theme={null}
        echo export AZURE_OPENAI_ENDPOINT="REPLACE_WITH_YOUR_ENDPOINT_HERE" >> /etc/environment && source /etc/environment
    ```
  </CodeGroup>

  ## Create a PowerShell app

  Run the following command. You need to replace `YourDeploymentName` with the deployment name you chose when you deployed the Whisper model. The deployment name isn't necessarily the same as the model name. Entering the model name results in an error unless you chose a deployment name that is identical to the underlying model name.

  ```powershell-interactive theme={null}
  # Azure OpenAI metadata variables
  $openai = @{
      api_key     = $Env:AZURE_OPENAI_API_KEY
      api_base    = $Env:AZURE_OPENAI_ENDPOINT # your endpoint should look like the following https://YOUR_RESOURCE_NAME.openai.azure.com/
      api_version = '2024-02-01' # this may change in the future
      name        = 'YourDeploymentName' #This will correspond to the custom name you chose for your deployment when you deployed a model.
  }

  # Header for authentication
  $headers = [ordered]@{
      'api-key' = $openai.api_key
  }

  $form = @{ file = get-item -path './wikipediaOcelot.wav' }

  # Send a completion call to generate an answer
  $url = "$($openai.api_base)/openai/deployments/$($openai.name)/audio/transcriptions?api-version=$($openai.api_version)"

  $response = Invoke-RestMethod -Uri $url -Headers $headers -Form $form -Method Post -ContentType 'multipart/form-data'
  return $response.text
  ```

  You can get sample audio files, such as *wikipediaOcelot.wav*, from the [Azure Speech in Foundry Tools SDK repository at GitHub](https://github.com/Azure-Samples/cognitive-services-speech-sdk/tree/master/sampledata/audiofiles).

  <Info>
    For production, store and access your credentials using a secure method, such as [The PowerShell Secret Management with Azure Key Vault](/powershell/utility-modules/secretmanagement/how-to/using-azure-keyvault). For more information, see [credential security](../../../ai-services/security-features).
  </Info>

  ## Output

  ```text theme={null}
  The ocelot, Lepardus paradalis, is a small wild cat native to the southwestern United States, Mexico, and Central and South America. This medium-sized cat is characterized by solid black spots and streaks on its coat, round ears, and white neck and undersides. It weighs between 8 and 15.5 kilograms, 18 and 34 pounds, and reaches 40 to 50 centimeters 16 to 20 inches at the shoulders. It was first described by Carl Linnaeus in 1758. Two subspecies are recognized, L. p. paradalis and L. p. mitis. Typically active during twilight and at night, the ocelot tends to be solitary and territorial. It is efficient at climbing, leaping, and swimming. It preys on small terrestrial mammals such as armadillo, opossum, and lagomorphs.
  ```
</ZoneContent>

<Note>
  For information about other audio models that you can use with Azure OpenAI, see [Audio models](../../foundry-models/concepts/models-sold-directly-by-azure).
</Note>

<Tip>
  The file size limit for the Whisper model is 25 MB. If you need to transcribe a file larger than 25 MB, you can use the Azure Speech in Foundry Tools [batch transcription](../../../ai-services/speech-service/batch-transcription-create#use-a-whisper-model) API.
</Tip>

## Troubleshooting

### Authentication errors

If you receive 401 Unauthorized errors, verify:

* Your API key is correctly set in environment variables
* Your Azure OpenAI resource is active
* Your account has the Cognitive Services Contributor role

### File format errors

The Whisper model supports mp3, mp4, mpeg, mpga, m4a, wav, and webm formats. Other formats return an error.

### File size limit

Audio files must be 25 MB or smaller. For larger files, use the [Azure Speech batch transcription API](../../../ai-services/speech-service/batch-transcription-create#use-a-whisper-model).

### Deployment not found

Verify your deployment name matches exactly what you created in Azure OpenAI Studio. Deployment names are case-sensitive.

## Clean up resources

If you want to clean up and remove an Azure OpenAI resource, you can delete the resource. Before deleting the resource, you must first delete any deployed models.

* [Azure portal](../../../ai-services/multi-service-resource)
* [Azure CLI](../../../ai-services/multi-service-resource)

## Next steps

* To learn how to convert audio data to text in batches, see [Create a batch transcription](../../../ai-services/speech-service/batch-transcription-create).
* For more examples, check out the [Azure OpenAI Samples GitHub repository](https://github.com/Azure-Samples/openai).
