本项目提供了Claude AI的非官方API,允许用户访问和与Claude AI进行交互。
<img src="https://github.com/KoushikNavuluri/Claude-API/assets/103725723/385fa539-e725-4c20-86ff-0864e6ffab82" width="400">1. Python控制台聊天机器人(在usecases文件夹中查看示例控制台聊天机器人)
2. Discord聊天机器人
3. 还可以做更多...
要使用此API,您需要满足以下条件:
在您的系统上安装Python 安装requests库
pip install requests
要使用Claude AI非官方API,您可以克隆GitHub存储库或直接下载Python文件。
终端:
pip install claude-api
或
克隆存储库:
git clone https://github.com/KoushikNavuluri/Claude-API.git
在您的Python脚本中导入claude_api模块:
from claude_api import Client
接下来,您需要通过提供Claude AI的cookie来创建Client类的实例:
您可以从浏览器的开发者工具网络标签中获取cookie(查看任何claude.ai请求的cookie,复制整个值)或存储标签(您可以找到claude.ai的cookie,会有四个值)
(查看下面的图片了解cookie的格式,从网络标签获取cookie更容易)
cookie = os.environ.get('cookie')
claude_api = Client(cookie)
要列出您与Claude进行的所有对话ID,可 以使用list_all_conversations方法:
conversations = claude_api.list_all_conversations()
for conversation in conversations:
conversation_id = conversation['uuid']
print(conversation_id)
要向Claude发送消息,可以使用send_message方法。您需要提供提示和对话ID:
prompt = "你好,Claude!"
conversation_id = "<conversation_id>"或claude_api.create_new_chat()['uuid']
response = claude_api.send_message(prompt, conversation_id)
print(response)
您可以使用send_message()中的attachment参数向Claude发送任何类型的附件以获取响应。 注意:Claude目前只支持某些文件类型。
{如果需要,您还可以使用timeout参数设置超时时间[默认设置为500]}
prompt = "嘿,给我总结一下这个文档!"
conversation_id = "<conversation_id>"或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方法:
conversation_id = "<conversation_id>"
deleted = claude_api.delete_conversation(conversation_id)
if deleted:
print("对话删除成功")
else:
print("删除对话失败")
要获取聊天对话历史,可以使用chat_conversation_history方法:
conversation_id = "<conversation_id>"
history = claude_api.chat_conversation_history(conversation_id)
print(history)
要创建新的聊天对话(ID),可以使用create_new_chat方法:
new_chat = claude_api.create_new_chat()
conversation_id = new_chat['uuid']
print(conversation_id)
要重置所有对话,可以使用reset_all方法:
reset = claude_api.reset_all()
if reset:
print("所有对话重置成功")
else:
print("重置对话失败")
要重命名聊天对话,可以使用rename_chat方法:
conversation_id = "<conversation_id>"
title = "新聊天标题"
renamed = claude_api.rename_chat(title, conversation_id)
if renamed:
print("聊天对话重命名成功")
else:
print("重命名聊天对话失败")
本项目提供Claude AI的非官方API,与Claude AI或Anthropic没有关联或得到其认可。使用风险自负。
请参考官方Claude AI文档[https://claude.ai/docs]以获取有关如何使用Claude AI的更多信息。


职场AI,就用扣子
AI办公助手,复杂任务高效处理。办公效率低?扣子空间AI助手支持播客生成、PPT制作、网页开发及报告写作,覆盖科研、商业、舆情等领域的专家Agent 7x24小时响应,生活工作无缝切换,提升50%效率!


多风格AI绘画神器
堆友平台由阿里巴巴设计团队 创建,作为一款AI驱动的设计工具,专为设计师提供一站式增长服务。功能覆盖海量3D素材、AI绘画、实时渲染以及专业抠图,显著提升设计品质和效率。平台不仅提供工具,还是一个促进创意交流和个人发展的空间,界面友好,适合所有级别的设计师和创意工作者。

