1. Learn
  2. /
  3. Courses
  4. /
  5. Working with the OpenAI API

Exercise

Digging into the response

One of the key skills required to work with APIs is manipulating the JSON response object to extract the desired information. In this exercise, you'll push your Python dictionary and list manipulation skills to the max to extract information from the API response.

You've been provided with a response object from the OpenAI API, where a request containing the prompt, What is the goal of OpenAI? was sent to the Completion endpoint. This response object has been printed for you so you can see and understand its structure.

Instructions 1/3

undefined XP
  • 1
    • Extract the "model" from the response.
  • 2
    • Extract the "total_tokens" value from the response.
  • 3
    • Extract the "text" answer to the prompt from the response.