# huggingface-chat

> A lightweight and powerful Node.js API client for Hugging Face Chat. Interact with open-source LLMs like Llama 3, Mixtral, and Gemma for conversational AI, text generation, and more. Supports ESM and CJS modules.

Latest version **4.1.2** (published 2025-05-24) · ISC license · 0 weekly downloads

## Install

```sh
npm install huggingface-chat
pnpm add huggingface-chat
yarn add huggingface-chat
bun add huggingface-chat
```

## Health

**Score 50/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 4.1.2 |
| Published | 2025-05-24 |
| First published | 2023-09-03 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18.17 |
| Dependencies | 0 |
| Unpacked size | 101.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Author | Rahul Sharma |
| Maintainers | srahul0_0 |
| Keywords | huggingface, huggingface-chat, chat-api, llm, conversational-ai, ai, machine-learning, llama, llama-3, mixtral, gemma, typescript, text-generation, api-client |

## Links

- npm: https://www.npmjs.com/package/huggingface-chat
- Repository: https://github.com/rahulsushilsharma/huggingface-chat
- Homepage: https://github.com/rahulsushilsharma/huggingface-chat#readme
- Issues: https://github.com/rahulsushilsharma/huggingface-chat/issues
- npm.io page: https://npm.io/package/huggingface-chat

## Alternatives

- [@expo/fingerprint](https://npm.io/package/@expo/fingerprint.md) — 6.2M weekly downloads
- [@azure/monitor-opentelemetry-exporter](https://npm.io/package/@azure/monitor-opentelemetry-exporter.md) — 850.0K weekly downloads
- [@azure/monitor-opentelemetry](https://npm.io/package/@azure/monitor-opentelemetry.md) — 624.0K weekly downloads
- [@posthog/ai](https://npm.io/package/@posthog/ai.md) — 423.3K weekly downloads
- [fakefilter](https://npm.io/package/fakefilter.md) — 63.9K weekly downloads

## Recent versions

- 4.1.2 (latest) — 2025-05-24
- 4.1.1 — 2025-05-17
- 4.0.1 — 2024-12-08
- 4.0.0 — 2024-12-08
- 3.0.7 — 2024-11-20
- 3.0.6 — 2024-11-15
- 3.0.5 — 2024-11-15
- 3.0.4 — 2024-06-09
- 3.0.3 — 2024-06-08
- 3.0.2 — 2024-05-04
- 3.0.1 — 2024-04-27
- 3.0.0 — 2024-04-23
- 2.1.0 — 2024-04-18
- 2.0.9 — 2024-02-13
- 2.0.8 — 2024-02-08
- … 17 more at https://npm.io/package/huggingface-chat/versions

## README

**Deprecation Notice**

> The versions 2.x and lower are deprecated please use latest.
 
# Huggingface chat api 
A simple api for hugging face chat with login caching.

## Installation

Current stable release (`4.x`) 
> Added tools support 🎉

```sh
npm i huggingface-chat
``` 


## Example usage 
```js

import { Login ,ChatBot} from "huggingface-chat";

const EMAIL = "email"
const PASSWD = "password"
const cachePath = "./login_cache/"
const signin = new Login(EMAIL, PASSWD)
const res = await signin.login(cachePath) // default path is ./login_cache/
const chat = new ChatBot(res) // res is cookies which is required for subsequent aip calls

await chat.intialize()

const models = chat.listAvilableModels()
console.log(models)


const sessons = chat.listAvilableSesson()
console.log(sessons)

// more info : https://huggingface.co/chat/models
let currentModel = chat.showCurrentModel()
console.log(currentModel)


chat.switchModel("microsoft/Phi-3.5-mini-instruct")

currentModel = chat.showCurrentModel()
console.log(currentModel)

const currentChat = await chat.getNewChat("you are a drunk person") // optional if you want to set a system prompt
console.log(currentChat)

const tools = await chat.getToolList("1") // for the sake of not overloading the api the tools need to be called when needed also pass the page number more info : https://huggingface.co/chat/tools
console.log(tools)

let data  = await chat.chat("take screenshoot of this website : google.com", undefined, {
	tools:["000000000000000000000001","66e99753cb638fb7e2342da5"], // pass the tools id tools[0].id
	rawResponse:true
}); 

let  reader  =  data.stream.getReader();
while (true) {
	const  {  done,  value  }  =  await  reader.read();
	if (done) break;  // The streaming has ended.
	process.stdout.write(value)
}


data = await chat.chat("what is my name"); 
let response = await data.completeResponsePromise() //non streaming response 
console.log(response)

data = await chat.chat("what is my name", sessons[0].id); // using existing sessons
response = await data.completeResponsePromise()
console.log(response)



```


>Note: Supported in node 18.x and higher.

>Note: In case the package stops working there is most likely a change in hugging face api, if possible please report it and update the package to latest if available.

## Documentations

Full API documentations of both classes can be found here [Chat](./docs/chat.md) [Login](./docs/login.md)


## Contributions

- If you happen to see missing feature or a bug, feel free to open an [issue](https://github.com/rahulsushilsharma/huggingface-chat/issues).
- Pull requests are welcomed too!

## License

[MIT](LICENSE.md)

---
_Source: https://npm.io/package/huggingface-chat · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
