Zavu implements rate limiting to ensure fair usage and protect the platform from abuse. All API requests to /v1/* endpoints are subject to rate limiting.
Use .withResponse() to access the rate limit headers:
Copy
import Zavudev from '@zavudev/sdk';const zavu = new Zavudev({ apiKey: process.env['ZAVUDEV_API_KEY'], // This is the default and can be omitted});// Use .withResponse() to get the full HTTP responseconst { response, result } = await zavu.messages.send.withResponse({ to: "+14155551234", text: "Hello from Zavu!",});// Access rate limit headersconst limit = response.headers.get("X-RateLimit-Limit");const remaining = response.headers.get("X-RateLimit-Remaining");const reset = response.headers.get("X-RateLimit-Reset");console.log(`Rate limit: ${remaining}/${limit} requests remaining`);console.log(`Window resets at: ${new Date(Number(reset)).toISOString()}`);// Access the message result as usualconsole.log("Message ID:", result.message.id);
For sending many messages, implement a simple rate limiter:
Copy
import Zavudev from '@zavudev/sdk';const zavu = new Zavudev({ apiKey: process.env['ZAVUDEV_API_KEY'], // This is the default and can be omitted});async function sendBulkMessages(messages: { to: string; text: string }[]) { const results = []; let remaining = 600; for (const msg of messages) { // If running low, wait for next window if (remaining < 10) { console.log("Approaching rate limit, waiting for next window..."); await new Promise(resolve => setTimeout(resolve, 60000)); remaining = 600; } const { response, result } = await zavu.messages.send.withResponse(msg); remaining = Number(response.headers.get("X-RateLimit-Remaining")); results.push(result); } return results;}