{"id":13562977,"url":"https://github.com/AshwinPathi/claude-api-py","last_synced_at":"2025-04-03T19:32:00.069Z","repository":{"id":181563017,"uuid":"666913227","full_name":"AshwinPathi/claude-api-py","owner":"AshwinPathi","description":"Unofficial Python API for Anthropic's Claude LLM","archived":false,"fork":false,"pushed_at":"2024-04-25T07:44:12.000Z","size":39,"stargazers_count":100,"open_issues_count":7,"forks_count":11,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-25T08:42:46.885Z","etag":null,"topics":["ai","api","bot","chatbot","claude","claude-ai","claude-api","gpt","llm","python","unofficial"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/claude-api-py/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AshwinPathi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-16T02:35:24.000Z","updated_at":"2024-06-28T03:56:58.842Z","dependencies_parsed_at":"2024-04-25T08:52:36.008Z","dependency_job_id":null,"html_url":"https://github.com/AshwinPathi/claude-api-py","commit_stats":null,"previous_names":["ashwinpathi/claude","ashwinpathi/claude-api-py"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AshwinPathi%2Fclaude-api-py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AshwinPathi%2Fclaude-api-py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AshwinPathi%2Fclaude-api-py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AshwinPathi%2Fclaude-api-py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AshwinPathi","download_url":"https://codeload.github.com/AshwinPathi/claude-api-py/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247065329,"owners_count":20877758,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","api","bot","chatbot","claude","claude-ai","claude-api","gpt","llm","python","unofficial"],"created_at":"2024-08-01T13:01:13.912Z","updated_at":"2025-04-03T19:31:59.803Z","avatar_url":"https://github.com/AshwinPathi.png","language":"Python","funding_links":[],"categories":["Python","API Wrappers"],"sub_categories":["Python"],"readme":"# Unofficial Claude API For Python\n\nThe UNOFFICIAL free API for Anthropic's Claude LLM.\n\n## Background\n\nClaude is [Anthropic's](https://www.anthropic.com/) LLM app (similar to ChatGPT). This library allows you to use the API (for free) and interact with it in your python projects.\n\n## Implemented actions:\nThe Unofficial Claude API is under active development. The following endpoints are usable in some capacity:\n\n- Getting organizations you're in\n- Getting conversations you're in\n- Starting a conversation\n- Sending a message and receiving a response\n- Delete a conversation\n- Create an attachment from a file\n- Send attachments\n- getting message history\n\nNote that the api is __**synchronous**__.\n\n## TODO features\n- Tests\n- Fixing models OTHER than `claude_2`\n- asynchronous mode\n- Better caching\n- cleaner errors and passing these up to users\n\n\nThis project is under active development and is extremely unstable, so there are no guarantees it will work for you. If you find a bug or you think it should work in a scenario where it doesn't, file an issue.\n\n\n## Usage\n\n### Step 1\nInstall the library using the following:\n```\npip install claude-api-py\n```\n\nIf that doesn't work, you can install directly from this github repository:\n\n```\npip install git+git://github.com/AshwinPathi/claude-api-py.git\n```\n\nThere is one requirement as of now:\n- `sseclient-py` [link here](https://github.com/mpetazzoni/sseclient)\n\n\n### Step 2\nGet a `sessionKey` from the Claude website. You will need this to start the bot. Ideally also have a user agent of the computer you use to access claude.\n\nYou can get this information by logging into `https://claude.ai/chats` and doing the following:\n\n1. open inspect element (f12 on chrome)\n2. On the top bar, go to the `Application` tab.\n3. Under `Storage`, go to `Cookies`.\n4. look for a cookie called `https://claude.ai`, click it.\n5. click the `sessionKey` field, and copy the session key down. It should begin with `sk-ant-sid01...`\n\n\n### Step 3\nUse the bot. You can see an example at `example.py`.\n\n### Examples:\n\n#### Importing the necessary libraries\n```py\n# The ClaudeClient is the raw API that gives you access to all organization and conversation level API calls\n# with a simple python interface. However, you have to pass organization_uuid and conversation_uuid everywhere, so\n# its not ideal if you want a simple to use API.\nfrom claude import claude_client\n\n# The ClaudeWrapper takes in a claude client instance and allows you to use a single organization and conversation\n# context. This allows you to use the API more ergonomically.\nfrom claude import claude_wrapper\n```\n\n#### Create the client and wrapper\n```py\nclient = claude_client.ClaudeClient(SESSION_KEY)\n\norganizations = client.get_organizations()\n# You can omit passing in the organization uuid and the wrapper will assume\n# you will use the first organization instead.\nclaude_obj = claude_wrapper.ClaudeWrapper(client, organization_uuid=organizations[0]['uuid'])\n```\n\n#### Starting a new conversation\n```py\nnew_conversation_data = claude_obj.start_new_conversation(\"New Conversation\", \"Hi Claude!\")\nconversation_uuid = new_conversation_data['uuid']\n# You can get the response from the initial message you sent with:\ninitial_response = new_conversation_data['response']\n# You can get the title of the new chat you created with this:\nchat_title = new_conversation_data['title']\n```\n\n#### Send a message (passing in the client uuid)\n```py\nconversation_uuid = claude_obj.get_conversations()[0]['uuid']\nresponse = claude_obj.send_message(\"How are you doing today!\", conversation_uuid=conversation_uuid)\n```\n\n#### Setting a conversation context and sending a message\n```py\nconversation_uuid = claude_obj.get_conversations()[0]['uuid']\n# This is so you don't have to constantly pass in conversation uuid on every call that requires it.\n# anywhere that has an argument conversation_uuid=X can be omitted if you set the conversation context.\nclaude_obj.set_conversation_context(conversation_uuid)\n\nresponse = claude_obj.send_message(\"How are you doing today!\")\nresponse = claude_obj.send_message(\"Who won the league of legends worlds 2022 finals?\")\n```\n\n#### Sending an attachment\n```py\n# This generates an attachment in the right format\nattachment = claude_obj.get_attachment('example_attachment.txt')\nresponse = claude_obj.send_message(\"Hi Claude, what does this attachment say?\", attachments=[attachment],\n                                    conversation_uuid = conversation_uuid)\n```\n\n#### Deleting a conversation\n```py\ndeleted = claude_obj.delete_conversation(conversation_uuid)\n```\n\n#### Deleting all conversations in an organization\n```py\nfailed_deletions = claude_obj.delete_all_conversations()\nassert len(failed_deletions) == 0\n```\n\n#### Renaming a conversation\n```py\nconversation = claude_obj.rename_conversation(\"New name\", conversation_uuid = conversation_uuid)\n```\n\n#### Get conversation history\n```py\nconversation_history = claude_obj.get_conversation_info(conversation_uuid = conversation_uuid)\n```\n\n\n## Disclaimer\nThis library is for purely educational purposes and is UNOFFICIAL. I am not responsible if your account gets banned. If you would like to use the actual API, go to [anthropic website](https://docs.anthropic.com/claude/docs).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAshwinPathi%2Fclaude-api-py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAshwinPathi%2Fclaude-api-py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAshwinPathi%2Fclaude-api-py/lists"}