Azure OpenAI API Service
Available To
Students, Staff
Service Fee

You will receive a monthly free credit of HKD 8.00, which will be automatically recharged on the first day of each month at 8:00am and shared with the usage of HKUST ChatGPT platform. For additional usage, it is available for top-up credit at your own cost.

API Key Subscription

To control access to the Azure OpenAI models, this requires an API key.  This key acts as a unique identifier for each user.  Follow the instructions below to acquire your own API key.  REMEMBER to keep your API key secure and do not share it with others, as it provides access to your account and usage.

  • Navigate to HKUST API Developer Portal Microsoft Azure API Management
    Image
    Thumbnail
  • Sign up with ITSC account
    Image
    Thumbnail
  • Navigate to the Products page from top menu, click on the Azure OpenAI (personal)
    Image
    Thumbnail
  • Input a description, click on the Subscribe button
    Image
    Thumbnail
  • Click Show to display the hidden API key.  Both Primary and Secondary keys will access the OpenAI API
    Image
    Thumbnail

 

API Key Verification

Verify API key access to OpenAI

  • Command line - curl
    • open a terminal or command prompt on your local machine
    • enter the following command
      curl https://hkust.azure-api.net/openai/deployments/gpt-35-turbo/chat/completions?api-version=2024-02-01 \
          -H "Content-Type: application/json" \
          -H "api-key: <YOUR_SUBSCRIPTION KEY>" \
          -d '{"messages": [{"role": "system", "content": "You are an Azure expert."},
                                        {"role": "user", "content": "What is OpenAI ?"}]}'
    • response
      {"id":"chatcmpl-7gOoV5cwgigwIqly7XsK2ZWfpaM8c","object":"chat.completion","created":1690339515,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":"stop","message":{"role":"assistant","content":"OpenAI is an AI research laboratory consisting of various cutting-edge researchers and engineers dedicated to developing advanced artificial intelligence in a safe, responsible, and transparent manner. It was founded in December 2015 by some of the top leaders in technology such as Elon Musk, Sam Altman, Greg Brockman, and Ilya Sutskever. OpenAI works on various AI research projects ranging from natural language processing to robotics and aims to make AI beneficial for everyone. OpenAI is also known for developing advanced language models such as GPT-3."}}],"usage":{"completion_tokens":109,"prompt_tokens":24,"total_tokens":133}}

     

  • Windows - Postman
    • start Postman (Postman API Platform)
    • prepare a POST request to https://hkust.azure-api.net/openai/deployments/gpt-35-turbo/chat/completions?api-version=2024-02-01, and set header and body as follows:
      Image
      Thumbnail
      Image
      Thumbnail
    • send the request to receive a response
      Image
      Thumbnail

 

Use OpenAI Python Library

Use the OpenAI Python library to integrate OpenAI's services into Python applications.

Sample Python code that uses OpenAI Python library version 0.28.1 or older.

Image
Thumbnail

Sample Python code that uses OpenAI Python library version 1.x

Image
Thumbnail

Useful tool to migrate existing code to version 1.x - grit online migration

  • Select Use Azure OpenAI
  • Paste existing code into the left window
  • Validate and test the generated code
Image
Thumbnail

 

Rate Limits

Rate limits are restrictions that the API imposes on the number of times a user or client can access the services within a specific period of time. Currently, the rate limits defined on the API gateway are set at 60 requests per minute.

Recommendation to remain within rate limits

  • Avoid sharp changes in workload and increasing the workload gradually
  • Introduce a delay between requests
  • Implement retry logic in your application

 

Supported OpenAI API Models and Versions
  • API Models
    OpenAI Model name Azure Deployment name Model version Recommended Replacement
    dall-e-2 dall-e 2.0
    gpt-35-turbo gpt-35-turbo 0125
    gpt-35-turbo-16k
    (retiring 2024-10-01)
    gpt-35-turbo-16k 0613 gpt-35-turbo
    gpt-4 gpt-4 0613 gpt-4o
    gpt-4-32k gpt-4-32k 0613 gpt-4o
    gpt-4-turbo gpt-4-turbo turbo-2024-04-09
    gpt-4o gpt-4o 2024-05-13
    text-embedding-ada-002 text-embedding-ada-002 2

     

  • API Versions
    • preview API
      • 2023-06-01-preview
      • 2023-07-01-preview (retiring 2024-07-01)
      • 2023-10-01-preview
      • 2023-12-01-preview (retiring 2024-07-01)
      • 2024-05-01-preview
    • GA API
      • 2023-05-15
      • 2024-02-01
      • 2024-06-01

 

Unsupported Features
  • Stream Response from OpenAI API is currently not supported.

 

Top Up

Once you have depleted your credit, the following response will be returned when you try to access the OpenAI API.  Top up your credit at the OpenAI Credit Purchase System

Image
Thumbnail

 

Reference

Azure OpenAI Service REST API reference

Azure OpenAI Service - Pricing


Learn More

The Azure OpenAI API service is available to offices and departments on chargeback basis.  For further information, please contact cchelp@ust.hk.