ClaudeAI-api

A Python package provides an unofficial api for interacting with the Claude from Anthropic


Keywords
claude, ai, claude-ai, API, requests, chatbot, anthropic, anthropic-claude, claude-api, nlp
License
MIT
Install
pip install ClaudeAI-api==0.1.0

Documentation

Claude 2 API ( Unofficial )

This project provides an unofficial API for Claude 2 from Anthropic, allowing users to access and interact with Claude AI and trying out experiments with the same.

The python package that returns response of Claude 2 through value of cookie.

Please exercise caution and use this package responsibly.

I referred to this github repository(https://github.com/KoushikNavuluri/Claude-API) where inference process of Claude was reverse engineered. Using SessionKey cookie, you can ask questions and get answers from Claude 2. Please note that the claude 2 api is not a free service, but rather a tool provided to assist developers with testing certain functionalities due to the delayed development and release of Anthropic's Claude 2 free API. It has been designed with a lightweight structure that can easily adapt to the emergence of an official API. Therefore, I strongly discourage using it for any other purposes. If you have access to official Claude-2 API, replace the provided response with the corresponding official code.


Installation

To use the Claude 2 Unofficial API, you can either pip install or clone the GitHub repository or directly download the Python file.

Terminal :

pip install claude2

or

Clone the repository:

git clone https://github.com/Nipun1212/Claude_api.git

Authentication

Warning Do not expose the sessionKey cookie

  1. Visit https://claude.ai/
  2. F12 for console
  3. Network: organizations → Request Headers → Copy the whole value of Cookie.

Note that while I referred to sessionKey value as an API key for convenience, it is not an officially provided API key. Cookie value subject to frequent changes. Verify the value again if an error occurs. Most errors occur when an invalid cookie value is entered.


Usage

Import the Claude AI module in your Python script:

from claude import Claude
  • 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 = 'sesionKEY=.....'
    
      claude = Claude(cookie)
    

Send Message

To send a message to Claude, you can use the get_answer method. It finds your most recent conversation, and if it doesn't exist, it automatically creates a new conversation, and uses it to chat with the model.

prompt = "Hello, Claude!"
response=claude.get_answer(prompt)
print(response)

Create New Chat

To create a new chat conversation , you can use the create_new_conversation method:

claude.create_new_conversation()
response=claude.get_answer("Hi, what are you?")
print(response)

License

MIT
We hold no legal responsibility; for more information, please refer to the bottom of the readme file. We just want you to give me and them a star.

The MIT License (MIT)

Copyright (c) 2023 Nipun Bhatia

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

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.

Reference

[1] https://github.com/KoushikNavuluri/Claude-API

Warning Important Notice The user assumes all legal responsibilities associated with using the BardAPI package. This Python package merely facilitates easy access to Google Bard for developers. Users are solely responsible for managing data and using the package appropriately. For further information, please consult the Google Bard Official Document.

Warning Caution This Python package is not an official Google package or API service. It is not affiliated with Google and uses Google account cookies, which means that excessive or commercial usage may result in restrictions on your Google account. The package was created to support developers in testing functionalities due to delays in the official Google package. However, it should not be misused or abused. Please be cautious and refer to the Readme for more information.



*Copyright (c) 2023 Nipun Bhatia *