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

rertchat-ai-api

v1.0.0

Published

RertChat AI API Client - 方便地调用 RertChat AI API

Readme

RertChat AI API

RertChat AI API 客户端库,用于方便地调用 RertChat AI 聊天接口。

安装

npm install rertchat-ai-api
# 或
pnpm add rertchat-ai-api
# 或
yarn add rertchat-ai-api

快速开始

基础用法

import { RertChatClient } from 'rertchat-ai-api'

// 创建客户端实例
const client = new RertChatClient({
  apiKey: 'sk_xxx' // 替换为你的 API Key
})

// 发送消息
const response = await client.chat({
  messages: [{ role: 'user', content: '你好' }]
})

console.log(response.text)

便捷方法

import { createClient } from 'rertchat-ai-api'

const client = createClient('sk_xxx')

// 快速发送消息
const reply = await client.send('你好')
console.log(reply)

流式响应

import { RertChatClient } from 'rertchat-ai-api'

const client = new RertChatClient({ apiKey: 'sk_xxx' })

// 使用流式响应
const stream = client.chatStream({
  messages: [{ role: 'user', content: '你好' }]
})

for await (const chunk of stream) {
  process.stdout.write(chunk.text)
}

多轮对话

import { RertChatClient } from 'rertchat-ai-api'

const client = new RertChatClient({ apiKey: 'sk_xxx' })

const messages = [
  { role: 'user', content: '你好' },
  { role: 'assistant', content: '你好!有什么可以帮助你的吗?' },
  { role: 'user', content: '帮我写一首诗' }
]

const reply = await client.chatWithHistory(messages)
console.log(reply)

API 文档

RertChatClient

构造函数参数

  • apiKey (必需) - API Key
  • baseUrl (可选) - API 基础 URL,默认为 https://rertx.dpdns.org/api/v1
  • defaultModel (可选) - 默认模型,默认为 @cf/qwen/qwen3-30b-a3b-fp8
  • timeout (可选) - 请求超时时间(毫秒),默认为 60000

方法

chat(request: ChatRequest): Promise<ChatResponse>

发送聊天请求(非流式)

const response = await client.chat({
  messages: [
    { role: 'user', content: '你好' }
  ],
  model: '@cf/qwen/qwen3-30b-a3b-fp8',
  stream: false
})

console.log(response.text)
chatStream(request: ChatRequest): AsyncGenerator<StreamChunk>

发送聊天请求(流式)

const stream = client.chatStream({
  messages: [{ role: 'user', content: '你好' }]
})

for await (const chunk of stream) {
  console.log(chunk.text)
}
send(message: string, model?: string): Promise<string>

便捷方法,快速发送消息

const reply = await client.send('你好')
chatWithHistory(messages: ChatMessage[], model?: string): Promise<string>

多轮对话便捷方法

const messages = [
  { role: 'user', content: '你好' },
  { role: 'assistant', content: '你好!' },
  { role: 'user', content: '帮我写代码' }
]

const reply = await client.chatWithHistory(messages)

类型定义

ChatMessage

interface ChatMessage {
  role: 'user' | 'assistant'
  content: string
}

ChatRequest

interface ChatRequest {
  messages: ChatMessage[]
  model?: string
  stream?: boolean
}

ChatResponse

interface ChatResponse {
  message: ChatMessage
  text: string
}

StreamChunk

interface StreamChunk {
  text: string
  done: boolean
}

环境变量

推荐将 API Key 存储在环境变量中:

# .env
RERTCHAT_API_KEY=sk_xxx
const client = new RertChatClient({
  apiKey: process.env.RERTCHAT_API_KEY!
})

错误处理

try {
  const response = await client.send('你好')
  console.log(response)
} catch (error) {
  if (error instanceof Error) {
    console.error('请求失败:', error.message)
  }
}

自定义 API 地址

const client = new RertChatClient({
  apiKey: 'sk_xxx',
  baseUrl: 'https://your-custom-domain.com/api/v1'
})

开发

# 安装依赖
pnpm install

# 开发模式
pnpm dev

# 构建
pnpm build

# 清理构建产物
pnpm clean

License

MIT