{"id":13433525,"url":"https://github.com/Explosion-Scratch/claude-unofficial-api","last_synced_at":"2025-03-17T12:31:57.614Z","repository":{"id":181051726,"uuid":"666140407","full_name":"Explosion-Scratch/claude-unofficial-api","owner":"Explosion-Scratch","description":"Unofficial API for Claude-2 via Claude Web (Also CLI)","archived":false,"fork":false,"pushed_at":"2023-08-21T21:35:18.000Z","size":5940,"stargazers_count":740,"open_issues_count":4,"forks_count":82,"subscribers_count":9,"default_branch":"main","last_synced_at":"2024-03-29T09:21:02.254Z","etag":null,"topics":["api","claude","cli","gpt","llm","node","unofficial"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/claude-ai","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Explosion-Scratch.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":"ROADMAP.md","authors":null}},"created_at":"2023-07-13T20:07:11.000Z","updated_at":"2024-03-29T03:08:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"69011f27-ab33-4d73-9639-4facd1648c5f","html_url":"https://github.com/Explosion-Scratch/claude-unofficial-api","commit_stats":null,"previous_names":["explosion-scratch/claude-unofficial-api"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Explosion-Scratch%2Fclaude-unofficial-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Explosion-Scratch%2Fclaude-unofficial-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Explosion-Scratch%2Fclaude-unofficial-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Explosion-Scratch%2Fclaude-unofficial-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Explosion-Scratch","download_url":"https://codeload.github.com/Explosion-Scratch/claude-unofficial-api/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244033867,"owners_count":20387015,"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":["api","claude","cli","gpt","llm","node","unofficial"],"created_at":"2024-07-31T02:01:28.257Z","updated_at":"2025-03-17T12:31:54.161Z","avatar_url":"https://github.com/Explosion-Scratch.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","API Wrappers"],"sub_categories":["Node.js"],"readme":"\u003e [!IMPORTANT]\n\u003e Claude seems to have blocked all non-browser traffic to their internal API – Effectively rendering this project useless. **If you have a fix/method to get around this please PR**. Sorry – [@Explosion-Scratch](https://github.com/Explosion-Scratch)\n\n\n\n\u003ch1\u003e\u003cdiv align=center\u003e\u003ca href=\"https://github.com/explosion-scratch/claude-unofficial-api\"\u003eclaude-unofficial-api\u003c/a\u003e\u003c/div\u003e\u003c/h1\u003e\n\nhttps://github.com/Explosion-Scratch/claude-unofficial-api/assets/61319150/6c3f706d-bddf-42e6-9745-aa1f7561ca40\n\nThis is a lightweight (isomorphic, 0 dependency) JavaScript library for interacting with the [Claude AI](https://www.claude.ai/) chatbot's unofficial internal API. [CLI installation](#cli-installation), [API installation + usage](#usage)\n\n\u003e _Psst. It can also [code full projects](https://github.com/Explosion-Scratch/claude-unofficial-api/blob/main/examples/coding.md) and [output valid JSON](https://github.com/Explosion-Scratch/claude-unofficial-api/blob/main/examples/json.md)_\n\n## Features\n- 💬 Start new conversations\n- 📎 Upload files\n- 🧪 [Unit tests included with 85% coverage of code and 100% pass rates!](https://github.com/Explosion-Scratch/claude-unofficial-api/assets/61319150/b65d32f4-2b43-4bc3-8e2c-4cf977fe7e89)\n \n- 🌎 Isomorphic (supposing you setup a proxy, cors make me sad)\n- 🔄 Async/await ready with modern syntax\n- 💾 Get and respond to existing conversations\n- 🚀 Upcoming\n  - CLI: ~~Retrying responses, [Reflexion](https://arxiv.org/abs/2303.11366) implementation, prompt templates~~, auto conversation saving\n  - API: ~~Better error handling, automated unit tests~~, caching layer, searching, ~~`setActiveModel`, list available models, send message directly to existing conversation~~, hooks for events, used tokens count (percentage/raw), token estimator, ~~available tokens for model~~\n- 💪 Supports all claude models (`claude-2`, `claude-1.3`, `claude-instant-100k` - See `--model` flag)\n\n\n## Installation\n\n```\nnpm install claude-ai\n```\n\n## CLI installation\n```\nnpm install -g claude-cli\n```\n\u003e **Note**\n\u003e Run `claude --help` or see [CLI_DOCS.md](CLI_DOCS.md) for more info about the CLI\n\n## Usage\n\nFirst, import the library:\n\n```js\nconst Claude = require('claude-ai'); \n```\n\nInitialize a new Claude instance with your session key:\n\n\u003e **Note**\n\u003e Get `sessionKey` from the `sessionKey` cookie via the Claude website.\n\n```js\nconst claude = new Claude({\n  sessionKey: 'YOUR_SESSION_KEY' \n});\n```\n\nStart a conversation by calling `startConversation()` with a prompt message (or get existing conversations via `.getConversations()`):\n\n```js\nconst conversation = await claude.startConversation('Hello Claude!');\n```\n\nThe `Conversation` instance exposes methods like `sendMessage()` to continue the chat:\n\n```js \nawait conversation.sendMessage('How are you today?');\n```\n\nThe full code would look like:\n\n```js\nconst Claude = require('claude-ai');\n\nconst claude = new Claude({\n  sessionKey: 'YOUR_SESSION_KEY'\n});\n\nawait claude.init();\n\nconst conversation = await claude.startConversation('Hello Claude!');\n\nawait conversation.sendMessage('How are you today?');\n```\n\nSee the [documentation](#documentation) below for the full API reference.\n\n## Documentation\n\n### `Claude`\n\nThe main class for interfacing with the Claude API.\n\n**Constructor:**\n```js\nconst claude_instance = new Claude({\n  sessionKey: string,\n  proxy: string | ({endpoint, options}) =\u003e ({endpoint, options})\n})\n```\n\n- If proxy is a function it will be passed the API route to fetch as well as the fetch options which can then be manipulated before running through fetch. If you're feeling adventurous you could also just modify the `claude.request` functionnn (see source for more info)\n- If `proxy` is a string, it will simply be prepended before the API endpoint, example: `https://claude.ai/` \n\n**Parameters:**\n\n- `sessionKey` - Your Claude `sessionKey` cookie \n\n**Methods (on an instance):**\n\n- `startConversation(prompt)` - Starts a new conversation with the given prompt message\n- `getConversations()` - Gets recent conversations\n- `clearConversations()` - Clear all conversations\n- `uploadFile(file)` - Uploads a file \n\n### `Conversation`\n\nReturned by `Claude.startConversation()`. \n\n**Methods:**\n\n- `sendMessage(message, options)` - Sends a followup message in the conversation  \n- `getInfo()` - Gets the conversation (includes messages, name, created_at, update_at, etc)\n- `delete()` - Delete the conversation (returns fetch response)\n\n**SendMessage Options:**\n\n- `timezone` - The timezone for completion \n- `attachments` - Array of file attachments \n- `model` - The Claude model to use (default: `claude-2`, other models that I know of include `claude-1.3`, and `claude-instant-100k`. Seems to also accept `claude-1` but transform it to `claude-1.3`)\n- `done` - Callback when completed\n- `progress` - Progress callback\n\n## Contributing\n\nContributions welcome! This library was created by @Explosion-Scratch on GitHub. Please submit PRs to help improve it.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FExplosion-Scratch%2Fclaude-unofficial-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FExplosion-Scratch%2Fclaude-unofficial-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FExplosion-Scratch%2Fclaude-unofficial-api/lists"}