### Make Example Executable and Run Source: https://github.com/openai/openai-python/blob/main/CONTRIBUTING.md Grant execute permissions to a new example script and then run it against your API. ```sh $ chmod +x examples/.py ``` ```sh $ ./examples/.py ``` -------------------------------- ### Install aiohttp for Async OpenAI Client (Shell) Source: https://github.com/openai/openai-python/blob/main/README.md Install 'aiohttp' to enable improved concurrency performance for the AsyncOpenAI client. This command installs the 'openai' package with the 'aiohttp' extra. ```sh # install from PyPI pip install openai[aiohttp] ``` -------------------------------- ### Install OpenAI Python Library Source: https://github.com/openai/openai-python/blob/main/README.md Use pip to install the OpenAI Python client library from PyPI. ```sh # install from PyPI pip install openai ``` -------------------------------- ### Python Example File Template Source: https://github.com/openai/openai-python/blob/main/CONTRIBUTING.md Template for adding a new Python example file in the `examples/` directory, including the shebang for Rye. ```py # add an example to examples/.py #!/usr/bin/env -S rye run python … ``` -------------------------------- ### Install Development Dependencies with pip Source: https://github.com/openai/openai-python/blob/main/CONTRIBUTING.md Install all development dependencies using pip after setting up a virtual environment manually. ```sh $ pip install -r requirements-dev.lock ``` -------------------------------- ### Install Python Package from Wheel File Source: https://github.com/openai/openai-python/blob/main/CONTRIBUTING.md Install the built Python package efficiently from its generated wheel file. ```sh $ pip install ./path-to-wheel-file.whl ``` -------------------------------- ### Install openai-python from Git via SSH Source: https://github.com/openai/openai-python/blob/main/CONTRIBUTING.md Install the openai-python library directly from the GitHub repository using pip and SSH. ```sh $ pip install git+ssh://git@github.com/openai/openai-python.git ``` -------------------------------- ### get /models Source: https://github.com/openai/openai-python/blob/main/api.md Lists all available models. ```APIDOC ## GET /models ### Description Lists all available models. ### Method GET ### Endpoint /models ### Parameters *No parameters.* ### Response #### Success Response (200) - **SyncPage[Model]** (array) - A list of model objects. ``` -------------------------------- ### Install Bedrock Dependencies for OpenAI Python Source: https://github.com/openai/openai-python/blob/main/README.md Install the optional Bedrock dependencies to enable AWS credential chain and SigV4 authentication for the OpenAI Python library. ```sh pip install 'openai[bedrock]' ``` -------------------------------- ### Start Mock Server for Tests Source: https://github.com/openai/openai-python/blob/main/CONTRIBUTING.md Run the script to set up a mock server, which is required for most tests. ```sh $ ./scripts/mock ``` -------------------------------- ### AsyncOpenAI().responses.create Source: https://github.com/openai/openai-python/blob/main/README.md Demonstrates how to use the asynchronous OpenAI client to create a response, showing the basic setup and an `await` call. ```APIDOC ## AsyncOpenAI().responses.create ### Description This method allows you to asynchronously create a response from the model. It's part of the `AsyncOpenAI` client, designed for non-blocking operations. ### Method `client.responses.create` ### Parameters #### Request Body - **model** (string) - Required - The ID of the model to use (e.g., "gpt-5.5"). - **input** (string) - Required - The text prompt for the model. ### Request Example ```python import os import asyncio from openai import AsyncOpenAI client = AsyncOpenAI( api_key=os.environ.get("OPENAI_API_KEY"), ) async def main() -> None: response = await client.responses.create( model="gpt-5.5", input="Explain disestablishmentarianism to a smart five year old." ) print(response.output_text) asyncio.run(main()) ``` ``` -------------------------------- ### get /fine_tuning/jobs Source: https://github.com/openai/openai-python/blob/main/api.md Lists fine-tuning jobs. ```APIDOC ## GET /fine_tuning/jobs ### Description Lists fine-tuning jobs. ### Method GET ### Endpoint /fine_tuning/jobs ### Parameters #### Query Parameters - **params** (object) - Optional - Parameters for listing fine-tuning jobs. ### Response #### Success Response (200) - **SyncCursorPage[FineTuningJob]** (array) - A list of fine-tuning job objects. ``` -------------------------------- ### get /organization/projects Source: https://github.com/openai/openai-python/blob/main/api.md Lists all projects for the organization, with optional filtering. ```APIDOC ## GET /organization/projects ### Description Lists all projects for the organization, with optional filtering. ### Method GET ### Endpoint /organization/projects ### Parameters #### Query Parameters - **params** (object) - Optional - Parameters for filtering and pagination. ### Response #### Success Response (200) - **SyncConversationCursorPage[Project]** (object) - A paginated list of project objects. ``` -------------------------------- ### get /skills Source: https://github.com/openai/openai-python/blob/main/api.md Lists all available skills, with optional filtering and pagination. ```APIDOC ## GET /skills ### Description Lists all available skills. ### Method GET ### Endpoint /skills ### Parameters #### Query Parameters - **params** (object) - Optional - Parameters for filtering and pagination. ### Response #### Success Response (200) - **SyncCursorPage[Skill]** (object) - A paginated list of skill objects. ``` -------------------------------- ### GET /vector_stores Source: https://github.com/openai/openai-python/blob/main/api.md Lists all available vector stores. ```APIDOC ## GET /vector_stores ### Description Lists all available vector stores. ### Method GET ### Endpoint /vector_stores ### Parameters #### Query Parameters - **params** (object) - Optional - Parameters for filtering and pagination of the list. ### Response #### Success Response (200) - **SyncCursorPage[VectorStore]** (object) - A paginated list of vector store objects. ``` -------------------------------- ### GET /videos Source: https://github.com/openai/openai-python/blob/main/api.md Lists all available video resources, with optional filtering parameters. ```APIDOC ## GET /videos ### Description Lists all available video resources, with optional filtering parameters. ### Method GET ### Endpoint /videos ### Query Parameters - **params** (object) - Optional - Parameters for listing videos. ### Response #### Success Response (200) - **SyncConversationCursorPage[Video]** (object) - A paginated list of video objects. ``` -------------------------------- ### Synchronize Rye Environment with All Features Source: https://github.com/openai/openai-python/blob/main/CONTRIBUTING.md After manually installing Rye, use this command to synchronize the project dependencies and enable all features. ```sh $ rye sync --all-features ``` -------------------------------- ### GET /batches Source: https://github.com/openai/openai-python/blob/main/api.md Lists all batch jobs, with optional filtering and pagination. ```APIDOC ## GET /batches ### Description Lists all batch jobs, with optional filtering and pagination. ### Method GET ### Endpoint /batches ### Parameters #### Query Parameters - **params** (object) - Optional - Parameters for filtering and pagination of batch jobs. ``` -------------------------------- ### get /skills/{skill_id}/versions/{version}/content Source: https://github.com/openai/openai-python/blob/main/api.md Retrieves the binary content for a specific version of a skill. ```APIDOC ## GET /skills/{skill_id}/versions/{version}/content ### Description Retrieves the content of a specific skill version. ### Method GET ### Endpoint /skills/{skill_id}/versions/{version}/content ### Parameters #### Path Parameters - **skill_id** (string) - Required - The ID of the skill. - **version** (string) - Required - The version identifier of the skill. ### Response #### Success Response (200) - **HttpxBinaryResponseContent** (binary) - The binary content of the skill version. ``` -------------------------------- ### client.beta.threads.runs.steps.list Source: https://github.com/openai/openai-python/blob/main/api.md Lists all steps for a run in a thread, allowing pagination and filtering. ```APIDOC ## GET /threads/{thread_id}/runs/{run_id}/steps ### Description Lists all steps for a run in a thread, allowing pagination and filtering. ### Method GET ### Endpoint /threads/{thread_id}/runs/{run_id}/steps ### Parameters #### Path Parameters - **run_id** (string) - Required - The ID of the run to list steps for. - **thread_id** (string) - Required - The ID of the thread to which the run belongs. ### Response #### Success Response (200) - **SyncCursorPage[RunStep]** (object) - A paginated list of RunStep objects. ``` -------------------------------- ### get /skills/{skill_id}/versions Source: https://github.com/openai/openai-python/blob/main/api.md Lists all versions for a specified skill, with optional filtering and pagination. ```APIDOC ## GET /skills/{skill_id}/versions ### Description Lists all versions for a specific skill. ### Method GET ### Endpoint /skills/{skill_id}/versions ### Parameters #### Path Parameters - **skill_id** (string) - Required - The ID of the skill to list versions for. #### Query Parameters - **params** (object) - Optional - Parameters for filtering and pagination. ### Response #### Success Response (200) - **SyncCursorPage[SkillVersion]** (object) - A paginated list of skill version objects. ``` -------------------------------- ### GET /containers Source: https://github.com/openai/openai-python/blob/main/api.md Lists all containers accessible to the user. This method supports pagination and filtering through optional parameters. ```APIDOC ## GET /containers\n\n### Description\nLists all containers accessible to the user. This method supports pagination and filtering through optional parameters.\n\n### Method\nGET\n\n### Endpoint\n/containers\n\n### Parameters\n#### Query Parameters\n- **params** (object) - Optional - Parameters for listing containers, as defined by `container_list_params.py`.\n\n### Response\n#### Success Response (200)\n- **response** (SyncCursorPage[ContainerListResponse]) - A paginated list of container objects. ``` -------------------------------- ### get /evals Source: https://github.com/openai/openai-python/blob/main/api.md Lists all evaluations, with support for pagination and filtering through optional parameters. ```APIDOC ## GET /evals ### Description Lists all evaluations, with support for pagination and filtering. ### Method GET ### Endpoint /evals ### Parameters #### Query Parameters - **params** (object) - Optional - Parameters for filtering and pagination. See `eval_list_params.py` for schema details. ### Response #### Success Response (200) - **response** (SyncCursorPage[EvalListResponse]) - A paginated list of evaluation objects. ``` -------------------------------- ### GET /organization/projects/{project_id}/api_keys Source: https://github.com/openai/openai-python/blob/main/api.md Lists all API keys associated with a specific project. ```APIDOC ## GET /organization/projects/{project_id}/api_keys ### Description Lists all API keys associated with a specific project. ### Method GET ### Endpoint /organization/projects/{project_id}/api_keys ### Parameters #### Path Parameters - **project_id** (string) - Required - The ID of the project. #### Query Parameters - **params** (object) - Optional - Additional parameters for filtering and pagination, as defined in `api_key_list_params.py`. ### Response #### Success Response (200) - **SyncConversationCursorPage[ProjectAPIKey]** (object) - A paginated list of API keys. ``` -------------------------------- ### Check Installed openai-python Version Source: https://github.com/openai/openai-python/blob/main/README.md Use this snippet to programmatically determine the version of the openai-python package currently installed and active in your Python environment. ```python import openai print(openai.__version__) ``` -------------------------------- ### GET /files Source: https://github.com/openai/openai-python/blob/main/api.md Lists all files uploaded by the organization, with optional filtering parameters. ```APIDOC ## GET /files ### Description Lists all files uploaded by the organization. ### Method GET ### Endpoint /files ### Parameters #### Query Parameters - **params** (object) - Optional - Parameters for listing files. ### Response #### Success Response (200) - **SyncCursorPage[FileObject]** (object) - A paginated list of file objects. ``` -------------------------------- ### List Organization Admin API Keys in Python Source: https://github.com/openai/openai-python/blob/main/api.md Get a paginated list of all Admin API Keys associated with the organization. ```python client.admin.organization.admin_api_keys.list(**params) ``` -------------------------------- ### Bootstrap Development Environment with Rye Source: https://github.com/openai/openai-python/blob/main/CONTRIBUTING.md Run this script to automatically provision a Python environment and manage dependencies using Rye. ```sh $ ./scripts/bootstrap ``` -------------------------------- ### AsyncOpenAI().chat.completions.create (with aiohttp) Source: https://github.com/openai/openai-python/blob/main/README.md Demonstrates how to use the asynchronous OpenAI client with `aiohttp` as the HTTP backend to create chat completions. ```APIDOC ## AsyncOpenAI().chat.completions.create (with aiohttp) ### Description This method allows you to asynchronously create chat completions using the `AsyncOpenAI` client configured with `aiohttp` for improved concurrency performance. ### Method `client.chat.completions.create` ### Parameters #### Request Body - **messages** (array) - Required - A list of message objects comprising the conversation. - **role** (string) - Required - The role of the message sender (e.g., "user"). - **content** (string) - Required - The content of the message. - **model** (string) - Required - The ID of the model to use (e.g., "gpt-5.5"). ### Request Example ```python import os import asyncio from openai import DefaultAioHttpClient from openai import AsyncOpenAI async def main() -> None: async with AsyncOpenAI( api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted http_client=DefaultAioHttpClient(), ) as client: chat_completion = await client.chat.completions.create( messages=[ { "role": "user", "content": "Say this is a test", } ], model="gpt-5.5", ) asyncio.run(main()) ``` ``` -------------------------------- ### client.beta.threads.create_and_run Source: https://github.com/openai/openai-python/blob/main/api.md Creates a new thread and immediately initiates a run on it. This combines the thread creation and run initiation steps into a single call, useful for starting a new assistant interaction directly. It accepts parameters for both thread creation and run configuration. ```APIDOC ## POST /threads/runs ### Description Creates a new thread and immediately runs it. ### Method POST ### Endpoint /threads/runs ### Request Body - **params** (object) - Required - Parameters for creating and running the thread, including assistant ID and initial messages. ### Response #### Success Response (200) - **Run** (object) - The run object initiated for the new thread. ``` -------------------------------- ### GET /organization/spend_alerts Source: https://github.com/openai/openai-python/blob/main/api.md Lists all spend alerts for the organization. ```APIDOC ## GET /organization/spend_alerts ### Description Lists all spend alerts for the organization. ### Method GET ### Endpoint /organization/spend_alerts ### Parameters #### Query Parameters - **params** (object) - Optional - Query parameters for filtering and pagination. Refer to `spend_alert_list_params.py` for details. ### Response #### Success Response (200) - **SyncConversationCursorPage[OrganizationSpendAlert]** (object) - A paginated list of spend alert objects. ``` -------------------------------- ### Configure AsyncOpenAI Client with aiohttp Backend (Python) Source: https://github.com/openai/openai-python/blob/main/README.md Use this snippet to instantiate AsyncOpenAI with DefaultAioHttpClient for improved concurrency. Ensure 'aiohttp' is installed before using this configuration. ```python import os import asyncio from openai import DefaultAioHttpClient from openai import AsyncOpenAI async def main() -> None: async with AsyncOpenAI( api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted http_client=DefaultAioHttpClient(), ) as client: chat_completion = await client.chat.completions.create( messages=[ { "role": "user", "content": "Say this is a test" } ], model="gpt-5.5" ) asyncio.run(main()) ``` -------------------------------- ### GET /organization/roles Source: https://github.com/openai/openai-python/blob/main/api.md Lists all roles within the organization. ```APIDOC ## GET /organization/roles ### Description Lists all roles within the organization. ### Method GET ### Endpoint /organization/roles ### Parameters #### Query Parameters - **params** (object) - Optional - Query parameters for filtering and pagination. Refer to `role_list_params.py` for details. ### Response #### Success Response (200) - **SyncNextCursorPage[Role]** (object) - A paginated list of role objects. ``` -------------------------------- ### Execute Project Tests Source: https://github.com/openai/openai-python/blob/main/CONTRIBUTING.md Run the project's test suite after ensuring a mock server is set up. ```sh $ ./scripts/test ``` -------------------------------- ### get /organization/costs Source: https://github.com/openai/openai-python/blob/main/api.md Retrieves cost data for an organization. ```APIDOC ## GET /organization/costs ### Description Retrieves cost data for an organization. ### Method GET ### Endpoint /organization/costs ### Parameters This endpoint accepts various parameters for filtering and pagination, but specific details are not provided in the source. ### Response #### Success Response (200) Returns a UsageCostsResponse object containing the requested cost data. ``` -------------------------------- ### Initialize Legacy BedrockOpenAI Client with AWS Profile Source: https://github.com/openai/openai-python/blob/main/README.md Initialize the legacy `BedrockOpenAI` client, specifying the AWS region and a named profile for authentication. ```py from openai import BedrockOpenAI client = BedrockOpenAI( aws_region="us-west-2", aws_profile="my-profile", ) ``` -------------------------------- ### get /fine_tuning/jobs/{fine_tuning_job_id} Source: https://github.com/openai/openai-python/blob/main/api.md Retrieves a fine-tuning job. ```APIDOC ## GET /fine_tuning/jobs/{fine_tuning_job_id} ### Description Retrieves a fine-tuning job. ### Method GET ### Endpoint /fine_tuning/jobs/{fine_tuning_job_id} ### Parameters #### Path Parameters - **fine_tuning_job_id** (string) - Required - The ID of the fine-tuning job to retrieve. ### Response #### Success Response (200) - **FineTuningJob** (object) - The fine-tuning job object. ``` -------------------------------- ### Create a Container (Python) Source: https://github.com/openai/openai-python/blob/main/api.md Call the `create` method to provision a new container with specified parameters. ```python client.containers.create(**params) -> ContainerCreateResponse ``` -------------------------------- ### Create a Vector Store File Batch Source: https://github.com/openai/openai-python/blob/main/api.md Initiate the creation of a new file batch within a specified vector store using the `create` method. ```python client.vector_stores.file_batches.create(vector_store_id, **params) ``` -------------------------------- ### GET /projects/{project_id}/users/{user_id}/roles Source: https://github.com/openai/openai-python/blob/main/api.md Lists all roles assigned to a user within a project. ```APIDOC ## GET /projects/{project_id}/users/{user_id}/roles ### Description Lists all roles assigned to a user within a project. ### Method GET ### Endpoint /projects/{project_id}/users/{user_id}/roles ### Parameters #### Path Parameters - **user_id** (string) - Required - The ID of the user. - **project_id** (string) - Required - The ID of the project. #### Query Parameters - **params** (object) - Optional - Additional parameters for filtering or pagination. ### Response #### Success Response (200) - **SyncNextCursorPage[RoleListResponse]** (object) - A paginated list of role assignment responses. ``` -------------------------------- ### get /organization/projects/{project_id} Source: https://github.com/openai/openai-python/blob/main/api.md Retrieves a specific project by its ID. ```APIDOC ## GET /organization/projects/{project_id} ### Description Retrieves a specific project by its ID. ### Method GET ### Endpoint /organization/projects/{project_id} ### Parameters #### Path Parameters - **project_id** (string) - Required - The ID of the project to retrieve. ### Response #### Success Response (200) - **Project** (object) - The retrieved project object. ``` -------------------------------- ### Initialize AzureOpenAI Client and Make Chat Completion Request (Python) Source: https://github.com/openai/openai-python/blob/main/README.md Initialize the `AzureOpenAI` client with a specific API version and Azure endpoint, then make a chat completion request using a deployment name as the model. ```python from openai import AzureOpenAI # gets the API Key from environment variable AZURE_OPENAI_API_KEY client = AzureOpenAI( # https://learn.microsoft.com/azure/ai-services/openai/reference#rest-api-versioning api_version="2023-07-01-preview", # https://learn.microsoft.com/azure/cognitive-services/openai/how-to/create-resource?pivots=web-portal#create-a-resource azure_endpoint="https://example-endpoint.openai.azure.com", ) completion = client.chat.completions.create( model="deployment-name", # e.g. gpt-35-instant messages=[ { "role": "user", "content": "How do I output all files in a directory using Python?" } ] ) print(completion.to_json()) ``` -------------------------------- ### GET /assistants Source: https://github.com/openai/openai-python/blob/main/api.md Lists all Assistants, with options for filtering and pagination. This allows you to retrieve a collection of Assistants managed by your account. ```APIDOC ## GET /assistants ### Description Lists all Assistants, with options for filtering and pagination. ### Method GET ### Endpoint /assistants ### Parameters #### Query Parameters - **params** (object) - Optional - Parameters for listing Assistants, such as `limit`, `order`, `after`, or `before` for pagination. ``` -------------------------------- ### get /organization/certificates Source: https://github.com/openai/openai-python/blob/main/api.md Lists all certificates for the organization, with optional filtering. ```APIDOC ## GET /organization/certificates ### Description Lists all certificates for the organization, with optional filtering. ### Method GET ### Endpoint /organization/certificates ### Parameters #### Query Parameters - **params** (object) - Optional - Parameters for filtering and pagination. ### Response #### Success Response (200) - **SyncConversationCursorPage[CertificateListResponse]** (object) - A paginated list of certificate response objects. ``` -------------------------------- ### POST /fine_tuning/alpha/graders/run Source: https://github.com/openai/openai-python/blob/main/api.md Runs a fine-tuning alpha grader. ```APIDOC ## POST /fine_tuning/alpha/graders/run ### Description Runs a fine-tuning alpha grader. ### Method POST ### Endpoint /fine_tuning/alpha/graders/run ### Parameters #### Request Body - **params** (object) - Required - Parameters for running the grader. ### Response #### Success Response (200) - **GraderRunResponse** (object) - The response from running the grader. ``` -------------------------------- ### get /organization/certificates/{certificate_id} Source: https://github.com/openai/openai-python/blob/main/api.md Retrieves a specific certificate by its ID. ```APIDOC ## GET /organization/certificates/{certificate_id} ### Description Retrieves a specific certificate by its ID. ### Method GET ### Endpoint /organization/certificates/{certificate_id} ### Parameters #### Path Parameters - **certificate_id** (string) - Required - The ID of the certificate to retrieve. #### Query Parameters - **params** (object) - Optional - Additional parameters for the request. ### Response #### Success Response (200) - **Certificate** (object) - The retrieved certificate object. ``` -------------------------------- ### client.responses.create (Vision with image URL) Source: https://github.com/openai/openai-python/blob/main/README.md Demonstrates how to use the `client.responses.create` method to process an image from a URL with a text prompt using the Vision model. ```APIDOC ## client.responses.create (Vision with image URL) ### Description This method allows you to send a text prompt and an image URL to the model for analysis. It's used for Vision capabilities, enabling the model to understand and respond based on image content. ### Method `client.responses.create` ### Parameters #### Request Body - **model** (string) - Required - The ID of the model to use (e.g., "gpt-5.5"). - **input** (array) - Required - A list of message objects. - **role** (string) - Required - The role of the message sender, typically "user". - **content** (array) - Required - A list of content parts. - **type** (string) - Required - The type of content, either "input_text" or "input_image". - **text** (string) - Required - (For type "input_text") The text prompt. - **image_url** (string) - Required - (For type "input_image") The URL of the image. ### Request Example ```python prompt = "What is in this image?" img_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/d/d5/2023_06_08_Raccoon1.jpg/1599px-2023_06_08_Raccoon1.jpg" response = client.responses.create( model="gpt-5.5", input=[ { "role": "user", "content": [ {"type": "input_text", "text": prompt}, {"type": "input_image", "image_url": f"{img_url}"}, ], } ], ) ``` ``` -------------------------------- ### GET /organization/roles/{role_id} Source: https://github.com/openai/openai-python/blob/main/api.md Retrieves a specific role by its ID. ```APIDOC ## GET /organization/roles/{role_id} ### Description Retrieves a specific role by its ID. ### Method GET ### Endpoint /organization/roles/{role_id} ### Parameters #### Path Parameters - **role_id** (string) - Required - The unique identifier of the role to retrieve. ### Response #### Success Response (200) - **Role** (object) - The retrieved role object. ``` -------------------------------- ### GET /organization/audit_logs Source: https://github.com/openai/openai-python/blob/main/api.md Retrieves a list of audit logs for the organization. ```APIDOC ## GET /organization/audit_logs ### Description Retrieves a list of audit logs for the organization. ### Method GET ### Endpoint /organization/audit_logs ### Parameters #### Query Parameters - **params** (object) - Optional - Additional query parameters for filtering and pagination. ### Response #### Success Response (200) - **data** (array of AuditLogListResponse) - A list of audit log entries. - **has_next_page** (boolean) - Indicates if there are more pages of results. #### Response Example ```json { "data": [ { "id": "log_123", "event": "user.login", "actor": "user_abc", "timestamp": 1678886400 } ], "has_next_page": false } ``` ``` -------------------------------- ### client.responses.create (Vision with base64 image) Source: https://github.com/openai/openai-python/blob/main/README.md Demonstrates how to use the `client.responses.create` method to process a base64 encoded image with a text prompt using the Vision model. ```APIDOC ## client.responses.create (Vision with base64 image) ### Description This method allows you to send a text prompt and a base64 encoded image string to the model for analysis. It's used for Vision capabilities, enabling the model to understand and respond based on image content. ### Method `client.responses.create` ### Parameters #### Request Body - **model** (string) - Required - The ID of the model to use (e.g., "gpt-5.5"). - **input** (array) - Required - A list of message objects. - **role** (string) - Required - The role of the message sender, typically "user". - **content** (array) - Required - A list of content parts. - **type** (string) - Required - The type of content, either "input_text" or "input_image". - **text** (string) - Required - (For type "input_text") The text prompt. - **image_url** (string) - Required - (For type "input_image") The base64 encoded image string, prefixed with `data:image/;base64,`. ### Request Example ```python import base64 from openai import OpenAI client = OpenAI() prompt = "What is in this image?" with open("path/to/image.png", "rb") as image_file: b64_image = base64.b64encode(image_file.read()).decode("utf-8") response = client.responses.create( model="gpt-5.5", input=[ { "role": "user", "content": [ {"type": "input_text", "text": prompt}, {"type": "input_image", "image_url": f"data:image/png;base64,{b64_image}"}, ], } ], ) ``` ``` -------------------------------- ### Helper Methods for Creating Assistant Streams (Python) Source: https://github.com/openai/openai-python/blob/main/helpers.md The SDK provides several helper methods to initiate different types of Assistant runs and stream their responses. ```python client.beta.threads.runs.stream() ``` ```python client.beta.threads.create_and_run_stream() ``` ```python client.beta.threads.runs.submit_tool_outputs_stream() ``` -------------------------------- ### get /models/{model} Source: https://github.com/openai/openai-python/blob/main/api.md Retrieves information about a specific model. ```APIDOC ## GET /models/{model} ### Description Retrieves information about a specific model. ### Method GET ### Endpoint /models/{model} ### Parameters #### Path Parameters - **model** (string) - Required - The ID of the model to retrieve. ### Response #### Success Response (200) - **Model** (object) - The model object containing details about the requested model. ``` -------------------------------- ### GET /conversations/{conversation_id} Source: https://github.com/openai/openai-python/blob/main/src/openai/resources/conversations/api.md Retrieves a specific conversation by its ID. ```APIDOC ## GET /conversations/{conversation_id} ### Description Retrieves a specific conversation by its ID. ### Method GET ### Endpoint /conversations/{conversation_id} ### Parameters #### Path Parameters - **conversation_id** (string) - Required - The ID of the conversation to retrieve. ### Response #### Success Response (200) - **Conversation** (object) - The retrieved conversation object. ``` -------------------------------- ### Create and Run a Thread in Python Source: https://github.com/openai/openai-python/blob/main/api.md Creates a new thread and immediately runs it, returning a Run object. ```python client.beta.threads.create_and_run(**params) -> Run ``` -------------------------------- ### GET /responses/{response_id} Source: https://github.com/openai/openai-python/blob/main/src/openai/resources/responses/api.md Retrieves a specific response by its ID. ```APIDOC ## GET /responses/{response_id}\n\n### Description\nRetrieves a specific response by its ID.\n\n### Method\nGET\n\n### Endpoint\n/responses/{response_id}\n\n### Parameters\n#### Path Parameters\n- **response_id** (string) - Required - The ID of the response to retrieve.\n\n#### Query Parameters\n- **params** (object) - Optional - Additional parameters for the request.\n\n### Response\n#### Success Response (200)\n- **Response** (object) - The retrieved Response object. ``` -------------------------------- ### Create Assistant in Python Source: https://github.com/openai/openai-python/blob/main/api.md Use this method to create a new Assistant instance with specified parameters. ```python client.beta.assistants.create(**params) ``` -------------------------------- ### GET /videos/characters/{character_id} Source: https://github.com/openai/openai-python/blob/main/api.md Retrieves a specific character by its unique identifier. ```APIDOC ## GET /videos/characters/{character_id} ### Description Retrieves a specific character by its unique identifier. ### Method GET ### Endpoint /videos/characters/{character_id} ### Parameters #### Path Parameters - **character_id** (string) - Required - The unique identifier of the character to retrieve. ### Response #### Success Response (200) - **VideoGetCharacterResponse** (object) - The retrieved character response. ``` -------------------------------- ### Build Python Package Distribution Source: https://github.com/openai/openai-python/blob/main/CONTRIBUTING.md Create distributable `.tar.gz` and `.whl` files for the library using either Rye or the standard Python build module. ```sh $ rye build ``` ```sh $ python -m build ``` -------------------------------- ### Activate Virtual Environment and Run Python Script Source: https://github.com/openai/openai-python/blob/main/CONTRIBUTING.md Activate the project's virtual environment, then run a Python script without the `rye run` prefix. ```sh # Activate the virtual environment - https://docs.python.org/3/library/venv.html#how-venvs-work $ source .venv/bin/activate ``` ```sh # now you can omit the `rye run` prefix $ python script.py ``` -------------------------------- ### get /skills/{skill_id} Source: https://github.com/openai/openai-python/blob/main/api.md Retrieves a specific skill by its unique identifier. ```APIDOC ## GET /skills/{skill_id} ### Description Retrieves a specific skill by its ID. ### Method GET ### Endpoint /skills/{skill_id} ### Parameters #### Path Parameters - **skill_id** (string) - Required - The ID of the skill to retrieve. ### Response #### Success Response (200) - **Skill** (object) - The retrieved skill object. ``` -------------------------------- ### GET /organization/spend_alerts/{alert_id} Source: https://github.com/openai/openai-python/blob/main/api.md Retrieves a specific spend alert by its ID. ```APIDOC ## GET /organization/spend_alerts/{alert_id} ### Description Retrieves a specific spend alert by its ID. ### Method GET ### Endpoint /organization/spend_alerts/{alert_id} ### Parameters #### Path Parameters - **alert_id** (string) - Required - The unique identifier of the spend alert to retrieve. ### Response #### Success Response (200) - **OrganizationSpendAlert** (object) - The retrieved spend alert object. ``` -------------------------------- ### Create Organization Admin API Key in Python Source: https://github.com/openai/openai-python/blob/main/api.md Use the create method to generate a new Admin API Key for the organization. ```python client.admin.organization.admin_api_keys.create(**params) ``` -------------------------------- ### POST /videos Source: https://github.com/openai/openai-python/blob/main/api.md Creates a new video resource with the provided parameters. ```APIDOC ## POST /videos ### Description Creates a new video resource with the provided parameters. ### Method POST ### Endpoint /videos ### Request Body - **params** (object) - Required - Parameters for video creation. ### Response #### Success Response (200) - **Video** (object) - The created video object. ``` -------------------------------- ### GET /organization/data_retention Source: https://github.com/openai/openai-python/blob/main/api.md Retrieves the organization's data retention settings. ```APIDOC ## GET /organization/data_retention ### Description Retrieves the organization's data retention settings. ### Method GET ### Endpoint /organization/data_retention ### Response #### Success Response (200) - **OrganizationDataRetention** (object) - The organization's data retention settings. ``` -------------------------------- ### get /organization/groups Source: https://github.com/openai/openai-python/blob/main/api.md Lists all organization groups, with optional filtering and pagination. ```APIDOC ## GET /organization/groups ### Description Lists all organization groups, with optional filtering and pagination. ### Method GET ### Endpoint /organization/groups ### Parameters #### Query Parameters - **params** (object) - Optional - Parameters for listing groups (refer to `group_list_params.py`). ### Response #### Success Response (200) - **groups** (array of Group) - A list of organization group objects. ``` -------------------------------- ### Create a File in a Container (Python) Source: https://github.com/openai/openai-python/blob/main/api.md Call the `create` method to upload a new file to a specified container. ```python client.containers.files.create(container_id, **params) -> FileCreateResponse ``` -------------------------------- ### get /organization/groups/{group_id} Source: https://github.com/openai/openai-python/blob/main/api.md Retrieves a specific organization group by its ID. ```APIDOC ## GET /organization/groups/{group_id} ### Description Retrieves a specific organization group by its ID. ### Method GET ### Endpoint /organization/groups/{group_id} ### Parameters #### Path Parameters - **group_id** (string) - Required - The ID of the group to retrieve. ### Response #### Success Response (200) - **group** (Group) - The retrieved group object. ``` -------------------------------- ### GET /organization/admin_api_keys Source: https://github.com/openai/openai-python/blob/main/api.md Retrieves a list of admin API keys for the organization. ```APIDOC ## GET /organization/admin_api_keys ### Description Retrieves a list of admin API keys for the organization. ### Method GET ### Endpoint /organization/admin_api_keys ### Parameters #### Query Parameters - **params** (object) - Optional - Additional query parameters for filtering and pagination. ### Response #### Success Response (200) - **data** (array of AdminAPIKey) - A list of admin API key objects. - **has_next_page** (boolean) - Indicates if there are more pages of results. #### Response Example ```json { "data": [ { "id": "admin_key_xyz", "created_at": 1678886400 }, { "id": "admin_key_abc", "created_at": 1678790000 } ], "has_next_page": false } ``` ``` -------------------------------- ### Configure `httpx` Client on a Per-Request Basis Source: https://github.com/openai/openai-python/blob/main/README.md Use `client.with_options()` to apply `httpx` client configurations, such as proxies or transports, for specific requests rather than globally. ```python client.with_options(http_client=DefaultHttpxClient(...)) ``` -------------------------------- ### List Checkpoint Permissions in Python Source: https://github.com/openai/openai-python/blob/main/api.md Use the client to list all permissions associated with a specified fine-tuned model checkpoint. ```python client.fine_tuning.checkpoints.permissions.list(fine_tuned_model_checkpoint, **params) ``` -------------------------------- ### Create and Run a Thread with Streaming in Python Source: https://github.com/openai/openai-python/blob/main/api.md Creates and runs a thread, streaming events back using an AssistantStreamManager. ```python client.beta.threads.create_and_run_stream(*args) -> AssistantStreamManager[AssistantEventHandler] | AssistantStreamManager[AssistantEventHandlerT] ``` -------------------------------- ### GET /vector_stores/{vector_store_id} Source: https://github.com/openai/openai-python/blob/main/api.md Retrieves a specific vector store by ID. ```APIDOC ## GET /vector_stores/{vector_store_id} ### Description Retrieves a specific vector store by ID. ### Method GET ### Endpoint /vector_stores/{vector_store_id} ### Parameters #### Path Parameters - **vector_store_id** (string) - Required - The ID of the vector store to retrieve. ### Response #### Success Response (200) - **VectorStore** (object) - The retrieved vector store object. ``` -------------------------------- ### Handle Assistant Run Step Events (Python) Source: https://github.com/openai/openai-python/blob/main/helpers.md Subscribe to events for the creation, incremental updates (delta), and completion of a RunStep. Useful for tracking the progress of an assistant's execution. ```python def on_run_step_created(self, run_step: RunStep) def on_run_step_delta(self, delta: RunStepDelta, snapshot: RunStep) def on_run_step_done(self, run_step: RunStep) ``` -------------------------------- ### get /fine_tuning/jobs/{fine_tuning_job_id}/checkpoints Source: https://github.com/openai/openai-python/blob/main/api.md Lists checkpoints for a fine-tuning job. ```APIDOC ## GET /fine_tuning/jobs/{fine_tuning_job_id}/checkpoints ### Description Lists checkpoints for a fine-tuning job. ### Method GET ### Endpoint /fine_tuning/jobs/{fine_tuning_job_id}/checkpoints ### Parameters #### Path Parameters - **fine_tuning_job_id** (string) - Required - The ID of the fine-tuning job. #### Query Parameters - **params** (object) - Optional - Parameters for listing checkpoints. ### Response #### Success Response (200) - **SyncCursorPage[FineTuningJobCheckpoint]** (array) - A list of fine-tuning job checkpoint objects. ``` -------------------------------- ### POST /assistants Source: https://github.com/openai/openai-python/blob/main/api.md Creates a new Assistant with specified parameters. This operation allows you to define the Assistant's capabilities, tools, and initial configuration. ```APIDOC ## POST /assistants ### Description Creates a new Assistant with specified parameters. ### Method POST ### Endpoint /assistants ### Request Body - **params** (object) - Required - Parameters for creating an Assistant, including its name, model, instructions, and tools. ``` -------------------------------- ### get /fine_tuning/jobs/{fine_tuning_job_id}/events Source: https://github.com/openai/openai-python/blob/main/api.md Lists events for a fine-tuning job. ```APIDOC ## GET /fine_tuning/jobs/{fine_tuning_job_id}/events ### Description Lists events for a fine-tuning job. ### Method GET ### Endpoint /fine_tuning/jobs/{fine_tuning_job_id}/events ### Parameters #### Path Parameters - **fine_tuning_job_id** (string) - Required - The ID of the fine-tuning job. #### Query Parameters - **params** (object) - Optional - Parameters for listing events. ### Response #### Success Response (200) - **SyncCursorPage[FineTuningJobEvent]** (array) - A list of fine-tuning job event objects. ``` -------------------------------- ### GET /files/{file_id} Source: https://github.com/openai/openai-python/blob/main/api.md Retrieves information about a specific file by its ID. ```APIDOC ## GET /files/{file_id} ### Description Retrieves information about a specific file. ### Method GET ### Endpoint /files/{file_id} ### Parameters #### Path Parameters - **file_id** (string) - Required - The ID of the file to retrieve. ### Response #### Success Response (200) - **FileObject** (object) - The file object. ``` -------------------------------- ### Create and Run a Thread with Polling in Python Source: https://github.com/openai/openai-python/blob/main/api.md Creates and runs a thread, then polls for its completion, returning a Run object. ```python client.beta.threads.create_and_run_poll(*args) -> Run ``` -------------------------------- ### GET /videos/{video_id}/content Source: https://github.com/openai/openai-python/blob/main/api.md Downloads the binary content of a specific video. ```APIDOC ## GET /videos/{video_id}/content ### Description Downloads the binary content of a specific video. ### Method GET ### Endpoint /videos/{video_id}/content ### Parameters #### Path Parameters - **video_id** (string) - Required - The unique identifier of the video whose content is to be downloaded. #### Query Parameters - **params** (object) - Optional - Parameters for downloading video content. ### Response #### Success Response (200) - **HttpxBinaryResponseContent** (binary) - The binary content of the video. ``` -------------------------------- ### Run Code Linting Source: https://github.com/openai/openai-python/blob/main/CONTRIBUTING.md Execute the linting script to check code for style and potential issues using Ruff. ```sh $ ./scripts/lint ``` -------------------------------- ### client.chat.completions.stream() Source: https://github.com/openai/openai-python/blob/main/helpers.md This method wraps the `.chat.completions.create(stream=True)` call, providing a more granular event API and automatic accumulation of deltas. It must be used within a context manager. ```APIDOC ## client.chat.completions.stream() ### Description Initiates a streaming chat completion, providing a granular event API and automatic accumulation of each delta. This method requires usage within a context manager to ensure proper resource management. ### Method Signature `async with client.chat.completions.stream(model: str, messages: list, **kwargs) as stream:` ### Parameters - **model** (string) - Required - The ID of the model to use. - **messages** (list) - Required - A list of messages comprising the conversation so far. ### Usage Example ```python from openai import AsyncOpenAI client = AsyncOpenAI() async with client.chat.completions.stream( model='gpt-4o-2024-08-06', messages=[ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "What is the capital of France?"} ], ) as stream: async for event in stream: if event.type == 'content.delta': print(event.content, flush=True, end='') ``` ### Returns An `AsyncChatCompletionStream` instance (or `ChatCompletionStream` for sync client) which is an async iterator (or iterator) yielding various event types. ``` -------------------------------- ### GET /videos/{video_id} Source: https://github.com/openai/openai-python/blob/main/api.md Retrieves a specific video resource by its unique identifier. ```APIDOC ## GET /videos/{video_id} ### Description Retrieves a specific video resource by its unique identifier. ### Method GET ### Endpoint /videos/{video_id} ### Parameters #### Path Parameters - **video_id** (string) - Required - The unique identifier of the video to retrieve. ### Response #### Success Response (200) - **Video** (object) - The retrieved video object. ``` -------------------------------- ### Manual Asynchronous Pagination with Page Control Methods Source: https://github.com/openai/openai-python/blob/main/README.md This snippet shows how to use has_next_page(), next_page_info(), and get_next_page() for granular control over fetching successive pages. It allows custom logic before requesting the next set of results. ```python first_page = await client.fine_tuning.jobs.list( limit=20, ) if first_page.has_next_page(): print(f"will fetch next page using these details: {first_page.next_page_info()}") next_page = await first_page.get_next_page() print(f"number of items we just fetched: {len(next_page.data)}") # Remove `await` for non-async usage. ``` -------------------------------- ### get /evals/{eval_id} Source: https://github.com/openai/openai-python/blob/main/api.md Retrieves the details of a specific evaluation by its unique identifier. ```APIDOC ## GET /evals/{eval_id} ### Description Retrieves the details of a specific evaluation by its unique identifier. ### Method GET ### Endpoint /evals/{eval_id} ### Parameters #### Path Parameters - **eval_id** (string) - Required - The ID of the evaluation to retrieve. ### Response #### Success Response (200) - **response** (EvalRetrieveResponse) - The retrieved evaluation object. ``` -------------------------------- ### Activate a Certificate for an Organization Project Source: https://github.com/openai/openai-python/blob/main/api.md Activate a specific certificate within an organization project. ```python client.admin.organization.projects.certificates.activate(project_id, **params) -> SyncPage[CertificateActivateResponse] ``` -------------------------------- ### post /organization/projects Source: https://github.com/openai/openai-python/blob/main/api.md Creates a new project for the organization. ```APIDOC ## POST /organization/projects ### Description Creates a new project for the organization. ### Method POST ### Endpoint /organization/projects ### Parameters #### Request Body - **params** (object) - Optional - Parameters for creating the project. ### Response #### Success Response (200) - **Project** (object) - The newly created project object. ``` -------------------------------- ### GET /organization/projects/{project_id}/users Source: https://github.com/openai/openai-python/blob/main/api.md Lists all users associated with a specific project. ```APIDOC ## GET /organization/projects/{project_id}/users ### Description Lists all users associated with a specific project. ### Method GET ### Endpoint /organization/projects/{project_id}/users ### Parameters #### Path Parameters - **project_id** (string) - Required - The ID of the project. #### Query Parameters - **params** (object) - Optional - Additional parameters for filtering or pagination. ### Response #### Success Response (200) - **SyncConversationCursorPage[ProjectUser]** (object) - A paginated list of project user objects. ``` -------------------------------- ### post /completions Source: https://github.com/openai/openai-python/blob/main/api.md Creates a completion for the provided prompt and parameters. This endpoint is used to generate text based on a given input. ```APIDOC ## POST /completions ### Description Creates a completion for the provided prompt and parameters. ### Method POST ### Endpoint /completions ### Request Body - **params** (object) - Required - Parameters for creating the completion. ``` -------------------------------- ### get /organization/usage/embeddings Source: https://github.com/openai/openai-python/blob/main/api.md Retrieves usage data specifically for embeddings within an organization. ```APIDOC ## GET /organization/usage/embeddings ### Description Retrieves usage data specifically for embeddings within an organization. ### Method GET ### Endpoint /organization/usage/embeddings ### Parameters This endpoint accepts various parameters for filtering and pagination, but specific details are not provided in the source. ### Response #### Success Response (200) Returns a UsageEmbeddingsResponse object containing the requested usage data. ``` -------------------------------- ### Create Checkpoint Permission in Python Source: https://github.com/openai/openai-python/blob/main/api.md Use the client to create a new permission for a specified fine-tuned model checkpoint. ```python client.fine_tuning.checkpoints.permissions.create(fine_tuned_model_checkpoint, **params) ```