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=2023-05-15 \
          -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=2023-05-15, 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
    dall-e-2 dall-e
    gpt-35-turbo gpt-35-turbo
    gpt-35-turbo-16k gpt-35-turbo-16k
    gpt-4 gpt-4
    gpt-4-32k gpt-4-32k
    text-embedding-ada-002 text-embedding-ada-002

     

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

 

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.