Get startedGet started for free

Creating embeddings

In this exercise, you'll create your very first embeddings using the OpenAI API. Normally, to interact with the OpenAI API, you would need an OpenAI API key, and creating embeddings would incur a cost. However, you do not need to create or provide an API key in this course.

The <OPENAI_API_TOKEN> placeholder has been provided in the code, which will send valid requests for the exercises in this course. If, at any point in the course, you hit a RateLimitError, pause for a moment and try again.

The OpenAI class from the openai library will be imported for you throughout the course, and after this exercise, the client will be created for you.

This exercise is part of the course

Introduction to Embeddings with the OpenAI API

View Course

Exercise instructions

  • Create an OpenAI client (you can leave the api_key set to the placeholder provided).
  • Create a request to the Embeddings endpoint, passing the text-embedding-3-small model any text you wish.
  • Convert the model response into a dictionary.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Create an OpenAI client
client = ____(api_key="")

# Create a request to obtain embeddings
response = ____

# Convert the response into a dictionary
response_dict = ____
print(response_dict)
Edit and Run Code