Retrieves a list of all models currently available through the OpenAI API. Each model object provides basic information including the owner and availability.
from openai import OpenAIclient = OpenAI()# List all available modelsmodels = client.models.list()for model in models: print(f"{model.id} (owned by {model.owned_by})")
def is_model_available(model_id: str) -> bool: models = client.models.list() return any(m.id == model_id for m in models)if is_model_available('gpt-4-turbo'): print("Model is available!")
# The list method returns a SyncPage object that supports iterationmodels_page = client.models.list()# Iterate through all models (handles pagination automatically)for model in models_page: print(model.id)
from openai import AsyncOpenAIclient = AsyncOpenAI()models = client.models.list()# AsyncPaginator supports async iterationasync for model in models: print(model.id)