This project provides an unofficial API for Claude AI, allowing users to access and interact with Claude AI .
![](https://private-user-images.githubusercontent.com/103725723/257031880-385fa539-e725-4c20-86ff-0864e6ffab82.jpg?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjE4OTc3MjksIm5iZiI6MTcyMTg5NzQyOSwicGF0aCI6Ii8xMDM3MjU3MjMvMjU3MDMxODgwLTM4NWZhNTM5LWU3MjUtNGMyMC04NmZmLTA4NjRlNmZmYWI4Mi5qcGc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzI1JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDcyNVQwODUwMjlaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1iMzkxMGM0MGRiNTQzNzdiMDI1MDdjZDJjODNiNmM3MDE2OGJmYmVlODU3M2VmNjAyYjA4MzkwMTgyZTZkZjk3JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.pbcRYWlDsJTQIykuqikO0RP-mq2dYjnPdec_0yMgxZ0)
- Use Cases
- Prerequisites
- Installation
- Usage
- List All Conversations
- Send Message
- Send Message with attachment
- Delete Conversation
- Chat Conversation History
- Create New Chat
- Reset All Conversations
- Rename Chat
- Disclaimer
1. Python Console ChatBot ( Check in usecases folder for sample console chatbot )
2. Discord Chatbot
3. Many more can be done....
To use this API, you need to have the following:
Python installed on your system requests library installed
pip install requests
To use the Claude AI Unofficial API, you can either clone the GitHub repository or directly download the Python file.
Terminal :
pip install claude-api
or
Clone the repository:
git clone https://github.com/KoushikNavuluri/Claude-API.git
Import the claude_api module in your Python script:
from claude_api import Client
-
Next, you need to create an instance of the Client class by providing your Claude AI cookie:
-
You can get cookie from the browser's developer tools network tab ( see for any claude.ai requests check out cookie ,copy whole value ) or storage tab ( You can find cookie of claude.ai ,there will be four values )
-
(Checkout below image for the format of cookie ,It is Better to Use from network tab to grab cookie easily )
cookie = os.environ.get('cookie') claude_api = Client(cookie)
To list all the conversation Id's you had with Claude , you can use the list_all_conversations method:
conversations = claude_api.list_all_conversations()
for conversation in conversations:
conversation_id = conversation['uuid']
print(conversation_id)
To send a message to Claude, you can use the send_message method. You need to provide the prompt and the conversation ID:
prompt = "Hello, Claude!"
conversation_id = "<conversation_id>" or claude_api.create_new_chat()['uuid']
response = claude_api.send_message(prompt, conversation_id)
print(response)
You can send any type of attachment to claude to get responses using attachment argument in send_message(). Note: Claude currently supports only some file types.
{ You can also add timeout if you need ,using timeout parameter[default set to 500] }
prompt = "Hey,Summarize me this document.!"
conversation_id = "<conversation_id>" or claude_api.create_new_chat()['uuid']
response = claude_api.send_message(prompt, conversation_id,attachment="path/to/file.pdf",timeout=600)
print(response)
To delete a conversation, you can use the delete_conversation method:
conversation_id = "<conversation_id>"
deleted = claude_api.delete_conversation(conversation_id)
if deleted:
print("Conversation deleted successfully")
else:
print("Failed to delete conversation")
To get the chat conversation history, you can use the chat_conversation_history method:
conversation_id = "<conversation_id>"
history = claude_api.chat_conversation_history(conversation_id)
print(history)
To create a new chat conversation (id), you can use the create_new_chat method:
new_chat = claude_api.create_new_chat()
conversation_id = new_chat['uuid']
print(conversation_id)
To reset all conversations, you can use the reset_all method:
reset = claude_api.reset_all()
if reset:
print("All conversations reset successfully")
else:
print("Failed to reset conversations")
To rename a chat conversation, you can use the rename_chat method:
conversation_id = "<conversation_id>"
title = "New Chat Title"
renamed = claude_api.rename_chat(title, conversation_id)
if renamed:
print("Chat conversation renamed successfully")
else:
print("Failed to rename chat conversation")
This project provides an unofficial API for Claude AI and is not affiliated with or endorsed by Claude AI or Anthropic. Use it at your own risk.
Please refer to the official Claude AI documentation[https://claude.ai/docs] for more information on how to use Claude AI.