繁中 ▾
取得 API 金鑰
每 1M 輸入 token
$0.15
輸出 token / 1M
$0.50
token 上下文
100,000
試用額度
$0.50
每分鐘請求數
300

開發者用的無審查文本 API

Unfiltered AINode.js 中的 OpenAI API 搭配無審查端點

Node.js 中的 OpenAI API 搭配無審查端點

對於 open ai api node 專案,你不需要特殊的函式庫。官方 openai 套件即可直接使用:你只需更改 base URL 和金鑰,並使用文件中的模型 ID。本頁展示了聊天、串流輸出、工具和速率限制的可用程式碼。

更新於

一個發光的節點透過電纜連接到 API 伺服器,代表 Node.js 與相容 OpenAI 的端點進行通訊

重點

  • 安裝 openai 套件,設定 baseURL 和 apiKey,並傳入單一模型 ID。
  • 串流輸出、工具呼叫和 JSON 模式遵循標準的 OpenAI 請求格式。
  • 完整金鑰允許 8 個並行請求,因此請限制並行工作數量,並讓 SDK 在收到 429 時重試。
  • 失敗或遭拒的請求不會計費,且每次回應都會回傳使用量資訊。

現有 Node 專案的變更

如果你的程式碼已經透過 openai 套件與聊天完成端點通訊,遷移只需兩行。在客戶端建構子中傳入不同的 baseURL 與不同的 apiKey,並將 uncensored 設為模型。請求中的其餘內容維持原有格式。

此服務是由獨立供應商託管的單一開放權重模型 API,經過微調以在法律允許的成人用途下提供無內容拒絕的回答。它並非任何模型供應商的官方 API,也不在各供應商之間路由,因此僅有一個模型 ID。提供兩種方法:POST /v1/chat/completions 與 GET /v1/models。僅支援文字,沒有影像端點與嵌入端點,若你的專案需要這些功能則需注意。

你需要一組金鑰。註冊支援 Google 或電子郵件與密碼,API 金鑰頁面 提供一鍵領取 $0.50 試用額度,無需綁定信用卡。試用期為 7 天。

安裝並進行首次請求

你需要較新的 Node 版本並使用 ES 模組。建立資料夾,安裝套件並將金鑰保留在環境變數中,而非原始碼中:

mkdir uncensored-node && cd uncensored-node
npm init -y
npm install openai
npm pkg set type=module
export UNFILTERED_API_KEY="paste-your-key-here"

以下是一個最小化腳本。將其儲存為 chat.js 並執行 node chat.js:

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.unfilteredaigenerator.top/v1",
  apiKey: process.env.UNFILTERED_API_KEY,
});

const completion = await client.chat.completions.create({
  model: "uncensored",
  messages: [
    { role: "system", content: "You are a blunt editor. Answer in plain language." },
    { role: "user", content: "Rewrite this sentence so it is shorter: The meeting that we had yesterday was a meeting about budgets." },
  ],
  temperature: 0.7,
});

console.log(completion.choices[0].message.content);
console.log(completion.usage);

回應具有熟悉的結構:文字位於 choices[0].message.content,token 計數位於 usage。回覆標頭還包含 X-Request-Id 與 X-Balance-USD,當你想記錄請求成本或檢查剩餘額度時非常有用。你可以透過在請求 promise 上呼叫 .withResponse() 來在 SDK 中讀取標頭。

如果你偏好 CommonJS,請將 import 替換為 const OpenAI = require("openai"),移除頂層的 await 並將主體包裝在 async 函式中。

串流接收到達的 token

若等待整個回應,長回覆會感覺很慢。設定 stream: true,端點會發送伺服器發送事件(SSE),每個文字片段對應一個區塊,並在串流結束時回報用量。

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.unfilteredaigenerator.top/v1",
  apiKey: process.env.UNFILTERED_API_KEY,
});

const stream = await client.chat.completions.create({
  model: "uncensored",
  messages: [{ role: "user", content: "Tell a two-paragraph story about a lighthouse keeper." }],
  stream: true,
});

let usage = null;
for await (const chunk of stream) {
  const delta = chunk.choices[0]?.delta?.content;
  if (delta) process.stdout.write(delta);
  if (chunk.usage) usage = chunk.usage;
}
console.log("\n", usage);

