How to list OpenAI assistants
Quick answer
Use the
OpenAI Python SDK v1 and call client.assistants.list() to retrieve all available OpenAI assistants. This method returns a list of assistant objects with their metadata.PREREQUISITES
Python 3.8+OpenAI API key (free tier works)pip install openai>=1.0
Setup
Install the official OpenAI Python SDK v1 and set your API key as an environment variable.
- Run
pip install openai>=1.0to install the SDK. - Set your API key in your shell environment:
export OPENAI_API_KEY='your_api_key_here'(Linux/macOS) orsetx OPENAI_API_KEY "your_api_key_here"(Windows).
pip install openai>=1.0 Step by step
This example shows how to list all OpenAI assistants using the official Python SDK v1. It prints the assistant IDs and names.
import os
from openai import OpenAI
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
response = client.assistants.list()
for assistant in response.data:
print(f"Assistant ID: {assistant.id}, Name: {assistant.name}") output
Assistant ID: assistant-123, Name: Example Assistant Assistant ID: assistant-456, Name: Support Bot ...
Common variations
- Use different models by specifying
modelparameter when creating assistants. - Use async calls with
asyncioandawaitif your environment supports it. - Filter or paginate assistants if the API supports query parameters.
Troubleshooting
- If you get an authentication error, verify your
OPENAI_API_KEYenvironment variable is set correctly. - If the
assistants.list()method is not found, ensure you have the latestopenaiSDK installed. - Check network connectivity if requests time out.
Key Takeaways
- Use
client.assistants.list()from the OpenAI Python SDK v1 to get all assistants. - Always set your API key securely via environment variables.
- Keep the SDK updated to access the latest assistant management features.