← all projects

chatgpt-export

Exporting chat conversations
repo chatgpt export

ChatGPT Conversation Exporter

Export a single ChatGPT conversation to Markdown (and optionally raw JSON) using its conversation ID.

This tool fetches the same structured JSON the ChatGPT web app uses and converts it into a clean, portable Markdown file suitable for archiving, version control, or further processing.


Features


Example Output

# How to export chat

_Exported: 2026-02-25T12:34:56+00:00_

## USER (2026-02-25T12:00:00+00:00)

How do I export this chat?

## ASSISTANT (2026-02-25T12:00:02+00:00)

Here are your options...

Requirements


Installation

Using UV (recommended)

uv init
uv add requests

Using pip

pip install requests

Clone the repository and place yourself in the project directory.


Usage

Basic export to Markdown:

python export_chat.py <CONVERSATION_ID> --bearer "$CHATGPT_BEARER"

Export Markdown + raw JSON:

python export_chat.py <CONVERSATION_ID> \
  --bearer "$CHATGPT_BEARER" \
  --out-md chat.md \
  --out-json chat.json

Using a session cookie instead of a Bearer token:

python export_chat.py <CONVERSATION_ID> --cookie "$CHATGPT_COOKIE"

Getting the Conversation ID

From the browser URL:

https://chatgpt.com/c/<CONVERSATION_ID>

Copy the <CONVERSATION_ID> part.


Getting Authentication

Open DevTools → Network → reload the conversation page.

Find the request:

/backend-api/conversation/<id>

From Request Headers, copy either:

Option A — Bearer token (preferred)

Authorization: Bearer <token>

Then:

export CHATGPT_BEARER="PASTE_TOKEN"

Option B — Cookie

Copy the full Cookie: header or just the session token:

export CHATGPT_COOKIE="__Secure-next-auth.session-token=..."

Then run the script.


Output Files

By default:

<conversation_id>.md

Optional:

<conversation_id>.json

Markdown includes:


How It Works

  1. Calls:

    GET /backend-api/conversation/<id>
    
  2. Parses the mapping message tree

  3. Extracts message content

  4. Sorts by create_time

  5. Renders Markdown

No DOM inspection. No scrolling hacks. No partial exports.


Limitations


Security Notes


Suggested Archival Workflow

python export_chat.py <id>
git add <id>.md
git commit -m "Archive chat <id>"

Keeps conversations searchable and portable without using the full account export.


Possible Extensions


Disclaimer

This project uses an internal backend endpoint exposed to the ChatGPT web client. It is not an officially documented public API and may change without notice. This project is based on an initial version, generated by ChatGPT.