Unofficial Claude2 API supporting direct HTTP chat creation/deletion/retrieval, message attachments and auto session gathering using Firefox with geckodriver.
Project description
unofficial-claude2-api
Claude2 unofficial API supporting direct HTTP chat creation/deletion/retrieval, message attachments and auto session gathering using Firefox with geckodriver.
How to install
pip install unofficial-claude2-api
Uninstallation
pip uninstall unofficial-claude2-api
Requirements
These requirements are needed to auto retrieve session cookie and UserAgent using selenium
-
Firefox installed, and with at least one profile logged into Claude.
-
geckodriver installed inside a folder registered in PATH environment variable.
Example Usage
from claude2_api.client import (
ClaudeAPIClient,
get_session_data,
MessageRateLimitHit,
)
FILEPATH = "test.txt"
# This function will automatically retrieve a SessionData instance using selenium
# Omitting profile argument will use default Firefox profile
data = get_session_data()
# Initialize a client instance using a session
client = ClaudeAPIClient(data)
# Create a new chat and cache the chat_id
chat_id = client.create_chat()
if not chat_id:
# This will not throw MessageRateLimitHit
# But it still means that account has no more messages left.
print(f"\nMessage limit hit, cannot create chat...")
quit()
try:
# Used for sending message with or without attachment
# Returns a SendMessageResponse instance
res = client.send_message(chat_id, "Hello!", attachment_path=FILEPATH, timeout=240)
# Inspect answer
if res.answer:
print(res.answer)
else:
# Inspect response status code and json error
print(f"\nError code {res.status_code}, response -> {res.error_response}")
except MessageRateLimitHit as e:
# The exception will hold these informations about the rate limit:
print(f"\nMessage limit hit, resets at {e.resetDate}")
print(f"\n{e.sleep_sec} seconds left until -> {e.resetTimestamp}")
quit()
finally:
# Perform chat deletion for cleanup
client.delete_chat(chat_id)
# Get a list of all chats ids
all_chat_ids = client.get_all_chat_ids()
# Delete all chats
for chat in all_chat_ids:
client.delete_chat(chat)
# Or by using a shortcut utility
#
# client.delete_all_chats()
TROUBLESHOOTING
This api will sometime return a 403 status_code when calling send_message
, when this happens it is recommeded to look for these things:
-
Check if your IP location is allowed, should be in US/UK, other locations may work sporadically.
-
Don't try to send the same prompt/file over and over again, instead wait for some time, and change input.
DISCLAIMER
This repository provides an unofficial API for automating free accounts on claude.ai. Please note that this API is not endorsed, supported, or maintained by Anthropic. Use it at your own discretion and risk. Anthropic may make changes to their official product or APIs at any time, which could affect the functionality of this unofficial API. We do not guarantee the accuracy, reliability, or security of the information and data retrieved using this API. By using this repository, you agree that the maintainers are not responsible for any damages, issues, or consequences that may arise from its usage. Always refer to Anthropic's official documentation and terms of use. This project is maintained independently by contributors who are not affiliated with Anthropic.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for unofficial-claude2-api-0.1.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f0041dd93627321f98f86ba89b055c5002876fadcac6dd2d74c607b2d22c960 |
|
MD5 | 8b256e32b7cfb71c7db4a8ac9b8418cd |
|
BLAKE2b-256 | b953ed70d5364a3777e6612772dace7806144c907f4435c4606b1aca93a8675c |
Hashes for unofficial_claude2_api-0.1.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f80c07fd7bff952b01fe45e24348b1be29a8fbe0062cc354a04e79e6ce553f91 |
|
MD5 | dc67d951f6d0a15907ee35c7ee7709b0 |
|
BLAKE2b-256 | 5b93dda656677ebaff4cd14f3e63d25cc7f0f05d8540143b4582e981531dccc2 |