Explosion-Scratch / claude-unofficial-api

Unofficial API for Claude-2 via Claude Web (Also CLI)
https://npmjs.com/package/claude-ai
The Unlicense
730 stars 80 forks source link
api claude cli gpt llm node unofficial

[!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

claude-unofficial-api

https://github.com/Explosion-Scratch/claude-unofficial-api/assets/61319150/6c3f706d-bddf-42e6-9745-aa1f7561ca40

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

Features

Installation

npm install claude-ai

CLI installation

npm install -g claude-cli

Note Run claude --help or see CLI_DOCS.md for more info about the CLI

Usage

First, import the library:

const Claude = require('claude-ai'); 

Initialize a new Claude instance with your session key:

Note Get sessionKey from the sessionKey cookie 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.

Documentation

Claude

The main class for interfacing with the Claude API.

Constructor:

const claude_instance = new Claude({
  sessionKey: string,
  proxy: string | ({endpoint, options}) => ({endpoint, options})
})

Parameters:

Methods (on an instance):

Conversation

Returned by Claude.startConversation().

Methods:

SendMessage Options:

Contributing

Contributions welcome! This library was created by @Explosion-Scratch on GitHub. Please submit PRs to help improve it.