Đi tới nội dung
Tất cả tài liệu

Mã

Vercel AI SDK

Tạo một nhà cung cấp nokeep bằng createOpenAICompatible từ @ai-sdk/openai-compatible. Sau đó generateText, streamText và công cụ hoạt động như với mọi mô hình của AI SDK.

Đã kiểm tra 29 tháng 10, 2026

Cài đặt và thiết lập nhà cung cấp

Shell
npm install ai @ai-sdk/openai-compatible zod
export NOKEEP_API_KEY="sk-nokeep-test"  # your own key once it connects
nokeep.js
import { createOpenAICompatible } from "@ai-sdk/openai-compatible"

export const nokeep = createOpenAICompatible({
  name: "nokeep",
  apiKey: process.env.NOKEEP_API_KEY,
  baseURL: "https://nokeep.ai/v1",
  includeUsage: true, // token counts on streamed replies too
})

nokeep("<model id>") cho bạn một mô hình. Các id là deepseek-v4.1-flash-uncensored và glm-5.3-flash-uncensored: so sánh chúng trong Mô hình, hoặc đọc từ GET /v1/models. includeUsage: true yêu cầu số token cho cả phản hồi truyền từng phần; nếu không có, streamText sẽ không báo số nào.

generateText

JavaScript
import { generateText } from "ai"
import { nokeep } from "./nokeep.js"

const { text, usage } = await generateText({
  model: nokeep("deepseek-v4.1-flash-uncensored"),
  system: "You are a blunt editor.",
  prompt: "Cut this opening line to ten words: ...",
})
console.log(text)
console.log(usage.inputTokens, usage.outputTokens)

streamText

JavaScript
import { streamText } from "ai"
import { nokeep } from "./nokeep.js"

const result = streamText({
  model: nokeep("deepseek-v4.1-flash-uncensored"),
  prompt: "Tell me a story in three lines.",
})
for await (const text of result.textStream) process.stdout.write(text)

// With includeUsage on, the counts arrive once the stream ends.
console.log(await result.usage)

Trong route handler của Next.js, trả về result.toUIMessageStreamResponse() cho useChat, hoặc result.toTextStreamResponse() cho văn bản thuần. Dừng một phản hồi bằng cách hủy yêu cầu (abortSignal); bạn trả tiền cho phần đã được viết trước khi dừng. Xem Truyền từng phần.

Gọi công cụ

JavaScript
import { generateText, stepCountIs, tool } from "ai"
import { z } from "zod"
import { nokeep } from "./nokeep.js"

const { text } = await generateText({
  model: nokeep("deepseek-v4.1-flash-uncensored"),
  tools: {
    weather: tool({
      description: "Get the weather in a city",
      inputSchema: z.object({ city: z.string() }),
      execute: async ({ city }) => ({ city, celsius: 18 }),
    }),
  },
  stopWhen: stepCountIs(5), // let the model call the tool, read the result and answer
  prompt: "What's the weather in Lisbon?",
})
console.log(text)

Cả hai mô hình đều gọi được công cụ. glm-5.3-flash-uncensored tự chọn công cụ: toolChoice: "required" hoặc một tên công cụ cụ thể sẽ nhận 400, nên hãy dùng DeepSeek khi bắt buộc phải chạy một công cụ. Xem Gọi công cụ.

Mức suy nghĩ

JavaScript
import { generateText } from "ai"
import { nokeep } from "./nokeep.js"

const { text, reasoningText } = await generateText({
  model: nokeep("deepseek-v4.1-flash-uncensored"),
  prompt: "Plan a three-act heist story in five bullet points.",
  maxOutputTokens: 4000, // thinking counts toward the limit
  providerOptions: { nokeep: { reasoningEffort: "high" } },
})
console.log(reasoningText) // the thinking, apart from the answer
console.log(text)

Khóa dưới providerOptions là name bạn đặt cho nhà cung cấp. Nó được gửi đi nguyên vẹn như reasoning_effort. DeepSeek V4.1 Flash Uncensored trả lời ngay trừ khi bạn yêu cầu nó suy nghĩ: nó nhận none, low, high, max. Tùy chọn reasoning: "high" của chính AI SDK gửi cùng trường đó. Xem Suy nghĩ.

Hình ảnh (DeepSeek)

JavaScript
import { readFile } from "node:fs/promises"
import { generateText } from "ai"
import { nokeep } from "./nokeep.js"

const { text } = await generateText({
  model: nokeep("deepseek-v4.1-flash-uncensored"),
  messages: [{
    role: "user",
    content: [
      { type: "text", text: "What is in this picture?" },
      { type: "file", mediaType: "image/jpeg", data: await readFile("photo.jpg") },
    ],
  }],
})
console.log(text)
  • deepseek-v4.1-flash-uncensored đọc tối đa 10 hình ảnh mỗi yêu cầu. glm-5.3-flash-uncensored chỉ đọc văn bản và trả về 400 unsupported_input.
  • AI SDK gửi mọi hình ảnh nằm trong yêu cầu, dưới dạng base64. Nếu truyền một URL làm data, nó sẽ tải tệp về trước. Một yêu cầu có thể lên tới 12 MB, nên hãy thu nhỏ các ảnh lớn.
  • Hình ảnh là các phần file có media type image/*. Phần image cũ vẫn chạy được nhưng đã lỗi thời.
  • Các tệp khác, như PDF hay âm thanh, bị từ chối với 400 unsupported_input. Xem Hình ảnh.

Lưu ý

  • `reasoning_effort` chỉ nhận các giá trị của chính mô hình. deepseek-v4.1-flash-uncensored nhận none, low, high, max; glm-5.3-flash-uncensored nhận low, high. Các giá trị minimal, medium và xhigh của ứng dụng khác sẽ chạy ở mức gần nhất mà mô hình có (medium thành high, xhigh thành max khi mô hình có mức đó); mọi giá trị khác nhận 400 invalid_reasoning_effort. Xem Suy nghĩ.
  • Trường mà mô hình không nhận sẽ bị bỏ qua, không bị từ chối. Lần gọi vẫn được trả lời, và header phản hồi x-nokeep-ignored nêu tên những gì đã bị bỏ. GLM chỉ giữ tools, tool_choice và reasoning_effort, nên temperature và response_format của nó bị bỏ. Xem mỗi mô hình nhận trường nào.
  • `n` phải bằng 1. Muốn nhiều phản hồi, hãy gọi nhiều lần.
  • Dùng `@ai-sdk/openai-compatible`, không dùng `@ai-sdk/openai`. Nhà cung cấp OpenAI gọi /v1/responses theo mặc định, mà nokeep không có endpoint đó.

Câu hỏi

Có gói nhà cung cấp nokeep cho AI SDK không?

Bạn không cần gói nào cả. @ai-sdk/openai-compatible là gói chính thức của AI SDK cho các API tương thích OpenAI, và mọi tính năng trên trang này đều chạy qua nó.

streamText có báo số token không?

Có, khi nhà cung cấp được tạo với includeUsage: true. Khi đó await result.usage cho số token của lần gọi.

Tôi có thể thử mà không trả tiền không?

Có. Dùng khóa sk-nokeep-test: mỗi lần gọi trả về một dòng cố định và không tốn gì, nên bạn có thể kết nối ứng dụng trước. Khóa thử miễn phí.