Mã
JavaScript và TypeScript
Gói openai chính thức chạy được trên Node, Bun, Deno và trình duyệt. Chỉ cần đổi base URL và khóa.
Đã kiểm tra 26 tháng 10, 2026
Cài đặt và kết nối
npm install openai
export NOKEEP_API_KEY="sk-nokeep-test" # your own key once it connectsimport OpenAI from "openai"
const client = new OpenAI({
baseURL: "https://nokeep.ai/v1",
apiKey: process.env.NOKEEP_API_KEY,
})Gửi và stream
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)Trong trình duyệt
API cho phép gọi từ mọi trang web. SDK sẽ từ chối chạy trong trình duyệt trừ khi bạn truyền dangerouslyAllowBrowser: true, vì khóa đặt trong trang có thể bị bất kỳ ai mở trang đọc được. Chỉ làm vậy với khóa do chính người dùng tự nhập, hoặc với khóa thử miễn phí.
Lỗi và trường bổ sung
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)
}