Authentication and base URL
เริ่มต้นด้วยการสร้างคีย์ของคุณบนแดชบอร์ด
ใช้ URL พื้นฐานนี้สำหรับคำขอทั้งหมด:
HTTPS://api.nsfwia.com/v1
ส่งคีย์ของคุณในหัว Authorization จุดปลายทางรองรับไคลเอนต์ที่เข้ากันได้กับ OpenAI มาตรฐาน
การส่ง request ครั้งแรกของคุณ
ส่งคำขอ POST ไปยัง /v1/chat/completions เพื่อรับคำตอบ
ใช้ ID ของโมเดล "uncensored" สำหรับการสร้างข้อความ
Input คือข้อความ Output คือข้อความ ไม่มีรูปภาพหรือวิดีโอ
นี่คือตัวอย่าง curl พื้นฐาน:
curl https://api.nsfwia.com/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [{"role": "user", "content": "List the API endpoints and their HTTP methods"}]
}'
การตอบสนองแบบสตรีม
เปิดใช้งานการสตรีมโดยตั้งค่า stream เป็น true
รับโทเค็นทันทีที่ถูกสร้างขึ้น
ใช้ SSE สำหรับผลลัพธ์แบบเรียลไทม์
สิ่งนี้เหมาะสำหรับบทบาทสมมติ
Example streaming code:
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)
การเรียกฟังก์ชันและโหมด JSON
ใช้ฟังก์ชันคอลลิงสำหรับข้อมูลที่มีโครงสร้าง
ตั้งค่า response_format เป็น json_object เพื่อ JSON แบบเข้มงวด
กำหนดเครื่องมือใน body ของคำขอ
สิ่งนี้ช่วยให้การแยกวิเคราะห์ข้อมูลเป็นไปได้อย่างน่าเชื่อถือ
ตัวอย่าง Python SDK:
from openai import OpenAI
client = OpenAI(base_url="https://api.nsfwia.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)
พารามิเตอร์: อุณหภูมิ, top_p และอื่นๆ
ปรับอุณหภูมิเพื่อความสร้างสรรค์
ตั้งค่า top_p สำหรับการสุ่มแบบ nucleus
ใช้ stop sequences เพื่อจบการสร้าง
Seed รับประกันความสามารถในการทำซ้ำ
ตัวอย่าง Node SDK:
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.nsfwia.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);
การเข้าใจต้นทุนโทเค็น
ราคาอยู่ที่ $0.15 ต่อ 1M input tokens และ $0.50 ต่อ 1M output tokens.
ข้อผิดพลาดไม่ต้องเสียเงิน การปฏิเสธไม่ต้องเสียเงิน
หน้าต่างบริบทคือ 100,000 โทเค็นรวม
เอาต์พุตสูงสุดคือ 16,000 โทเค็นต่อคำขอ
ข้อจำกัด: 300 คำขอต่อนาที คำขอพร้อมกันได้ 8 คำขอ
ข้อผิดพลาดรวมถึง 401 (คีย์ไม่ถูกต้อง), 402 (ไม่มีเครดิต), 429 (เกินอัตราจำกัด)