npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

claude-ai

v1.2.2

Published

Unofficial library for interacting with Claude AI

Downloads

461

Readme

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

  • 💬 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, ~~setActiveModel, list available models, send message directly to existing conversation~~, hooks for events, used tokens count (percentage/raw), token estimator, ~~available tokens for model~~
  • 💪 Supports all claude models (claude-2, claude-1.3, claude-instant-100k - See --model flag)

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})
})
  • 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)
  • If proxy is a string, it will simply be prepended before the API endpoint, example: https://claude.ai/

Parameters:

  • sessionKey - Your Claude sessionKey cookie

Methods (on an instance):

  • startConversation(prompt) - Starts a new conversation with the given prompt message
  • getConversations() - Gets recent conversations
  • clearConversations() - Clear all conversations
  • uploadFile(file) - Uploads a file

Conversation

Returned 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 completed
  • progress - Progress callback

Contributing

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