API 快速入門
此快速入門指南展示如何使用標準 SDK 向我們的 uncensored、OpenAI 相容 API 傳送請求。您將設定基礎 URL、處理身份驗證,並串流回應,且無供應商鎖定問題。
基礎 URL 與驗證
The deepseek api documentation 此服務的基礎 URL 為 https://api.deepseekcoderpricing.com/v1. 您需要一個透過 Authorization 每次請求的標頭。 取得您的 API 金鑰 使用 Google 或電子郵件註冊後立即。
驗證很簡單。包含標頭 Authorization: Bearer YOUR_API_KEY 在所有呼叫中。如果金鑰遺失或無效,伺服器會返回 401 錯誤。這確保您的 uncensored LLM API 存取保持安全,且無需複雜的設定步驟。
首次請求
您的第一個請求確認連接和 token 計費。端點為 POST /v1/chat/completions. 您必須將模型 ID 設為 uncensored. 此模型在我們自己的伺服器上運行,不會拒絕合法的成人內容。
發送基本提示以驗證連線是否正常運作。系統僅對回應中實際使用的 token 收費。錯誤和拒絕不會消耗您的預付額度。
基礎網址為 https://api.deepseekcoderpricing.com/v1.
curl https://api.deepseekcoderpricing.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [{"role": "user", "content": "List the hourly compute cost for the 7b model."}]
}'
Python SDK 整合
使用標準的 OpenAI Python SDK 是最簡單的整合方式。設定 base_url 和 api_key 變數初始化客戶端之前。這使您能以最小的變更重用來自其他平台的程式碼片段。
客戶端自動處理 JSON 序列化。您將訊息作為字典列表傳遞。回應物件包含生成的文本和用於帳務透明度的 token 使用統計數據。
from openai import OpenAI
client = OpenAI(base_url="https://api.deepseekcoderpricing.com/v1", api_key="YOUR_KEY")
resp = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "Summarise this thread without softening it."}],
)
print(resp.choices[0].message.content)Node.js
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.deepseekcoderpricing.com/v1", apiKey: process.env.API_KEY });
const resp = await client.chat.completions.create({
model: "uncensored",
messages: [{ role: "user", content: "Draft a villain monologue for my game." }],
});
console.log(resp.choices[0].message.content);串流
stream = client.chat.completions.create(
model="uncensored",
messages=[{"role": "user", "content": "Tell the story in second person."}],
stream=True,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)