
Azure OpenAI API 的调用需要一个 API 密钥,这个密钥可以在 Azure 门户中找到。
我们可以使用 Azure CLI 或 Azure 门户来配置 OpenAI API 的调用。
Azure OpenAI API调用前置条件
Before you can start calling the Azure OpenAI API, you need to meet a few prerequisites. To begin with, you'll need an Azure subscription, which you can create for free.
You'll also need to have deployed an Azure OpenAI service resource with either the gpt-4o or gpt-4o-mini model. The standard or global standard model deployment type is recommended for initial exploration, but you can check the resource deployment guide for more details.
Curious to learn more? Check out: Azure Openai Completions Playground for Gpt-4o
先决条件
Before you start exploring the Azure OpenAI API, you'll need to meet a few prerequisites.
First and foremost, you'll need an Azure subscription, which you can get for free.
To deploy the Azure OpenAI service resource, you'll need to have either the gpt-4o or gpt-4o-mini model deployed. It's recommended to start with the standard or global standard model deployment type for initial exploration.
Header
To use the Azure OpenAI API, you need to have a subscription to Azure and an Azure OpenAI resource.
The Azure OpenAI API requires a valid Azure subscription and an Azure OpenAI resource, which can be created in the Azure portal.
To create an Azure OpenAI resource, you need to sign up for an Azure account and then go to the Azure portal to create a new resource.
The Azure OpenAI resource requires a valid Azure subscription, and you need to enable the Azure OpenAI API in your Azure subscription.
You can find more information about creating an Azure OpenAI resource in the Azure documentation.
To use the Azure OpenAI API, you also need to have a valid Azure OpenAI resource, which can be created in the Azure portal.
The Azure OpenAI API has a limit on the number of requests you can make per second, which is 20 requests per second.
Related reading: Create an Ai Model in My Azure Tenant
获取服务密钥和端点
To get started with Azure OpenAI API calls, you'll first need to obtain your service key and endpoint. Navigate to the "Keys and Endpoint" section under "Resource Management" and obtain the KEY value for later use.
Intriguing read: Azure Openai Endpoint
You'll also need to copy the service endpoint, which can be done by clicking on "View code", switching the setting to "json", copying the code, and then copying the service endpoint.
Writing the key and endpoint into environment variables is a great protective measure, as it enhances security and makes the program easier to maintain. To do this, click on the "Environment" section and add the key and endpoint, setting the type to "secret".
This approach prevents sensitive information from being written directly into the program, protecting the key from unauthorized use or exposure. If you delete the original Azure OpenAI Service and create a new one, you'll only need to change the variables in the environment without modifying any code.
Here's a summary of the steps to obtain your service key and endpoint:
- Navigate to "Keys and Endpoint" under "Resource Management"
- Obtain the KEY value for later use
- Click on "View code", switch the setting to "json", copy the code, and copy the service endpoint
- Write the key and endpoint into environment variables, setting the type to "secret"
创建和配置
To create an Azure OpenAI API call, you first need to create a workspace. This involves choosing a subscription, resource group, workspace name, and region. For now, the only region that supports the ChatGPT dialogue model is the "美东" (Eastern US) region.
To create a workspace, select the subscription, resource group, and workspace name, and then click "Create". Make sure to choose the correct region, as this will affect the functionality of your API call.
Once your workspace is created, you can proceed to configure your API call. This involves setting up parameters such as the endpoint, deployment ID, and API version. The endpoint is the URL of the Azure OpenAI resource, and the deployment ID is the ID of the deployed Whisper model. The API version is also required, which can be set to a specific version of the API.
Here is a summary of the required parameters:
Note: The parameters listed above are required for creating an API call, and are specific to the Azure OpenAI API.
創建工作區
To create a workspace, you need to choose a subscription, resource group, workspace name, and workspace region. The region you choose is important, as it determines which chatGPT dialogue model you'll be using. Currently, only the "美东" (Eastern US) region supports the chatGPT dialogue model, but you can choose other regions like "西歐" (Western Europe) if you don't need the dialogue model.
You'll need to click "創建" (Create) after confirming your selection. Once the workspace is created, you can click "探索" (Explore) to enter the workspace.
The region you choose will affect the models available to you, so make sure to select the one that best fits your needs.
Curious to learn more? Check out: Azure Openai vs Chatgpt
Creating a New Collection in Postman
To create a new collection in Postman, you need to change the GET method to "POST". This is the first step in establishing a new collection.
You can do this by selecting the "raw" option under "Body" and switching "Text" to "JSON" format.
Paste the "Endpoint" and code copied earlier and try sending a "POST" Request.
If you're seeing the HTTP status code return "401 Permission Denied", it's because you haven't provided the Key for the service.
Expand your knowledge: Azure Openai News
Extension Configuration
When creating and configuring Azure OpenAI extensions, it's essential to understand the different configuration options available.
The type of configuration required depends on the specific extension being used. For example, if you're using the Azure OpenAI chat extension, you'll need to specify the type as azureChatExtensionType.
To configure the Azure OpenAI chat extension, you'll need to provide the endpoint and index_name, which are required fields. You can also specify additional parameters such as authentication, top_n_documents, and strictness, but these are optional.
Expand your knowledge: Chat Completion Azure Openai
Here's a summary of the required fields for the Azure OpenAI chat extension configuration:
You can also configure the Azure Search chat extension, which allows you to use Azure Cognitive Search as an Azure OpenAI chat extension. This configuration requires the type field to be set to azureSearchChatExtensionType, and you can also specify additional parameters such as parameters, which is an optional field.
On a similar theme: Azure Search Openai Demo
Ting Lu - Create
To create a Ting Lu, you need to provide the audio file to be transcribed. The audio file should be in a format supported by Azure OpenAI, such as WAV or MP3.
You can specify the language of the input audio using the language parameter, which should be in ISO-639-1 format. This will improve the accuracy of the transcription and reduce the delay.
Here are the parameters you can pass to create a Ting Lu:
Note that the temperature parameter is optional and defaults to 0. If you don't specify it, the model will use a default temperature of 0.
示例体系结构

