Introduction

Rate limits

Each account can send 120 requests a minute.

The Orion API accepts up to 120 requests per minute per account. The limit counts every request made with any of your keys together, so two scripts with two keys share one budget.

The MCP server has its own, separate limit. Calls from an AI assistant do not use up your API budget.

When you reach the limit

Requests over the limit answer 429 with the code rate_limited and a Retry-After header that gives the wait in seconds:

HTTP/1.1 429 Too Many Requests
Retry-After: 60
Content-Type: application/json

{"error":{"code":"rate_limited","message":"Rate limit exceeded: at most 120 requests per minute per account. Retry after a minute."}}
HTTP

The request was not carried out. Nothing changed on your device.

Back off

Wait for the time in Retry-After, then send the request again.

async function orion(path, init = {}) {
	for (let attempt = 0; attempt < 3; attempt++) {
		const response = await fetch(`https://api.orionsleep.com${path}`, {
			...init,
			headers: { ...init.headers, Authorization: `Bearer ${process.env.ORION_API_KEY}` }
		});
		if (response.status !== 429) return response;
		const seconds = Number(response.headers.get('Retry-After') ?? 60);
		await new Promise((resolve) => setTimeout(resolve, seconds * 1000));
	}
	throw new Error('Still rate limited after 3 tries');
}

Stay under the limit

  • Change several zones of one device with one call to Set multiple zones, not one call per zone.
  • Do not poll Get live device state in a tight loop. Leave a few seconds between reads.
  • Call List devices once at the start and keep the ids, instead of before every request.
  • Cancel several timeline events, rate several nights or act on several changes in one call: those operations take a list of ids.