Save your Hey Pi AI conversation history for safekeeping.
bun install
- Sign into https://pi.ai and open up Chrome Developer Tools (or your browser's equivalent).
- Head to the Network tab and filter by
Fetch/XHR
. Refresh the Pi website so you get a fresh initial page load. - Look for a fetch request that looks like
history?conversation=xxxxxx...
This is the request we are looking to replicate, thatxxxxxx..
string is also your conversation ID. - Copy and paste
.env.example
and rename your copy.env
. These are your details. - Copy and paste in your conversation ID into the
CONVERSATION_ID
env variable. - Click into the network request and under the Headers tab, scroll down to the bottom, you're looking for the
> Request Headers
section. - There should be a value there called
Cookie
that looks like__Host-session=xxxxxx...; __cf_bm=xxxxxx...
. - Copy that whole Cookie string and paste it into the
COOKIE
env variable. - Now you may run the script. Your conversation history will be in
./saved/{conversationID}
, and in files positively incremented from the current point of your conversation backward.
bun run index.ts
I haven't figured out a way to start from a specific point yet, especially if your conversation is still ongoing with Pi. The cursors change everytime you continue the conversation so if you wanted to just fetch from your last cursor and get the delta, unless I figure out some fancy schmancy diffing algo, I can't say I'd be able to only fetch the difference. There's a way to do it, but again I'd have to sort out duplicated messages and whatnot, I'm not sure whether it'd be worth it (unless this is going to be integrated into the main desktop app, and if so, Inflection, I am open for work ! 😁)
Threads are going to be a bit more complicated as they're considered independent conversations. There is an endpoint to fetch those conversations but then I'm not sure how I'd bring you back to the main conversation. It's implementable though.
This project was created using bun init
in bun v1.1.17. Bun is a fast all-in-one JavaScript runtime.