Skip to content

Instantly share code, notes, and snippets.

@Iemand005
Created March 31, 2025 11:54
Show Gist options
  • Save Iemand005/5769f37919575c998a94b5cae3942c3e to your computer and use it in GitHub Desktop.
Save Iemand005/5769f37919575c998a94b5cae3942c3e to your computer and use it in GitHub Desktop.
Download ChatGPT full chat history

ChatGPT Downloader

Paste this script in your browser console to download your chats.

const token = __reactRouterContext.state.loaderData.root.clientBootstrap.session.accessToken;
async function request(endpoint, params = {}) {
return await fetch(`https://chatgpt.com/backend-api/${endpoint}?${new URLSearchParams(params).toString()}`, {
headers: { "Authorization": token }
}).then(response => response.json());
}
async function getConversations(offset = 0, limit = 100, order = 'updated') {
return await request("conversations", {
offset: offset,
limit: limit,
order: order
});
}
async function getAllConversations() {
const allConversations = [];
let conversationCount = true;
let offset = 0;
while (conversationCount) await getConversations(offset).then(conversations => (conversationCount = conversations.items.length, offset += conversations.limit, allConversations.push(...conversations.items)));
return allConversations;
}
async function getConversation(id) {
return await request(`conversation/${id}`);
}
async function getAllConversationsContents() {
const allConversations = await getAllConversations();
const allConversationContents = [];
for (const conversation of allConversations) allConversationContents.push(getConversation(conversation.id));
return {conversationHeaders: allConversations, conversationContents: await Promise.all(allConversationContents)};
}
async function downloadAll() {
const data = await getAllConversationsContents();
const a = document.createElement('a');
a.setAttribute('href', URL.createObjectURL(new Blob([JSON.stringify(data)], {type: 'application/json'})));
a.setAttribute('download', 'ChatGPTData.json');
a.click();
}
downloadAll();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment