Skip to main content

Claude AI-API ( Unofficial )

This project provides an unofficial API for Claude AI, allowing users to access and interact with Claude AI .

Current Version == 1.0.17 ( Added Timeouts,Faster Requests,File handling Fixed.. )

Table of contents

Use Cases

1. Python Console ChatBot ( Check in usecases folder for sample console chatbot )

2. Discord Chatbot   

3. Many more can be done....

Prerequisites

To use this API, you need to have the following:

Python installed on your system requests library installed

  pip install requests

Installation

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

Usage

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 )

    Screenshot (8)

    cookie = os.environ.get('cookie')
    claude_api = Client(cookie)
    

List All Conversations

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)

Send Message

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)

Send Message with attachment

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)

Delete Conversation

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")

Chat Conversation History

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)

Create New Chat

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)

Reset All Conversations

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")   

Rename Chat

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")

Disclaimer

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.

Metadata

Release files for claude-api 1.0.17

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for claude-api 1.0.17
File Size Uploaded
claude-api-1.0.17.tar.gz 6.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for claude-api 1.0.17
File Interpreter ABI Platform
claude_api-1.0.17-py3-none-any.whl Python 3 none any Details

Total release size: 12.3 kB

Release files / claude-api-1.0.17.tar.gz

Download URL claude-api-1.0.17.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
489c0c49eac93c3d91854ec1cbf6070087dc63d891b3acd83e87f47ea2fe24c2
BLAKE2b-256 checksum
How to use checksums
42f64a4970d54d1288da5052df8b9d75c65a94650ab380efda6289726d04f129
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release files / claude_api-1.0.17-py3-none-any.whl

Download URL claude_api-1.0.17-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5d0d12d17608c3d966277bd3385824d1ffa992bede6be76f65623b909d50c5b2
BLAKE2b-256 checksum
How to use checksums
3f0323156dba75e1f50f6dea64e32a9097f0f0cff5f58b53462d4a142c51564b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release history Release notifications | RSS feed

This release

1.0.17 This release

2 release files

1.0.16

2 release files

1.0.15

2 release files

1.0.14

2 release files

1.0.13

2 release files

1.0.12

2 release files

1.0.11

2 release files

1.0.10

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.5

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page