跳到正文
全部文档

代码

JavaScript 与 TypeScript

官方 openai 包可在 Node、Bun、Deno 和浏览器中使用。只需修改 base URL 和密钥。

核对于 2026年10月26日

安装与连接

Shell
npm install openai
export NOKEEP_API_KEY="sk-nokeep-test"  # your own key once it connects
client.ts
import OpenAI from "openai"

const client = new OpenAI({
  baseURL: "https://nokeep.ai/v1",
  apiKey: process.env.NOKEEP_API_KEY,
})

发送与流式输出

const reply = await client.chat.completions.create({
  model: "deepseek-v4.1-flash-uncensored",
  messages: [{ role: "user", content: "Name three good names for a tavern." }],
})
console.log(reply.choices[0].message.content)

在浏览器中使用

API 允许任何网页发起调用。除非你传入 dangerouslyAllowBrowser: true,否则 SDK 拒绝在浏览器中运行,因为页面中的密钥任何打开页面的人都能读取。只有在使用用户自己输入的密钥,或免费测试密钥时,才应这样做。

错误与额外字段

TypeScript
import OpenAI from "openai"

try {
  await client.chat.completions.create({
    model: "deepseek-v4.1-flash-uncensored",
    messages,
    // Fields the SDK's types don't name pass through as they are:
    // @ts-expect-error min_p isn't in OpenAI's types
    min_p: 0.05,
  })
} catch (error) {
  if (error instanceof OpenAI.APIError) console.log(error.status, error.code)
}