models = openai.models.list() for model in models.data: print(model.id) in python

To list and print the IDs of OpenAI models using the OpenAI Python library, you can use the following code:

main.py
import openai

openai.api_key = "YOUR_API_KEY"

models = openai.models.list()

for model in models.data:
    print(model['id'])
128 chars
9 lines

Make sure to replace "YOUR_API_KEY" with your actual OpenAI API key. This code first sets your API key using openai.api_key and then lists the available models using openai.models.list(). It then iterates over each model in the models.data list and prints the ID of each model using print(model['id']).

related categories

gistlibby LogSnag