In today’s article, we will introduce how to use Postman to call the Azure OpenAI API.
The article will be divided into several stages:
Now let’s dive into the main subject of this tutorial, integrating Azure OpenAI with Postman. Let’s get started!
(1) Go to Azure Portal
(2) Search for “OpenAI” and create a service
Once the service is created,
Next, click on Go to Azure OpenAI Studio
Once the model is confirmed to be usable,
That concludes the Azure part!
Remember to keep the copied data safe for later use
For first-time Postman users,
Adjust the newly created Request
Paste the “Endpoint” and code copied earlier and try sending a “POST” Request
However, you will find that the HTTP status code returns “401 Permission Denied” because we have not provided the Key for the service
So let’s add our API KEY to our Postman requests:
Seeing the HTTP status code display “200 OK,” and getting the content indicates that we have successfully called the Azure OpenAI API!
It’s exciting to successfully call the API, but exposing sensitive keys still feels odd. After all, data security is a serious issue we all need to be cautious about. If it’s leaked, it could lead to confidentiality breaches or significant financial losses.
Next, let’s look at how to enhance security measures to use Postman more securely.
Writing the Key and Endpoint into environment variables is a great protective measure!
{{OPENAI_API_BASE}}/openai/deployments/{{CHATCOMPLETION_MODEL}}/chat/completions?api-version={{OPENAI_API_VERSION}}&api-key={{OPENAI_API_KEY}}
Adopting this approach brings many benefits. It not only enhances security but also makes the program easier to maintain. Firstly, it prevents sensitive information from being written directly into the program, protecting the key from unauthorized use or exposure. Secondly, if we delete the original Azure OpenAI Service and create a new one, we only need to change the variables in the environment without modifying any code. This significantly reduces the complexity of maintenance and improves efficiency.
Now, store your keys in environment variables and add more protection to your programs!
Conclusion
Through this article, we’ve walked step-by-step on how to use Postman to call Azure OpenAI’s API. From basic introductions of API and Postman, to practical operations and security enhancements through Postman’s user-friendly interface, we can easily interact with Azure OpenAI. Storing keys and endpoints in environment variables not only makes our programs safer but also facilitates maintenance.