เริ่มต้นใช้งาน
Rate Limits
limits ต่อ tier — ทั้ง requests-per-minute (RPM) และ requests-per-day (RPD)
| Tier | RPM | RPD | Credits/เดือน |
|---|---|---|---|
| Free | 30 | 1,000 | 1,000 |
| Starter | 120 | 20,000 | 10,000 |
| Pro | 600 | 100,000 | 50,000 |
| Enterprise | Custom | Custom | Custom |
Response Headers
ทุก response มี header เหล่านี้ — ใช้ตรวจสอบ quota ที่เหลือ
HTTP/2 200
content-type: application/json
x-ratelimit-limit: 120
x-ratelimit-remaining: 117
x-ratelimit-reset: 1746788400
x-request-id: req_a1b2c3d4- x-ratelimit-limit — RPM ของ tier ปัจจุบัน
- x-ratelimit-remaining — จำนวน call ที่เหลือใน window นี้
- x-ratelimit-reset — UNIX timestamp ที่ window จะ refill
- x-request-id — ID opaque ส่งให้ 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++
}
}