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 🙏

© 2026 – Pkg Stats / Ryan Hefner

qwen-api

v0.1.0

Published

Unofficial Qwen Chat API client for Node.js and TypeScript

Readme

qwen-api

Unofficial Qwen Chat API client for Node.js and TypeScript.

Install

To use this package, you need to install the dependencies by running the following command:

npm install qwen-api

Setup

You need to set up the API token and other configurations by storing them in a .env file in the root of your project directory. Example of a .env file:

QWEN_AUTH_TOKEN=your_auth_token_here
QWEN_COOKIE=your_cookie_here

Make sure to replace your_auth_token_here and your_cookie_here with your valid authentication token and cookie.

Usage Examples

1. Using the Streaming API

In streaming mode, you can receive data incrementally as the request is being processed.

import { QwenClient } from 'qwen-api';
import 'dotenv/config';

async function main() {
    const client = new QwenClient();
    const stream = await client.completion.create({
        messages: [{
            role: "user",
            content: "What is the capital of Indonesia?",
            web_search: false,
            thinking: false
        }],
        model: "qwen-max-latest",
        stream: true,
    });

    console.log(`User: What is the capital of Indonesia?`);
    console.log(`Assistant:`);
    if (stream instanceof ReadableStream) {
        for await (const chunk of stream) {
            process.stdout.write(chunk.delta?.content || '');
        }
    } else {
        console.error('Stream is not a ReadableStream');
    }
}

main().catch(console.error);

2. Using the Non-Streaming API

If you prefer to get the response directly without streaming, you can use the non-streaming mode as shown below:

import { QwenClient } from 'qwen-api';
import 'dotenv/config';

async function main() {
    const client = new QwenClient();
    const response = await client.completion.create({
        messages: [{
            role: "user",
            content: "What is the capital of Indonesia?",
            web_search: false,
            thinking: false
        }],
        model: "qwen-max-latest",
        stream: false,
    });

    console.log(response);
}

main().catch(console.error);

API Reference

QwenClient

The main class to interact with the Qwen API.

QwenClient.completion.create(options: CompletionOptions)

This method sends a request to the Qwen API.

  • options: The request configuration object.

    • messages: An array of messages to send.

      • role: The role of the message sender, either "user" or "assistant".
      • content: The content of the message.
      • web_search: Whether to perform a web search (default: false).
      • thinking: Whether the model is processing its thoughts (default: false).
    • model: The name of the model being used, e.g., "qwen-max-latest".

    • stream: true for streaming, false for immediate response.

Example Response

For streaming mode, data is received incrementally through a ReadableStream. If not using streaming, the response will be in the form of a JSON object containing the result of the request.

Testing

You can run the tests provided to verify everything is working as expected:

npm run test:client
npm run test:stream

Make sure your .env file is configured correctly with a valid API key.