Unofficial API for Claude-2 via Claude Web (Also CLI)
Unofficial API for Claude-2 via Claude Web (Also CLI)
[!IMPORTANT] 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
This is a lightweight (isomorphic, 0 dependency) JavaScript library for interacting with the Claude AI chatbot's unofficial internal API. CLI installation, API installation + usage
Psst. It can also code full projects and output valid JSON
Start new conversations
Upload files
Unit tests included with 85% coverage of code and 100% pass rates!
Isomorphic (supposing you setup a proxy, cors make me sad)
Async/await ready with modern syntax
Get and respond to existing conversations
Upcoming
CLI: Retrying responses, Reflexion implementation, prompt templates, auto conversation saving
API: Better error handling, automated unit tests, caching layer, searching, , hooks for events, used tokens count (percentage/raw), token estimator, setActiveModel, list available models, send message directly to existing conversationavailable tokens for model
Supports all claude models (claude-2, claude-1.3, claude-instant-100k - See --model flag)
npm install claude-ainpm install -g claude-cliNote Run
claude --helpor see CLI_DOCS.md for more info about the CLI
First, import the library:
const Claude = require('claude-ai'); Initialize a new Claude instance with your session key:
Note Get
sessionKeyfrom thesessionKeycookie via the Claude website.
const claude = new Claude({
sessionKey: 'YOUR_SESSION_KEY'
});Start a conversation by calling startConversation() with a prompt message (or get existing conversations via .getConversations()):
const conversation = await claude.startConversation('Hello Claude!');The Conversation instance exposes methods like sendMessage() to continue the chat:
await conversation.sendMessage('How are you today?');The full code would look like:
const Claude = require('claude-ai');
const claude = new Claude({
sessionKey: 'YOUR_SESSION_KEY'
});
await claude.init();
const conversation = await claude.startConversation('Hello Claude!');
await conversation.sendMessage('How are you today?');See the documentation below for the full API reference.
ClaudeThe main class for interfacing with the Claude API.
Constructor:
const claude_instance = new Claude({
sessionKey: string,
proxy: string | ({endpoint, options}) => ({endpoint, options})
})claude.request functionnn (see source for more info)proxy is a string, it will simply be prepended before the API endpoint, example: https://claude.ai/Parameters:
sessionKey - Your Claude sessionKey cookieMethods (on an instance):
startConversation(prompt) - Starts a new conversation with the given prompt messagegetConversations() - Gets recent conversationsclearConversations() - Clear all conversationsuploadFile(file) - Uploads a fileConversationReturned by Claude.startConversation().
Methods:
sendMessage(message, options) - Sends a followup message in the conversation getInfo() - Gets the conversation (includes messages, name, created_at, update_at, etc)delete() - Delete the conversation (returns fetch response)SendMessage Options:
timezone - The timezone for completion attachments - Array of file attachments 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)done - Callback when completedprogress - Progress callbackContributions welcome! This library was created by @Explosion-Scratch on GitHub. Please submit PRs to help improve it.
No open issues yet, or sync has not completed.