有兩個細節常讓人困擾。首先,chunk.choices[0]?.delta?.content 的選接運算子很重要,因為某些區塊不包含文字,包括結束區塊。其次,串流請求會佔用併發槽位直到串流結束。如果使用者關閉分頁而你的伺服器繼續讀取,你仍會佔用一個槽位,因此在客戶端斷線時應中止串流。

工具呼叫與 JSON 模式

工具呼叫使用你熟悉的欄位:tools、tool_choice,以及以 role: "tool" 回傳的結果。串流時,工具呼叫會分段到達,你需要在解析之前組裝參數字串。以下是不串流的完整往返範例:

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.unfilteredaigenerator.top/v1",
  apiKey: process.env.UNFILTERED_API_KEY,
});

const tools = [
  {
    type: "function",
    function: {
      name: "get_order_status",
      description: "Look up an order by its numeric ID",
      parameters: {
        type: "object",
        properties: { order_id: { type: "integer" } },
        required: ["order_id"],
      },
    },
  },
];

const messages = [{ role: "user", content: "Where is order 4812?" }];

const first = await client.chat.completions.create({
  model: "uncensored",
  messages,
  tools,
  tool_choice: "auto",
});

const call = first.choices[0].message.tool_calls?.[0];
if (call) {
  const args = JSON.parse(call.function.arguments);
  const result = { order_id: args.order_id, status: "shipped" };

  messages.push(first.choices[0].message);
  messages.push({
    role: "tool",
    tool_call_id: call.id,
    content: JSON.stringify(result),
  });

  const second = await client.chat.completions.create({
    model: "uncensored",
    messages,
    tools,
  });
  console.log(second.choices[0].message.content);
}

在實際程式碼中,請務必在 try 區塊內解析參數。模型偶爾會產生格式錯誤的 JSON,附加錯誤訊息的重試通常足以修復它。

當你只需要結構化輸出且不需要工具時,JSON 模式更簡短。設定 response_format,並在提示詞中告知模型你想要哪些鍵,因為格式標記要求 JSON 物件但不強制執行你的結構描述:

const res = await client.chat.completions.create({
  model: "uncensored",
  response_format: { type: "json_object" },
  messages: [
    { role: "system", content: "Reply with a JSON object with keys title and tags (an array of strings)." },
    { role: "user", content: "Summarise: a short guide to composting kitchen scraps." },
  ],
});

const data = JSON.parse(res.choices[0].message.content);
console.log(data.title, data.tags);

速率限制、重試與並行工作

限制取決於金鑰類型。完整金鑰允許 8 個並行請求與每分鐘 300 個請求。試用金鑰允許 2 個並行與每分鐘 60 個請求。超過限制時,你會收到 HTTP 429 錯誤,超過每分鐘上限時錯誤碼為 rate_limited,同時請求過多時錯誤碼為 concurrency。在暫時過載時,API 也會回傳 429,並附上 Retry-After: 5 標頭。

openai 套件預設會重試 429 回應並遵循 Retry-After,你可以透過 maxRetries 選項增加重試次數。對於批次工作,加入限制器以進行佇列而非碰撞。p-limit 套件可用幾行程式碼達成此目的:

import OpenAI from "openai";
import pLimit from "p-limit";

const client = new OpenAI({
  baseURL: "https://api.unfilteredaigenerator.top/v1",
  apiKey: process.env.UNFILTERED_API_KEY,
  maxRetries: 4,
});

const limit = pLimit(6); // stay under the 8 concurrent requests allowed on a full key

const prompts = ["Idea one", "Idea two", "Idea three"];

const results = await Promise.all(
  prompts.map((p) =>
    limit(async () => {
      const r = await client.chat.completions.create({
        model: "uncensored",
        messages: [{ role: "user", content: p }],
        max_tokens: 400,
      });
      return r.choices[0].message.content;
    })
  )
);

將限制器設定為等於或低於金鑰的並行數。對於試用金鑰,使用 2。如果你串流,請記住每個開啟的串流在其整個持續期間都計入,因此擁有許多使用者的聊天伺服器需要自己的佇列。

要在你自己的處理程序中區分兩種 429 類型,請檢查程式碼:

