เริ่มต้นใช้งาน
Rate Limits
limits ต่อ tier — ทั้ง requests-per-minute (RPM) และ requests-per-day (RPD)
| Tier | RPM | RPD | Credits/เดือน |
|---|---|---|---|
| Free | 10 | 500 | 1,000 |
| Starter | 120 | 20,000 | 25,000 |
| Growth | 300 | 60,000 | 100,000 |
| Pro | 600 | 150,000 | 400,000 |
| Enterprise | Custom | Custom | Custom |
Response Headers
endpoint ที่คิด credit จะส่ง header เหล่านี้กลับมาเมื่อผ่านการตรวจ tier ใช้ตรวจสอบ quota ที่เหลือ
HTTP/2 200
content-type: application/json
x-request-id: 6f1c2a9e-4b7d-4c1e-9a53-2f0d8b1e7c44
x-subscription-tier: starter
x-ratelimit-limit-day: 20000
x-ratelimit-remaining-day: 19873
x-ratelimit-reset-day: 1792368000
x-ratelimit-limit-minute: 120
x-ratelimit-remaining-minute: 117- x-subscription-tier — แผนที่ใช้กับ call นี้
- x-ratelimit-limit-minute / x-ratelimit-limit-day — เพดานต่อนาทีและต่อวันของแผนปัจจุบัน
- x-ratelimit-remaining-minute / x-ratelimit-remaining-day — จำนวน call ที่เหลือใน window นาทีนี้และในวันนี้ (UTC)
- x-ratelimit-reset-day — UNIX timestamp (วินาที) ของเที่ยงคืน UTC ถัดไป ซึ่งเป็นเวลาที่ quota รายวันรีเซ็ต ไม่มี header reset รายนาที ให้ใช้ Retry-After เมื่อเจอ 429
- x-request-id — string แบบ opaqueในทุก response (ส่งค่า X-Request-Id ของคุณกลับมาถ้าส่งไว้ ไม่เช่นนั้นเป็น ID ที่ระบบสร้าง) ส่งให้ support เพื่อ debug call นั้น
จัดการ 429 Too Many Requests
response มี Retry-After (วินาที) — แนะนำให้ทำ exponential backoff: 1s, 2s, 4s, 8s แล้วยอมแพ้
// Exponential backoff on 429
async function callWithRetry(url: string, init: RequestInit, max = 4) {
let attempt = 0
while (true) {
const res = await fetch(url, init)
if (res.status !== 429) return res
if (attempt >= max) return res
const retryAfter = Number(res.headers.get('Retry-After') ?? 1)
const waitMs = (retryAfter || 2 ** attempt) * 1000
await new Promise((r) => setTimeout(r, waitMs))
attempt++
}
}Retry แบบ idempotent
ส่ง header Idempotency-Key (ยาวไม่เกิน 128 ตัว ใช้ตัวอักษร ตัวเลข _ : . -) กับ POST ใดก็ได้ ภายใน 24 ชั่วโมง ถ้าส่งซ้ำด้วย key และ body เดิม จะได้ response เดิมพร้อม header idempotency-replayed: true และไม่ถูกตัด credit ซ้ำ ถ้าใช้ key เดิมกับ body ต่างกันจะได้ 409 idempotency_conflict ส่วน error ฝั่งเซิร์ฟเวอร์ (5xx) จะไม่ถูกเก็บ