コード
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 を指定すると、ストリーミングの返信でもトークン数を受け取れます。指定しないと、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は1リクエストで最大10枚の画像を読めます。glm-5.3-flash-uncensoredはテキストだけを読み、400 unsupported_inputを返します。- AI SDK は、すべての画像を base64 としてリクエストに含めます。
URLをdataに渡すと、先にファイルをダウンロードします。リクエストは最大12MBまでなので、大きい写真は縮小してください。 - 画像は
image/*のメディアタイプを持つfileパートとして渡します。古い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` ではなく `@ai-sdk/openai-compatible` を使ってください。 OpenAI プロバイダーは既定で
/v1/responsesを呼びますが、nokeep にはそのエンドポイントがありません。
よくある質問
AI SDK 用の nokeep プロバイダーパッケージはありますか?
必要ありません。@ai-sdk/openai-compatible は、OpenAI 互換 API 用の AI SDK 公式パッケージで、このページのすべての機能がこれを通じて動きます。
streamText はトークン数を報告しますか?
はい。プロバイダーを includeUsage: true で作った場合に報告します。すると await result.usage で、その呼び出しのトークン数が得られます。
お金を払わずに試せますか?
はい。キー sk-nokeep-test を使ってください。どの呼び出しも固定の1行を返し、料金はかかりません。先にアプリを接続できます。無料テストキー。