├── .gitignore
├── LICENSE
├── README.md
├── claude-api
└── claude_api.py
├── setup.py
└── usecases
└── console_chat.py
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 |
9 | # Distribution / packaging
10 | .Python
11 | build/
12 | develop-eggs/
13 | dist/
14 | downloads/
15 | eggs/
16 | .eggs/
17 | lib/
18 | lib64/
19 | parts/
20 | sdist/
21 | var/
22 | wheels/
23 | share/python-wheels/
24 | *.egg-info/
25 | .installed.cfg
26 | *.egg
27 | MANIFEST
28 |
29 | # PyInstaller
30 | # Usually these files are written by a python script from a template
31 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
32 | *.manifest
33 | *.spec
34 |
35 | # Installer logs
36 | pip-log.txt
37 | pip-delete-this-directory.txt
38 |
39 | # Unit test / coverage reports
40 | htmlcov/
41 | .tox/
42 | .nox/
43 | .coverage
44 | .coverage.*
45 | .cache
46 | nosetests.xml
47 | coverage.xml
48 | *.cover
49 | *.py,cover
50 | .hypothesis/
51 | .pytest_cache/
52 | cover/
53 |
54 | # Translations
55 | *.mo
56 | *.pot
57 |
58 | # Django stuff:
59 | *.log
60 | local_settings.py
61 | db.sqlite3
62 | db.sqlite3-journal
63 |
64 | # Flask stuff:
65 | instance/
66 | .webassets-cache
67 |
68 | # Scrapy stuff:
69 | .scrapy
70 |
71 | # Sphinx documentation
72 | docs/_build/
73 |
74 | # PyBuilder
75 | .pybuilder/
76 | target/
77 |
78 | # Jupyter Notebook
79 | .ipynb_checkpoints
80 |
81 | # IPython
82 | profile_default/
83 | ipython_config.py
84 |
85 | # pyenv
86 | # For a library or package, you might want to ignore these files since the code is
87 | # intended to run in multiple environments; otherwise, check them in:
88 | # .python-version
89 |
90 | # pipenv
91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
94 | # install all needed dependencies.
95 | #Pipfile.lock
96 |
97 | # poetry
98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99 | # This is especially recommended for binary packages to ensure reproducibility, and is more
100 | # commonly ignored for libraries.
101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102 | #poetry.lock
103 |
104 | # pdm
105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106 | #pdm.lock
107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108 | # in version control.
109 | # https://pdm.fming.dev/#use-with-ide
110 | .pdm.toml
111 |
112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113 | __pypackages__/
114 |
115 | # Celery stuff
116 | celerybeat-schedule
117 | celerybeat.pid
118 |
119 | # SageMath parsed files
120 | *.sage.py
121 |
122 | # Environments
123 | .env
124 | .venv
125 | env/
126 | venv/
127 | ENV/
128 | env.bak/
129 | venv.bak/
130 |
131 | # Spyder project settings
132 | .spyderproject
133 | .spyproject
134 |
135 | # Rope project settings
136 | .ropeproject
137 |
138 | # mkdocs documentation
139 | /site
140 |
141 | # mypy
142 | .mypy_cache/
143 | .dmypy.json
144 | dmypy.json
145 |
146 | # Pyre type checker
147 | .pyre/
148 |
149 | # pytype static type analyzer
150 | .pytype/
151 |
152 | # Cython debug symbols
153 | cython_debug/
154 |
155 | # PyCharm
156 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158 | # and can be added to the global gitignore or merged into this file. For a more nuclear
159 | # option (not recommended) you can uncomment the following to ignore the entire idea folder.
160 | #.idea/
161 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 Koushik Navuluri
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Claude AI-API ( Unofficial )
2 | This project provides an unofficial API for Claude AI, allowing users to access and interact with Claude AI .
3 |
4 |
5 |
6 |
7 |
8 | #### Current Version == 1.0.17 ( Added Timeouts,Faster Requests,File handling Fixed.. )
9 |
10 | ## Table of contents
11 |
12 | * [Use Cases](#use-cases)
13 | * [Prerequisites](#prerequisites)
14 | * [Installation](#installation)
15 | * [Usage](#usage)
16 | * [List All Conversations](#list-all-conversations)
17 | * [Send Message](#send-message)
18 | * [Send Message with attachment](#send-message-with-attachment)
19 | * [Delete Conversation](#delete-conversation)
20 | * [Chat Conversation History](#chat-conversation-history)
21 | * [Create New Chat](#create-new-chat)
22 | * [Reset All Conversations](#reset-all-conversations)
23 | * [Rename Chat](#rename-chat)
24 | * [Disclaimer](#disclaimer)
25 |
26 |
27 | ## Use Cases
28 |
29 | 1. Python Console ChatBot ( Check in usecases folder for sample console chatbot )
30 |
31 | 2. Discord Chatbot
32 |
33 | 3. Many more can be done....
34 |
35 |
36 | ## Prerequisites
37 |
38 | To use this API, you need to have the following:
39 |
40 | Python installed on your system
41 | requests library installed
42 | ```bash
43 | pip install requests
44 |
45 | ```
46 |
47 | ## Installation
48 |
49 | To use the Claude AI Unofficial API, you can either clone the GitHub repository or directly download the Python file.
50 |
51 | Terminal :
52 |
53 | pip install claude-api
54 |
55 | or
56 |
57 | Clone the repository:
58 |
59 | git clone https://github.com/KoushikNavuluri/Claude-API.git
60 |
61 | ## Usage
62 |
63 |
64 | Import the claude_api module in your Python script:
65 |
66 | from claude_api import Client
67 |
68 | * Next, you need to create an instance of the Client class by providing your Claude AI cookie:
69 |
70 | * 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 )
71 |
72 | * (Checkout below image for the format of cookie ,It is Better to Use from network tab to grab cookie easily )
73 |
74 | 
75 |
76 |
77 | cookie = os.environ.get('cookie')
78 | claude_api = Client(cookie)
79 |
80 | ## List All Conversations
81 |
82 | To list all the conversation Id's you had with Claude , you can use the list_all_conversations method:
83 |
84 | conversations = claude_api.list_all_conversations()
85 | for conversation in conversations:
86 | conversation_id = conversation['uuid']
87 | print(conversation_id)
88 |
89 | ## Send Message
90 |
91 | To send a message to Claude, you can use the send_message method. You need to provide the prompt and the conversation ID:
92 |
93 |
94 |
95 | prompt = "Hello, Claude!"
96 | conversation_id = "" or claude_api.create_new_chat()['uuid']
97 | response = claude_api.send_message(prompt, conversation_id)
98 | print(response)
99 |
100 | ## Send Message with attachment
101 |
102 | You can send any type of attachment to claude to get responses using attachment argument in send_message().
103 | Note: Claude currently supports only some file types.
104 |
105 | { You can also add timeout if you need ,using timeout parameter[default set to 500] }
106 |
107 | prompt = "Hey,Summarize me this document.!"
108 | conversation_id = "" or claude_api.create_new_chat()['uuid']
109 | response = claude_api.send_message(prompt, conversation_id,attachment="path/to/file.pdf",timeout=600)
110 | print(response)
111 |
112 |
113 | ## Delete Conversation
114 |
115 | To delete a conversation, you can use the delete_conversation method:
116 |
117 |
118 | conversation_id = ""
119 | deleted = claude_api.delete_conversation(conversation_id)
120 | if deleted:
121 | print("Conversation deleted successfully")
122 | else:
123 | print("Failed to delete conversation")
124 |
125 | ## Chat Conversation History
126 |
127 | To get the chat conversation history, you can use the chat_conversation_history method:
128 |
129 | conversation_id = ""
130 | history = claude_api.chat_conversation_history(conversation_id)
131 | print(history)
132 |
133 | ## Create New Chat
134 |
135 | To create a new chat conversation (id), you can use the create_new_chat method:
136 |
137 |
138 | new_chat = claude_api.create_new_chat()
139 | conversation_id = new_chat['uuid']
140 | print(conversation_id)
141 |
142 | ## Reset All Conversations
143 |
144 | To reset all conversations, you can use the reset_all method:
145 |
146 |
147 | reset = claude_api.reset_all()
148 | if reset:
149 | print("All conversations reset successfully")
150 | else:
151 | print("Failed to reset conversations")
152 |
153 | ## Rename Chat
154 |
155 | To rename a chat conversation, you can use the rename_chat method:
156 |
157 | conversation_id = ""
158 | title = "New Chat Title"
159 | renamed = claude_api.rename_chat(title, conversation_id)
160 | if renamed:
161 | print("Chat conversation renamed successfully")
162 | else:
163 | print("Failed to rename chat conversation")
164 |
165 | ## Disclaimer
166 |
167 | 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.
168 |
169 | Please refer to the official Claude AI documentation[https://claude.ai/docs] for more information on how to use Claude AI.
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
--------------------------------------------------------------------------------
/claude-api/claude_api.py:
--------------------------------------------------------------------------------
1 | import json
2 | import os
3 | import uuid
4 | from curl_cffi import requests
5 | import requests as req
6 | import re
7 |
8 |
9 | class Client:
10 |
11 | def __init__(self, cookie):
12 | self.cookie = cookie
13 | self.organization_id = self.get_organization_id()
14 |
15 | def get_organization_id(self):
16 | url = "https://claude.ai/api/organizations"
17 |
18 | headers = {
19 | 'User-Agent':
20 | 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0',
21 | 'Accept-Language': 'en-US,en;q=0.5',
22 | 'Referer': 'https://claude.ai/chats',
23 | 'Content-Type': 'application/json',
24 | 'Sec-Fetch-Dest': 'empty',
25 | 'Sec-Fetch-Mode': 'cors',
26 | 'Sec-Fetch-Site': 'same-origin',
27 | 'Connection': 'keep-alive',
28 | 'Cookie': f'{self.cookie}'
29 | }
30 |
31 | response = requests.get(url, headers=headers,impersonate="chrome110")
32 | res = json.loads(response.text)
33 | uuid = res[0]['uuid']
34 |
35 | return uuid
36 |
37 | def get_content_type(self, file_path):
38 | # Function to determine content type based on file extension
39 | extension = os.path.splitext(file_path)[-1].lower()
40 | if extension == '.pdf':
41 | return 'application/pdf'
42 | elif extension == '.txt':
43 | return 'text/plain'
44 | elif extension == '.csv':
45 | return 'text/csv'
46 | # Add more content types as needed for other file types
47 | else:
48 | return 'application/octet-stream'
49 |
50 | # Lists all the conversations you had with Claude
51 | def list_all_conversations(self):
52 | url = f"https://claude.ai/api/organizations/{self.organization_id}/chat_conversations"
53 |
54 | headers = {
55 | 'User-Agent':
56 | 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0',
57 | 'Accept-Language': 'en-US,en;q=0.5',
58 | 'Referer': 'https://claude.ai/chats',
59 | 'Content-Type': 'application/json',
60 | 'Sec-Fetch-Dest': 'empty',
61 | 'Sec-Fetch-Mode': 'cors',
62 | 'Sec-Fetch-Site': 'same-origin',
63 | 'Connection': 'keep-alive',
64 | 'Cookie': f'{self.cookie}'
65 | }
66 |
67 | response = requests.get(url, headers=headers,impersonate="chrome110")
68 | conversations = response.json()
69 |
70 | # Returns all conversation information in a list
71 | if response.status_code == 200:
72 | return conversations
73 | else:
74 | print(f"Error: {response.status_code} - {response.text}")
75 |
76 | # Send Message to Claude
77 | def send_message(self, prompt, conversation_id, attachment=None,timeout=500):
78 | url = "https://claude.ai/api/append_message"
79 |
80 | # Upload attachment if provided
81 | attachments = []
82 | if attachment:
83 | attachment_response = self.upload_attachment(attachment)
84 | if attachment_response:
85 | attachments = [attachment_response]
86 | else:
87 | return {"Error: Invalid file format. Please try again."}
88 |
89 | # Ensure attachments is an empty list when no attachment is provided
90 | if not attachment:
91 | attachments = []
92 |
93 | payload = json.dumps({
94 | "completion": {
95 | "prompt": f"{prompt}",
96 | "timezone": "Asia/Kolkata",
97 | "model": "claude-2"
98 | },
99 | "organization_uuid": f"{self.organization_id}",
100 | "conversation_uuid": f"{conversation_id}",
101 | "text": f"{prompt}",
102 | "attachments": attachments
103 | })
104 |
105 | headers = {
106 | 'User-Agent':
107 | 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0',
108 | 'Accept': 'text/event-stream, text/event-stream',
109 | 'Accept-Language': 'en-US,en;q=0.5',
110 | 'Referer': 'https://claude.ai/chats',
111 | 'Content-Type': 'application/json',
112 | 'Origin': 'https://claude.ai',
113 | 'DNT': '1',
114 | 'Connection': 'keep-alive',
115 | 'Cookie': f'{self.cookie}',
116 | 'Sec-Fetch-Dest': 'empty',
117 | 'Sec-Fetch-Mode': 'cors',
118 | 'Sec-Fetch-Site': 'same-origin',
119 | 'TE': 'trailers'
120 | }
121 |
122 | response = requests.post( url, headers=headers, data=payload,impersonate="chrome110",timeout=500)
123 | decoded_data = response.content.decode("utf-8")
124 | decoded_data = re.sub('\n+', '\n', decoded_data).strip()
125 | data_strings = decoded_data.split('\n')
126 | completions = []
127 | for data_string in data_strings:
128 | json_str = data_string[6:].strip()
129 | data = json.loads(json_str)
130 | if 'completion' in data:
131 | completions.append(data['completion'])
132 |
133 | answer = ''.join(completions)
134 |
135 | # Returns answer
136 | return answer
137 |
138 | # Deletes the conversation
139 | def delete_conversation(self, conversation_id):
140 | url = f"https://claude.ai/api/organizations/{self.organization_id}/chat_conversations/{conversation_id}"
141 |
142 | payload = json.dumps(f"{conversation_id}")
143 | headers = {
144 | 'User-Agent':
145 | 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0',
146 | 'Accept-Language': 'en-US,en;q=0.5',
147 | 'Content-Type': 'application/json',
148 | 'Content-Length': '38',
149 | 'Referer': 'https://claude.ai/chats',
150 | 'Origin': 'https://claude.ai',
151 | 'Sec-Fetch-Dest': 'empty',
152 | 'Sec-Fetch-Mode': 'cors',
153 | 'Sec-Fetch-Site': 'same-origin',
154 | 'Connection': 'keep-alive',
155 | 'Cookie': f'{self.cookie}',
156 | 'TE': 'trailers'
157 | }
158 |
159 | response = requests.delete( url, headers=headers, data=payload,impersonate="chrome110")
160 |
161 | # Returns True if deleted or False if any error in deleting
162 | if response.status_code == 204:
163 | return True
164 | else:
165 | return False
166 |
167 | # Returns all the messages in conversation
168 | def chat_conversation_history(self, conversation_id):
169 | url = f"https://claude.ai/api/organizations/{self.organization_id}/chat_conversations/{conversation_id}"
170 |
171 | headers = {
172 | 'User-Agent':
173 | 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0',
174 | 'Accept-Language': 'en-US,en;q=0.5',
175 | 'Referer': 'https://claude.ai/chats',
176 | 'Content-Type': 'application/json',
177 | 'Sec-Fetch-Dest': 'empty',
178 | 'Sec-Fetch-Mode': 'cors',
179 | 'Sec-Fetch-Site': 'same-origin',
180 | 'Connection': 'keep-alive',
181 | 'Cookie': f'{self.cookie}'
182 | }
183 |
184 | response = requests.get( url, headers=headers,impersonate="chrome110")
185 |
186 |
187 | # List all the conversations in JSON
188 | return response.json()
189 |
190 | def generate_uuid(self):
191 | random_uuid = uuid.uuid4()
192 | random_uuid_str = str(random_uuid)
193 | formatted_uuid = f"{random_uuid_str[0:8]}-{random_uuid_str[9:13]}-{random_uuid_str[14:18]}-{random_uuid_str[19:23]}-{random_uuid_str[24:]}"
194 | return formatted_uuid
195 |
196 | def create_new_chat(self):
197 | url = f"https://claude.ai/api/organizations/{self.organization_id}/chat_conversations"
198 | uuid = self.generate_uuid()
199 |
200 | payload = json.dumps({"uuid": uuid, "name": ""})
201 | headers = {
202 | 'User-Agent':
203 | 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0',
204 | 'Accept-Language': 'en-US,en;q=0.5',
205 | 'Referer': 'https://claude.ai/chats',
206 | 'Content-Type': 'application/json',
207 | 'Origin': 'https://claude.ai',
208 | 'DNT': '1',
209 | 'Connection': 'keep-alive',
210 | 'Cookie': self.cookie,
211 | 'Sec-Fetch-Dest': 'empty',
212 | 'Sec-Fetch-Mode': 'cors',
213 | 'Sec-Fetch-Site': 'same-origin',
214 | 'TE': 'trailers'
215 | }
216 |
217 | response = requests.post( url, headers=headers, data=payload,impersonate="chrome110")
218 |
219 | # Returns JSON of the newly created conversation information
220 | return response.json()
221 |
222 | # Resets all the conversations
223 | def reset_all(self):
224 | conversations = self.list_all_conversations()
225 |
226 | for conversation in conversations:
227 | conversation_id = conversation['uuid']
228 | delete_id = self.delete_conversation(conversation_id)
229 |
230 | return True
231 |
232 | def upload_attachment(self, file_path):
233 | if file_path.endswith('.txt'):
234 | file_name = os.path.basename(file_path)
235 | file_size = os.path.getsize(file_path)
236 | file_type = "text/plain"
237 | with open(file_path, 'r', encoding='utf-8') as file:
238 | file_content = file.read()
239 |
240 | return {
241 | "file_name": file_name,
242 | "file_type": file_type,
243 | "file_size": file_size,
244 | "extracted_content": file_content
245 | }
246 | url = 'https://claude.ai/api/convert_document'
247 | headers = {
248 | 'User-Agent':
249 | 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0',
250 | 'Accept-Language': 'en-US,en;q=0.5',
251 | 'Referer': 'https://claude.ai/chats',
252 | 'Origin': 'https://claude.ai',
253 | 'Sec-Fetch-Dest': 'empty',
254 | 'Sec-Fetch-Mode': 'cors',
255 | 'Sec-Fetch-Site': 'same-origin',
256 | 'Connection': 'keep-alive',
257 | 'Cookie': f'{self.cookie}',
258 | 'TE': 'trailers'
259 | }
260 |
261 | file_name = os.path.basename(file_path)
262 | content_type = self.get_content_type(file_path)
263 |
264 | files = {
265 | 'file': (file_name, open(file_path, 'rb'), content_type),
266 | 'orgUuid': (None, self.organization_id)
267 | }
268 |
269 | response = req.post(url, headers=headers, files=files)
270 | if response.status_code == 200:
271 | return response.json()
272 | else:
273 | return False
274 |
275 |
276 |
277 | # Renames the chat conversation title
278 | def rename_chat(self, title, conversation_id):
279 | url = "https://claude.ai/api/rename_chat"
280 |
281 | payload = json.dumps({
282 | "organization_uuid": f"{self.organization_id}",
283 | "conversation_uuid": f"{conversation_id}",
284 | "title": f"{title}"
285 | })
286 | headers = {
287 | 'User-Agent':
288 | 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0',
289 | 'Accept-Language': 'en-US,en;q=0.5',
290 | 'Content-Type': 'application/json',
291 | 'Referer': 'https://claude.ai/chats',
292 | 'Origin': 'https://claude.ai',
293 | 'Sec-Fetch-Dest': 'empty',
294 | 'Sec-Fetch-Mode': 'cors',
295 | 'Sec-Fetch-Site': 'same-origin',
296 | 'Connection': 'keep-alive',
297 | 'Cookie': f'{self.cookie}',
298 | 'TE': 'trailers'
299 | }
300 |
301 | response = requests.post(url, headers=headers, data=payload,impersonate="chrome110")
302 |
303 | if response.status_code == 200:
304 | return True
305 | else:
306 | return False
307 |
308 |
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | from setuptools import setup, find_packages
2 | from pathlib import Path
3 | base_path = Path(__file__).parent
4 | long_description = (base_path / "README.md").read_text()
5 |
6 |
7 | setup(
8 | name='claude-api',
9 | version='1.0.17',
10 | author='Koushik',
11 | license="MIT",
12 | author_email='koushikk@outlook.com',
13 | description='An unofficial API for Claude AI, allowing users to access and interact with Claude AII',
14 | long_description=long_description,
15 | long_description_content_type='text/markdown',
16 | url='https://github.com/KoushikNavuluri/Claude-API/',
17 | packages=find_packages(),
18 | classifiers=[
19 | 'Development Status :: 5 - Production/Stable',
20 | 'Intended Audience :: Developers',
21 | 'License :: OSI Approved :: MIT License',
22 | 'Programming Language :: Python :: 3.7',
23 | 'Programming Language :: Python :: 3',
24 | 'Operating System :: Unix',
25 | 'Operating System :: MacOS :: MacOS X',
26 | 'Operating System :: Microsoft :: Windows',
27 | ],
28 | package_dir={
29 | "": "claude-api"
30 | },
31 | py_modules=["claude_api"],
32 | keywords=['claude', 'ai', 'claude-ai', 'API', 'requests', 'chatbot'],
33 | install_requires=[
34 | 'requests','curl_cffi'
35 | ],
36 | python_requires=">=3.7",
37 | )
38 |
--------------------------------------------------------------------------------
/usecases/console_chat.py:
--------------------------------------------------------------------------------
1 | import os
2 | from claude_api import Client
3 |
4 | def get_cookie():
5 | cookie = os.environ.get('cookie')
6 | if not cookie:
7 | raise ValueError("Please set the 'cookie' environment variable.")
8 | return cookie
9 |
10 | def main():
11 | cookie = get_cookie()
12 | claude = Client(cookie)
13 | conversation_id = None
14 |
15 | print("Welcome to Claude AI Chat!")
16 |
17 | while True:
18 | user_input = input("You: ")
19 |
20 | if user_input.lower() == 'exit':
21 | print("Thank you!")
22 | break
23 |
24 | if not conversation_id:
25 | conversation = claude.create_new_chat()
26 | conversation_id = conversation['uuid']
27 |
28 | response = claude.send_message(user_input, conversation_id)
29 | print("Chatbot:", response)
30 |
31 | if __name__ == "__main__":
32 | main()
33 |
--------------------------------------------------------------------------------