Let's dive into an example architecture for creating and configuring Azure OpenAI services. The example architecture involves an intelligent application icon, which points to two Azure API Management icons, one of which is a gateway. This is a great way to structure your services.
The intelligent application icon also points to two Azure OpenAI icons, one in each region. This allows for scalability and redundancy.
A batch request arrow from one of the Azure API Management icons points to an Azure Event Hub icon. This is a key component in handling large amounts of data.
On the other hand, the Azure Function icon has an arrow pointing to Azure API Management, marked as "replay batch requests". This shows how the function can interact with the API management service.
The Azure Function icon also has an arrow pointing to the Azure Event Hub, marked as "batch requests". This further emphasizes the importance of event hubs in handling large data sets.
Microsoft Entra ID, Azure Traffic Manager, Application Insights, and Azure Monitor are also part of the architecture, providing additional tools for security, traffic management, and monitoring.
Curious to learn more? Check out: Azure Openai Architecture
Choice Option

The choice option is a crucial setting when creating and configuring your chat completion tool. It determines which tools the model will call, if any.
The default value for the choice option is auto, but it can be set to none if you want the model to generate messages without calling any tools.
If you have specified a specific tool to be used, such as my_function, the model will be forced to call that tool. This option is set using {"type": "function", "function": {"name": "my_function"}}.
The required option is also available, which means the model must call one or more tools.
A fresh viewpoint: Azure Openai Function Calling
Sources
- https://medium.com/@ro5112/how-to-use-postman-to-call-azure-openais-api-a-step-by-step-tutorial-765aec0fba96
- https://learn.microsoft.com/zh-cn/azure/ai-services/openai/chatgpt-quickstart
- https://dev.to/jambochen/lai-azure-xue-xi-openai-san-yong-python-diao-yong-azure-openai-api-5ddn
- https://learn.microsoft.com/zh-cn/azure/ai-services/openai/reference
- https://learn.microsoft.com/zh-cn/azure/architecture/ai-ml/guide/azure-openai-gateway-guide
Featured Images: pexels.com