try {
  const r = await client.chat.completions.create({ model: "uncensored", messages });
} catch (err) {
  if (err instanceof OpenAI.APIError && err.status === 429) {
    console.log("code:", err.code, "retry after:", err.headers?.["retry-after"]);
  } else {
    throw err;
  }
}

用於網頁前端的輕量 Express 端點

切勿將金鑰放在瀏覽器程式碼中。常見模式是持有金鑰並轉發訊息的薄伺服器路由。此路由將文字以伺服器發送的事件串流傳輸到客戶端:

import express from "express";
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.unfilteredaigenerator.top/v1",
  apiKey: process.env.UNFILTERED_API_KEY,
});

const app = express();
app.use(express.json());

app.post("/api/chat", async (req, res) => {
  res.setHeader("Content-Type", "text/event-stream");
  res.setHeader("Cache-Control", "no-cache");

  try {
    const stream = await client.chat.completions.create({
      model: "uncensored",
      messages: req.body.messages,
      stream: true,
    });
    for await (const chunk of stream) {
      const text = chunk.choices[0]?.delta?.content ?? "";
      if (text) res.write("data: " + JSON.stringify({ text }) + "\n\n");
    }
    res.write("data: [DONE]\n\n");
  } catch (err) {
    res.write("data: " + JSON.stringify({ error: err.status ?? 500 }) + "\n\n");
  } finally {
    res.end();
  }
});

app.listen(3000);

在公開之前,請加入你自己的驗證機制並限制 messages 長度,因為任何能呼叫該路由的人都會消耗你的額度。最大請求主體為 8 MB,上下文視窗為 100,000 token(包含提示詞與補全),因此當對話變長時請截斷舊訊息。一個簡單的原則是保留系統訊息與最近的對話輪次,並優先刪除最舊的輪次。估算英文文字時,每個 token 約等於四個字元,然後確認每個回應回傳的 usage 欄位以取得精確數字。

請求的成本

計費標準為每 1M 輸入 token $0.15,每 1M 輸出 token $0.50,從預付額度扣除。考慮一個包含 1,500 個輸入 token 和 400 個輸出 token 的請求。輸入成本為 1,500 × $0.15 / 1,000,000 = $0.000225,輸出成本為 400 × $0.50 / 1,000,000 = $0.0002。每次請求成本為 $0.000425,因此 10,000 次此類請求的成本為 $4.25。

由於失敗或遭拒的請求不會計費,因此錯誤後的重試不會增加帳單。儲值金額為 $20 至 $500 的整數,且額度永不失效。較大的儲值會獲得額外贈金:$50 起贈 5%、$100 起贈 10% 以及 $200 起贈 15%。你可以使用加密貨幣(TRC20 上的 USDT、Base 上的 USDC)進行付款。定價頁面列出了詳細資訊,而API 文件則涵蓋了所有傳遞的參數,例如 temperature、top_p、stop、seed 以及懲罰係數。

提示詞不會用於訓練。對於愛好專案,這是一個合理的預設值;對於產品,這是你可以在隱私聲明中陳述的一點。涉及未成年人的色情內容在任何情況下都不允許,該模型旨在供合法成人用途。

問答

Node.js 需要特殊的 SDK 嗎?

不需要。官方的 openai 套件即可運作。將 baseURL 設為此網站的端點,將你的金鑰用作 apiKey,並傳入文件中顯示的模型 ID。

可以使用 fetch 取代 SDK 嗎?

可以。向 /v1/chat/completions 發送 POST 請求,並附上 Authorization: Bearer 標頭與 JSON 主體。SDK 僅提供重試與型別輔助功能。

可以使用嵌入或影像端點嗎?

不是。API 僅支援文字,提供聊天補全請求與模型列表。沒有嵌入、影像、音訊或影片端點。

為什麼我會收到 429 錯誤?

你每分鐘發送的請求超過 300 個,或同時發送的請求過多(完整金鑰帳戶為 8 個,試用金鑰為 2 個)。錯誤程式碼會告訴你屬於哪一種,SDK 會自動重試。

我的數據用於訓練嗎?

不會。提示詞不會用於訓練。

只需填寫表單即可取得金鑰

建立帳號、複製金鑰、更改基礎 URL。這就是整個設定過程。

取得 API 金鑰