### Install and Authenticate via CLI Source: https://github.com/youseiushida/login-with-chatgpt-py/blob/main/README.md Commands to install the package and perform initial user authentication. ```console uvx login-with-chatgpt login uv add login-with-chatgpt ``` -------------------------------- ### Initialize Python Client with Profiles Source: https://github.com/youseiushida/login-with-chatgpt-py/blob/main/README.md Select specific profiles programmatically without affecting the global CLI default. ```python from login_with_chatgpt import OpenAI work = OpenAI(profile="work") personal = OpenAI(profile="personal") ``` -------------------------------- ### Development Workflow Commands Source: https://github.com/youseiushida/login-with-chatgpt-py/blob/main/README.md Standard commands for syncing dependencies, linting, type checking, and running tests. ```console uv sync --dev uv run ruff check . uv run pyright uv run pytest uv build ``` -------------------------------- ### Manage CLI Profiles Source: https://github.com/youseiushida/login-with-chatgpt-py/blob/main/README.md Commands for logging in, listing profiles, switching active profiles, and checking status. ```console login-with-chatgpt --profile work login login-with-chatgpt profiles login-with-chatgpt use work login-with-chatgpt status login-with-chatgpt models login-with-chatgpt doctor login-with-chatgpt logout ``` -------------------------------- ### Initialize Synchronous OpenAI Client Source: https://github.com/youseiushida/login-with-chatgpt-py/blob/main/README.md Standard usage of the synchronous client to generate responses using ChatGPT models. ```python from login_with_chatgpt import OpenAI client = OpenAI() response = client.responses.create( model="gpt-5.6-sol", input="Explain Python descriptors in three sentences.", ) print(response.output_text) client.close() ``` -------------------------------- ### Run Live Contract Tests Source: https://github.com/youseiushida/login-with-chatgpt-py/blob/main/README.md Execute live tests for models and image generation by setting specific environment variables. ```console $env:LOGIN_WITH_CHATGPT_LIVE_MODEL = "gpt-5.6-sol" uv run pytest tests/test_live.py -m live ``` ```console $env:LOGIN_WITH_CHATGPT_LIVE_IMAGE_MODEL = "gpt-image-2" uv run pytest tests/test_live_images.py -m live ``` -------------------------------- ### Authenticate in Headless Environments Source: https://github.com/youseiushida/login-with-chatgpt-py/blob/main/README.md Use the device flow for authentication in environments without a browser, such as SSH or containers. ```console uvx login-with-chatgpt login --device ``` -------------------------------- ### client.responses.create() Source: https://github.com/youseiushida/login-with-chatgpt-py/blob/main/README.md Creates a response from the ChatGPT Codex endpoint. ```APIDOC ## POST /responses ### Description Creates a response using the ChatGPT Codex endpoint. ### Method POST ### Endpoint /responses ``` -------------------------------- ### Initialize Asynchronous OpenAI Client Source: https://github.com/youseiushida/login-with-chatgpt-py/blob/main/README.md Usage of the asynchronous client for non-blocking operations in async applications. ```python from login_with_chatgpt import AsyncOpenAI async def main() -> None: client = AsyncOpenAI() try: response = await client.responses.create( model="gpt-5.6-sol", input="Reply with only: async ok", ) print(response.output_text) finally: await client.close() ``` -------------------------------- ### ChatGPTAccount().list_models() Source: https://github.com/youseiushida/login-with-chatgpt-py/blob/main/README.md Lists available models from the ChatGPT Codex endpoint. ```APIDOC ## GET /models ### Description Retrieves a list of available models. ### Method GET ### Endpoint /models ``` -------------------------------- ### Verify Account and Model Status Source: https://github.com/youseiushida/login-with-chatgpt-py/blob/main/README.md Commands to check the current authentication status, available models, and system health. ```console uvx login-with-chatgpt status uvx login-with-chatgpt models uvx login-with-chatgpt doctor ``` -------------------------------- ### client.images.generate Source: https://github.com/youseiushida/login-with-chatgpt-py/blob/main/README.md Generates an image based on a text prompt using the gpt-image-2 model. ```APIDOC ## client.images.generate ### Description Generates an image from a text prompt. The result returns an `openai.types.ImagesResponse` model. ### Parameters - **model** (string) - Required - Must be "gpt-image-2". - **prompt** (string) - Required - The description of the image to generate. - **background** (string) - Optional - Background setting (e.g., "opaque"). - **quality** (string) - Optional - Image quality (e.g., "low"). - **size** (string) - Optional - Image dimensions (e.g., "1024x1024"). ### Response - **data** (list) - A list containing the generated image data, including `b64_json`. ``` -------------------------------- ### Generate an image with gpt-image-2 Source: https://github.com/youseiushida/login-with-chatgpt-py/blob/main/README.md Generates an image based on a text prompt and saves the base64 encoded result to a file. ```python import base64 from pathlib import Path from login_with_chatgpt import OpenAI client = OpenAI() result = client.images.generate( model="gpt-image-2", prompt="A quiet Tokyo street after rain", background="opaque", quality="low", size="1024x1024", ) assert result.data and result.data[0].b64_json Path("tokyo.png").write_bytes(base64.b64decode(result.data[0].b64_json)) client.close() ``` -------------------------------- ### client.images.generate() Source: https://github.com/youseiushida/login-with-chatgpt-py/blob/main/README.md Generates an image using the ChatGPT Codex endpoint. ```APIDOC ## POST /images/generations ### Description Generates an image via the ChatGPT Codex endpoint. ### Method POST ### Endpoint /images/generations ``` -------------------------------- ### Generate structured output with Pydantic Source: https://github.com/youseiushida/login-with-chatgpt-py/blob/main/README.md Use the parse method to map API responses directly to Pydantic models. Requires a defined BaseModel and an active client instance. ```python from pydantic import BaseModel from login_with_chatgpt import OpenAI class Answer(BaseModel): summary: str points: list[str] client = OpenAI() response = client.responses.parse( model="gpt-5.6-sol", input="Summarize OAuth PKCE.", text_format=Answer, ) print(response.output_parsed) client.close() ``` -------------------------------- ### Edit images with gpt-image-2 Source: https://github.com/youseiushida/login-with-chatgpt-py/blob/main/README.md Edits an existing image by providing a source file and a prompt, then saves the resulting base64 encoded image. ```python import base64 from pathlib import Path from login_with_chatgpt import OpenAI client = OpenAI() with Path("source.png").open("rb") as source: result = client.images.edit( model="gpt-image-2", image=source, prompt="Change the lighting to late afternoon", quality="medium", size="1024x1024", ) assert result.data and result.data[0].b64_json Path("edited.png").write_bytes(base64.b64decode(result.data[0].b64_json)) client.close() ``` -------------------------------- ### Stream responses from the API Source: https://github.com/youseiushida/login-with-chatgpt-py/blob/main/README.md Utilize the stream method to handle SSE responses in real-time. Ensure the client is closed after the stream context manager exits. ```python from login_with_chatgpt import OpenAI client = OpenAI() with client.responses.stream( model="gpt-5.6-sol", input="Write one short sentence.", ) as stream: for event in stream: if event.type == "response.output_text.delta": print(event.delta, end="", flush=True) client.close() ``` -------------------------------- ### client.responses.parse() Source: https://github.com/youseiushida/login-with-chatgpt-py/blob/main/README.md Parses a response from the ChatGPT Codex endpoint into a structured format. ```APIDOC ## POST /responses ### Description Parses a response from the ChatGPT Codex endpoint into a structured format using Pydantic models. ### Method POST ### Endpoint /responses ``` -------------------------------- ### client.images.edit Source: https://github.com/youseiushida/login-with-chatgpt-py/blob/main/README.md Edits one or more existing images based on a prompt using the gpt-image-2 model. ```APIDOC ## client.images.edit ### Description Edits provided source images based on a prompt. Supports PNG, JPEG, and WebP files. ### Parameters - **model** (string) - Required - Must be "gpt-image-2". - **image** (file) - Required - The source image file to edit. - **prompt** (string) - Required - The instructions for editing the image. - **quality** (string) - Optional - Image quality (e.g., "medium"). - **size** (string) - Optional - Image dimensions (e.g., "1024x1024"). ### Response - **data** (list) - A list containing the edited image data, including `b64_json`. ``` -------------------------------- ### Override Protocol Version Source: https://github.com/youseiushida/login-with-chatgpt-py/blob/main/README.md Force a specific Codex protocol version via environment variables or the Python constructor. ```console $env:LOGIN_WITH_CHATGPT_CLIENT_VERSION = "0.145.0" login-with-chatgpt doctor ``` ```python from login_with_chatgpt import OpenAI client = OpenAI(client_version="0.145.0") ``` -------------------------------- ### client.images.edit() Source: https://github.com/youseiushida/login-with-chatgpt-py/blob/main/README.md Edits an image using the ChatGPT Codex endpoint. ```APIDOC ## POST /images/edits ### Description Edits an image via the ChatGPT Codex endpoint. ### Method POST ### Endpoint /images/edits ``` -------------------------------- ### client.responses.stream() Source: https://github.com/youseiushida/login-with-chatgpt-py/blob/main/README.md Streams a response from the ChatGPT Codex endpoint. ```APIDOC ## POST /responses ### Description Streams a response from the ChatGPT Codex endpoint using SSE. ### Method POST ### Endpoint /responses ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.