Skip to content

Instantly share code, notes, and snippets.

@korakot
Created October 27, 2023 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save korakot/c89973a06e9aed34ebebdaabdf8eb365 to your computer and use it in GitHub Desktop.
Save korakot/c89973a06e9aed34ebebdaabdf8eb365 to your computer and use it in GitHub Desktop.
Use Claude API to get history
!pip install claude2
from claude import Claude
from fastcore.foundation import patch
from curl_cffi import requests
cookie = "sessionKey=sk-ant-sid01-4etj_0tI6RJKMbAAA"
claude = Claude(cookie)
@patch
def get_history(self: Claude):
url = f'https://claude.ai/api/organizations/{self.organisation_uuid}/chat_conversations'
headers = {
'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0',
'Accept-Language': 'en-US,en;q=0.5',
'Referer': 'https://claude.ai/chats',
'Content-Type': 'application/json',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin',
'Connection': 'keep-alive',
'Cookie': f'{self.cookies}'
}
rsp = requests.get(url, headers=headers, impersonate='chrome110')
return rsp.json()
history = claude.get_history()
claude.conversation_uuid = history[-1]['uuid'] # or list to see names, then select its uuid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment