代码
Vercel AI SDK
用 @ai-sdk/openai-compatible 中的 createOpenAICompatible 创建一个 nokeep 提供方。之后,generateText、streamText 和工具的用法与任何 AI SDK 模型相同。
核对于 2026年10月29日
安装并设置提供方
npm install ai @ai-sdk/openai-compatible zod
export NOKEEP_API_KEY="sk-nokeep-test" # your own key once it connectsimport { 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>") 会返回一个模型。可用的 ID 有 deepseek-v4.1-flash-uncensored 和 glm-5.3-flash-uncensored:可在模型中比较,也可从 GET /v1/models 读取。includeUsage: true 会要求流式回复中返回 token 计数;不设置的话,streamText 不会报告任何计数。
generateText
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
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)在 Next.js 路由处理函数中,useChat 应返回 result.toUIMessageStreamResponse(),纯文本则返回 result.toTextStreamResponse()。要停止回复,请中止请求(abortSignal);停止之前已生成的部分仍会计费。详见流式输出。
工具调用
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)两个模型都能调用工具。glm-5.3-flash-uncensored 自行决定是否调用:如果设为 toolChoice: "required" 或指定某个工具,会收到 400,因此工具必须运行时请使用 DeepSeek。详见工具调用。
推理强度
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)providerOptions 下的键就是你为提供方设置的 name。它会原样作为 reasoning_effort 发送。除非你要求它思考,DeepSeek V4.1 Flash Uncensored 会立即作答:可选值为 none、low、high、max。AI SDK 自身的 reasoning: "high" 选项会发送同一字段。详见思考。
图片(DeepSeek)
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每个请求最多读取 10 张图片。glm-5.3-flash-uncensored只读取文本,遇到图片会返回400 unsupported_input。- AI SDK 会把每张图片以 base64 形式放进请求中。如果将
URL作为data传入,它会先下载文件。单个请求最大 12 MB,因此请缩小较大的照片。 - 图片以
file部分发送,媒体类型为image/*。旧的image部分仍可使用,但已被弃用。 - 其他文件(如 PDF 或音频)会被拒绝,并返回
400 unsupported_input。详见图片。
注意事项
- `reasoning_effort` 只接受模型自身的取值。
deepseek-v4.1-flash-uncensored接受none、low、high、max;glm-5.3-flash-uncensored接受low、high。其他应用中的minimal、medium和xhigh会映射到模型最接近的档位(medium按high处理,模型支持时xhigh按max处理);其他任何值都会返回400 invalid_reasoning_effort。详见思考。 - 模型不支持的字段会被丢弃,而不是拒绝。 调用仍会正常返回,
x-nokeep-ignored响应头会列出被忽略的字段。GLM 只保留tools、tool_choice和reasoning_effort,因此它的temperature和response_format会被丢弃。详见各模型支持的字段。 - `n` 必须为 1。 如需多条回复,请发起多次调用。
- 请使用 `@ai-sdk/openai-compatible`,而不是 `@ai-sdk/openai`。 OpenAI 提供方默认调用
/v1/responses,而 nokeep 没有这个接口。
常见问题
AI SDK 有 nokeep 的提供方包吗?
不需要。@ai-sdk/openai-compatible 是 AI SDK 官方用于 OpenAI 兼容 API 的包,本页的每项功能都通过它实现。
streamText 会报告用量吗?
会,前提是创建提供方时设置了 includeUsage: true。之后 await result.usage 就会给出本次调用的 token 计数。
我可以不付费先试用吗?
可以。使用密钥 sk-nokeep-test:每次调用都会返回一行固定文字,且不产生费用,因此你可以先把应用接通。免费测试密钥。