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

dashscope-sdk-official

v1.25.3

Published

Official Node.js SDK for Alibaba Cloud Model Studio (DashScope) APIs

Readme

DashScope Node.js SDK

阿里云百炼 / Model Studio(DashScope) 的官方 Node.js 客户端。能力集尽可能与 Python SDK 对齐。

安装

npm install dashscope-sdk-official

克隆本仓库后本地开发:

npm install
npm run build

默认 npm test 使用 nock 模拟 HTTP,不访问真实服务。

若要用真实 DashScope HTTP API 跑同一套用例(会创建真实任务/文件/任务并计费),请设置密钥后执行:

export DASHSCOPE_API_KEY='你的密钥'
npm run test:live

可将 .env.example 复制为 .envtest/nock-hooks.cjs 会加载其中的 DASHSCOPE_API_KEY(供 test:live 使用)。

WebSocket 语音合成用例(test/audio/tts.test.ts)在未使用 test:live 时会 跳过;只有 test:live 会跑真实服务(可能计费)。

发布包同时提供 CommonJSlib/index.js)与 ESMlib/index.mjs),由 package.jsonexportsrequire / import 解析。

快速开始

const { Configuration, DashscopeApi } = require('dashscope-sdk-official');

const configuration = new Configuration({
  apiKey: process.env.DASHSCOPE_API_KEY || 'YOUR-DASHSCOPE-API-KEY',
});

const api = new DashscopeApi(configuration);

const result = await api.createGeneration({
  model: 'qwen-turbo',
  prompt: '今天天气好吗?',
  stream: true,
});

for await (const chunk of result) {
  console.log(chunk.output);
}

ESM(Node 18+):

import { Configuration, DashscopeApi } from 'dashscope-sdk-official';

const configuration = new Configuration({
  apiKey: process.env.DASHSCOPE_API_KEY || 'YOUR-DASHSCOPE-API-KEY',
});
const api = new DashscopeApi(configuration);

API Key

申请与使用方式见:Model Studio 文档

在代码中设置

const { Configuration } = require('dashscope-sdk-official');

const configuration = new Configuration({
  apiKey: 'YOUR-DASHSCOPE-API-KEY',
});

若不传 apiKey,SDK 会读取环境变量 DASHSCOPE_API_KEY

环境变量

export DASHSCOPE_API_KEY='YOUR-DASHSCOPE-API-KEY'

可选:

  • DASHSCOPE_HTTP_BASE_URL — HTTP API 根地址(默认 https://dashscope.aliyuncs.com/api/v1
  • DASHSCOPE_WEBSOCKET_BASE_URL — 流式语音 / TTS 等 WebSocket 根地址

功能概览

| 模块 | 说明 | |------|------| | Generation | 单轮 / 多轮文本生成,支持流式 | | Chat Completions | OpenAI 兼容的 chat/completions | | 代码生成 | 灵码等场景 | | 图像 / 视频合成 | 异步任务 + 轮询 | | 多模态对话 | 文本 + 图片等 | | 向量 | 文本、批量、多模态向量 | | 理解与重排 | NLU、rerank | | 文件 / 模型 / 部署 / 微调 | 资源与生命周期 API | | 语音 | 异步转写、实时 ASR、翻译、TTS(WebSocket + Qwen HTTP) | | Assistants & Threads | 线程、消息、Run 等 |

更多示例与字段说明见英文 README.md 或源码与 test/ 目录。

配置对象

const config = new Configuration({
  apiKey: 'YOUR-DASHSCOPE-API-KEY',
  basePath: 'https://dashscope.aliyuncs.com/api/v1',
  workspace: '可选的工作空间 ID',
});

返回结构

常见字段与 HTTP 信封一致:

  • request_id — 请求追踪 ID
  • status_code — 成功时一般为 200(以 SDK 归一化后的语义为准)
  • code / message — 错误时填充
  • output — 模型业务数据
  • usage — 用量(若接口返回)

变更记录

CHANGELOG.md。维护者发版流程(npm、打 tag、GitHub Release)见 docs/RELEASING.md

参与贡献

欢迎 Issue 与 PR。修改行为后请在本地执行 npm run lintnpm run typechecknpm run buildnpm test。调整 HTTP 行为时,请在 test/ 中同步更新对应的 nock 预期(模拟基址与辅助方法见 test/helpers/mockConfig.ts)。

许可证

Apache License 2.0,见 LICENSE