Created
May 14, 2025 16:30
-
-
Save andriitishchenko/33f5610b81fabb41b4b721a0bd85d924 to your computer and use it in GitHub Desktop.
chatgpt conversation removing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (async () => { | |
| const AUTH_TOKEN = "Replace with your token"; | |
| const OAI_CLIENT_VERSION = "Replace with your OAI_CLIENT"; | |
| const OAI_DEVICE_ID = "Replace with your OAI_DEVICE_ID"; | |
| // ==== Config ==== | |
| const API_BASE_URL = "https://chatgpt.com"; | |
| const PATH_CONVERSATIONS = "/backend-api/conversations"; | |
| const PATH_DELETE_CONVERSATION = "/backend-api/conversation"; | |
| const ORDER = "updated"; | |
| const SLEEP_INTERVAL = 500; | |
| const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); | |
| const commonHeaders = () => ({ | |
| "Accept": "*/*", | |
| "Accept-Language": "en-US,en;q=0.9", | |
| "Authorization": `Bearer ${AUTH_TOKEN}`, | |
| "Cache-Control": "no-cache", | |
| "Pragma": "no-cache", | |
| "OAI-Client-Version": OAI_CLIENT_VERSION, | |
| "OAI-Device-Id": OAI_DEVICE_ID, | |
| "OAI-Language": "en-US", | |
| "Priority": "u=3, i", | |
| "Referer": `${API_BASE_URL}`, | |
| "Sec-Fetch-Dest": "empty", | |
| "Sec-Fetch-Mode": "cors", | |
| "Sec-Fetch-Site": "same-origin", | |
| }); | |
| async function fetchConversations() { | |
| const url = `${API_BASE_URL}${PATH_CONVERSATIONS}?offset=0&limit=99&order=${ORDER}`; | |
| try { | |
| const response = await fetch(url, { | |
| method: "GET", | |
| headers: commonHeaders(), | |
| credentials: "include", | |
| }); | |
| if (!response.ok) { | |
| const error = await response.json().catch(() => ({})); | |
| throw new Error(`Failed to fetch conversations: ${response.status} ${response.statusText}. ${error.error || ''}`); | |
| } | |
| const data = await response.json(); | |
| return data.items || []; | |
| } catch (err) { | |
| console.error(err.message); | |
| return []; | |
| } | |
| } | |
| async function deleteConversation(id) { | |
| const url = `${API_BASE_URL}${PATH_DELETE_CONVERSATION}/${id}`; | |
| try { | |
| const response = await fetch(url, { | |
| method: "PATCH", | |
| headers: { | |
| ...commonHeaders(), | |
| "Content-Type": "application/json", | |
| "Referer": `${API_BASE_URL}/c/${id}`, | |
| }, | |
| credentials: "include", | |
| body: JSON.stringify({ is_visible: false }), | |
| }); | |
| if (!response.ok) { | |
| const error = await response.json().catch(() => ({})); | |
| throw new Error(`Failed to delete conversation ${id}: ${error.error || response.statusText}`); | |
| } | |
| console.log(`β Conversation ${id} deleted successfully`); | |
| } catch (err) { | |
| console.error(`β ${err.message}`); | |
| } | |
| } | |
| try { | |
| const conversations = await fetchConversations(); | |
| console.log(`π Found conversations: ${conversations.length}`); | |
| if (conversations.length === 0) { | |
| console.log("No conversations available for deletion."); | |
| return; | |
| } | |
| for (const { id } of conversations) { | |
| console.log(`ποΈ Deleting conversation: ${id}`); | |
| await deleteConversation(id); | |
| await sleep(SLEEP_INTERVAL); | |
| } | |
| } catch (err) { | |
| console.error("Script execution error:", err); | |
| } | |
| })(); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The token and identifiers can be taken from any request in the "Network" tab of the developer tools.