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.
- Export a single conversation by ID
- Clean Markdown output
- Optional raw JSON export
- Preserves roles and timestamps
- No scraping — uses the same backend endpoint as the web UI
# 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...- Python 3.10+
requests- A valid authenticated ChatGPT web session
uv init
uv add requestspip install requestsClone the repository and place yourself in the project directory.
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.jsonUsing a session cookie instead of a Bearer token:
python export_chat.py <CONVERSATION_ID> --cookie "$CHATGPT_COOKIE"From the browser URL:
https://chatgpt.com/c/<CONVERSATION_ID>
Copy the <CONVERSATION_ID> part.
Open DevTools → Network → reload the conversation page.
Find the request:
/backend-api/conversation/<id>
From Request Headers, copy either:
Authorization: Bearer <token>
Then:
export CHATGPT_BEARER="PASTE_TOKEN"Copy the full Cookie: header or just the session token:
export CHATGPT_COOKIE="__Secure-next-auth.session-token=..."Then run the script.
By default:
<conversation_id>.md
Optional:
<conversation_id>.json
Markdown includes:
- Conversation title
- Export timestamp
- Chronologically sorted messages
- Roles (
user,assistant, etc.) - ISO 8601 timestamps (UTC)
-
Calls:
GET /backend-api/conversation/<id> -
Parses the
mappingmessage tree -
Extracts message content
-
Sorts by
create_time -
Renders Markdown
No DOM inspection. No scrolling hacks. No partial exports.
- Requires active authenticated session
- API endpoint is undocumented and may change
- Messages are sorted strictly by timestamp (not branch-aware)
- Attachments are not downloaded (text content only)
- Treat Bearer tokens like passwords
- Never commit tokens to version control
- Revoke your session if a token is exposed
- JSON output may contain metadata
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.
- Branch-aware export (follow active path)
- HTML output
- JSONL output for indexing
- Batch export multiple conversation IDs
- Attachment downloading
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.