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.

installshell
pip install openai
first_call.pypython
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

requestshell
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.

headerhttp
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

POST/v1/chat/completions

สร้างคำตอบจากโมเดลภาษา รองรับทั้งโหมดปกติและโหมดสตรีม

Generate a completion from a language model. Supports both standard and streaming modes.

พารามิเตอร์

Parameters

ชื่อName ประเภทType คำอธิบายDescription
modelstringรหัสโมเดล เช่น lts-thai-72bModel ID, e.g. lts-thai-72b
messagesarrayรายการข้อความบทสนทนา แต่ละรายการมี role และ contentConversation messages, each with role and content
temperaturenumberความสุ่มของคำตอบ 0–2 (ค่าเริ่มต้น 1)Sampling randomness, 0–2 (default 1)
max_tokensintegerจำนวนโทเคนสูงสุดของคำตอบMaximum tokens in the response
streambooleanเปิดโหมดสตรีมทีละโทเคนStream the response token by token
toolsarrayนิยามฟังก์ชันที่โมเดลเรียกใช้ได้Function definitions the model may call

Embeddings

Embeddings

POST/v1/embeddings

แปลงข้อความเป็นเวกเตอร์สำหรับงานค้นหา จัดกลุ่ม และ RAG

Convert text into vectors for search, clustering, and retrieval-augmented generation.

embeddings.pypython
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ตรวจคีย์และส่วนหัว AuthorizationCheck 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 backoffSlow 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.

headershttp
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.pypython
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.pypython
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.