Rate limits

Rate limit ต่อ API key, reset ที่ UTC midnight (00:00 UTC = 07:00 ICT) ทุกวัน

Free tier

1,000 requests / day ต่อ key

ต้องการมากขึ้น? ดู pricing หรือติดต่อ hello@smongrot.com

Headers

ทุก response (รวม error) มี:

X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 987
X-RateLimit-Reset: 29322
  • Limit — โควตาต่อวัน
  • Remaining — เหลือกี่ req ก่อน reset
  • Reset — วินาทีจนถึงโควตา reset (UTC midnight)

เกินโควตา

Response = 429 Too Many Requests

{
  "error": {
    "code": "rate_limit_exceeded",
    "message": "daily limit of 1000 exceeded",
    "docs_url": "https://developers.smongrot.com/docs/rate-limits"
  }
}

พร้อม header:

Retry-After: 29322

สิ่งที่ควรทำ:

  • อย่ายิงซ้ำทันที — รอตามค่า Retry-After
  • Implement exponential backoff ใน retry logic
  • Cache response ที่ static (เช่น /ecu-models, /schemas) ฝั่ง client — 24h ก็ได้

Best practices

1. Cache static endpoints

ecu-models และ schemas เปลี่ยนน้อยมาก — cache 24 ชั่วโมงก็ยัง safe:

// Server-side cache example (Next.js)
export const revalidate = 86400; // 24h

async function getEcuModels() {
  const res = await fetch("https://api.smongrot.com/v1/ecu-models", {
    headers: { Authorization: `Bearer ${process.env.SMONGROT_API_KEY}` },
    next: { revalidate: 86400 },
  });
  return res.json();
}

2. ใช้ pagination อย่างถูกวิธี

Default limit=25, max limit=100 — ใช้ next_cursor แทน offset เพราะเร็วกว่าและ stable:

let cursor: string | null = null;
const all = [];
do {
  const url = new URL("https://api.smongrot.com/v1/ecu-models");
  url.searchParams.set("limit", "100");
  if (cursor) url.searchParams.set("cursor", cursor);
  const res = await fetch(url, { headers: { Authorization: `Bearer ${KEY}` } });
  const json = await res.json();
  all.push(...json.data);
  cursor = json.next_cursor;
} while (cursor);

3. Batch งานที่ไม่ต้อง realtime

ถ้าจะ sync catalog ทั้งหมด — ทำ 1 ครั้ง/วัน ตอน off-peak แล้ว store ไว้ database ตัวเอง

4. Monitor usage ใน Dashboard

Dashboard แสดง usage 24h/7d/30d — set alert เมื่อใกล้ 80% ของโควตา

Pro tier (v2)

  • 100,000 req/day
  • Priority queue (bypass rate limit ในช่วง incident)
  • Higher burst allowance