DEVELOPERSนักพัฒนา
เอกสาร API API Documentation
API เดียวที่เข้ากันได้กับ OpenAI SDK ใช้งานได้กับทุกโมเดลบนแพลตฟอร์มของเรา One OpenAI-compatible API covering every model on our platform.
เริ่มต้นอย่างเร็ว
Quickstart
API ของเราเข้ากันได้กับ OpenAI SDK หากคุณมีโค้ดที่เรียก OpenAI อยู่แล้ว เพียงเปลี่ยน base_url และใช้คีย์ของเรา
Our API is compatible with the OpenAI SDK. If you already call OpenAI, change the base_url and use our key.
pip install openai
from openai import OpenAI
client = OpenAI(
api_key="lts-live-...",
base_url="https://api.ai-token.lightuptotal.co.th/v1"
)
resp = client.chat.completions.create(
model="lts-thai-72b",
messages=[{"role": "user",
"content": "สรุปสัญญานี้เป็น 5 ข้อ"}]
)
print(resp.choices[0].message.content)
ด้วย cURL
With cURL
curl https://api.ai-token.lightuptotal.co.th/v1/chat/completions \
-H "Authorization: Bearer $LTS_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"lts-thai-72b",
"messages":[{"role":"user","content":"สวัสดี"}]}'
การยืนยันตัวตน
Authentication
ส่งคีย์ API มาพร้อมส่วนหัว Authorization ในทุกรีเควสต์ คีย์มีรูปแบบ lts-live- ตามด้วยอักขระสุ่ม
Send your API key in the Authorization header on every request. Keys have the form lts-live- followed by random characters.
Authorization: Bearer lts-live-xxxxxxxxxxxxxxxx
ข้อควรระวัง
Handling keys
- อย่าใส่คีย์ลงในโค้ดฝั่งไคลเอนต์หรือ commit ลง repository
- Never embed keys in client-side code or commit them to a repository
- ใช้ environment variable หรือระบบจัดการความลับ
- Use environment variables or a secrets manager
- หากสงสัยว่าคีย์รั่ว ให้แจ้งเราทันทีเพื่อเพิกถอน
- If you suspect a key has leaked, contact us immediately to revoke it
Chat completions
Chat completions
สร้างคำตอบจากโมเดลภาษา รองรับทั้งโหมดปกติและโหมดสตรีม
Generate a completion from a language model. Supports both standard and streaming modes.
พารามิเตอร์
Parameters
| ชื่อ | Name | ประเภท | Type | คำอธิบาย | Description |
|---|---|---|---|---|---|
| model | string | รหัสโมเดล เช่น lts-thai-72b | Model ID, e.g. lts-thai-72b | ||
| messages | array | รายการข้อความบทสนทนา แต่ละรายการมี role และ content | Conversation messages, each with role and content | ||
| temperature | number | ความสุ่มของคำตอบ 0–2 (ค่าเริ่มต้น 1) | Sampling randomness, 0–2 (default 1) | ||
| max_tokens | integer | จำนวนโทเคนสูงสุดของคำตอบ | Maximum tokens in the response | ||
| stream | boolean | เปิดโหมดสตรีมทีละโทเคน | Stream the response token by token | ||
| tools | array | นิยามฟังก์ชันที่โมเดลเรียกใช้ได้ | Function definitions the model may call |
Embeddings
Embeddings
แปลงข้อความเป็นเวกเตอร์สำหรับงานค้นหา จัดกลุ่ม และ RAG
Convert text into vectors for search, clustering, and retrieval-augmented generation.
resp = client.embeddings.create(
model="lts-embed-multilingual",
input="เอกสารที่ต้องการค้นหา"
)
vector = resp.data[0].embedding
รหัสข้อผิดพลาด
Error codes
| รหัส | Code | ความหมาย | Meaning | วิธีแก้ | Resolution |
|---|---|---|---|---|---|
| 400 | คำขอไม่ถูกต้อง | Bad request | ตรวจรูปแบบ JSON และชื่อพารามิเตอร์ | Check JSON shape and parameter names | |
| 401 | คีย์ไม่ถูกต้อง | Invalid key | ตรวจคีย์และส่วนหัว Authorization | Check the key and Authorization header | |
| 403 | ไม่มีสิทธิ์ | Forbidden | โมเดลนี้อาจยังไม่เปิดให้บัญชีคุณ | The model may not be enabled for your account | |
| 404 | ไม่พบโมเดล | Model not found | ตรวจรหัสโมเดลกับรายการที่รองรับ | Check the model ID against the supported list | |
| 429 | เกินข้อจำกัดอัตรา | Rate limited | ลดความถี่หรือใช้ exponential backoff | Slow down or use exponential backoff | |
| 500 | ข้อผิดพลาดฝั่งเซิร์ฟเวอร์ | Server error | ลองใหม่ แล้วแจ้งเราหากเกิดซ้ำ | Retry, then contact us if it persists | |
| 503 | บริการไม่พร้อม | Unavailable | รอสักครู่แล้วลองใหม่ ระบบมี failover อัตโนมัติ | Wait and retry; automatic failover is in place |
ข้อจำกัดอัตรา
Rate limits
ข้อจำกัดขึ้นกับแพ็กเกจของคุณ และแสดงในส่วนหัวการตอบกลับทุกครั้ง
Limits depend on your plan and are returned in response headers on every call.
x-ratelimit-limit-requests: 600
x-ratelimit-remaining-requests: 597
x-ratelimit-reset-requests: 12s
Streaming
Streaming
เปิด stream=true เพื่อรับผลลัพธ์ทีละโทเคน เหมาะกับแชตบอตที่ต้องการให้ผู้ใช้เห็นข้อความทยอยขึ้น
Set stream=true to receive output token by token — ideal for chatbots where users should see text appear progressively.
stream = client.chat.completions.create(
model="lts-thai-72b",
messages=[{"role": "user", "content": "เล่าเรื่องสั้น"}],
stream=True
)
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="")
Function calling
Function calling
ให้นิยามเครื่องมือที่โมเดลเรียกใช้ได้ เพื่อเชื่อมต่อกับระบบหลังบ้านของคุณ
Define tools the model can call, letting it reach into your backend systems.
tools = [{
"type": "function",
"function": {
"name": "get_order_status",
"description": "ตรวจสถานะคำสั่งซื้อ",
"parameters": {
"type": "object",
"properties": {"order_id": {"type": "string"}}
}
}
}]
ต้องการเอกสารเพิ่มเติม?
Need more documentation?
เราจัดทำเอกสารเฉพาะทางสำหรับการเชื่อมต่อระบบองค์กร การปรับจูนโมเดล และการตั้งค่า private endpoint ให้ลูกค้าแต่ละราย ติดต่อทีมงานได้เลย
We prepare tailored documentation for enterprise integration, model tuning, and private endpoint setup. Get in touch with our team.
ขอเอกสารเพิ่มเติม → Request documentation →ขอคีย์ทดลองแล้วเริ่มเขียนโค้ดได้เลย
Get a trial key and start building
ทีมวิศวกรของเราช่วยตอบข้อสงสัยด้านเทคนิคและออกแบบการเชื่อมต่อให้
Our engineers answer technical questions and help design your integration.