Skip to content

Give your AI agent a calendar

An AI agent that schedules, follows up or runs long tasks needs somewhere to keep track of time. With Chronary, the agent gets a calendar of its own through an API. You don’t borrow a person’s Google account, and there’s no OAuth to set up.

In this tutorial you will:

  1. Create an agent and a calendar for it.
  2. Add an event and read the calendar back.
  3. Share the calendar with a person, so it shows up in their calendar app.

Everything here works on the Free plan.

  • A Chronary account and an API key (chr_sk_…). Sign up and copy the key the console shows you. If you lost it, create a new one under API keys.
  • Node.js 18+ or Python 3.10+.

Install the SDK and put your key in an environment variable:

Terminal window
npm install @chronary/sdk
export CHRONARY_API_KEY=chr_sk_your_key_here

Both SDKs read CHRONARY_API_KEY from the environment, so the code below never contains the key.

Every calendar belongs to an agent. Create the agent first, then a calendar in the time zone the agent works in.

Set prevent_overlaps to true. The calendar then refuses any event that would overlap one it already has, even when several requests arrive at once. Your agent can’t double-book itself.

import { Chronary } from '@chronary/sdk';
const chronary = new Chronary();
const agent = await chronary.agents.create({
name: 'Scheduling Assistant',
type: 'ai',
description: 'Books and tracks meetings',
});
const calendar = await chronary.calendars.create({
agentId: agent.id,
name: 'Work',
timezone: 'America/New_York',
prevent_overlaps: true,
});
console.log(agent.id, calendar.id); // agt_… cal_…

Save both IDs. Your agent uses the calendar ID for everything that follows.

Times are ISO 8601. Send them in UTC or with an offset. This adds a 30-minute call tomorrow at the current time of day:

const start = new Date(Date.now() + 24 * 60 * 60 * 1000);
const end = new Date(start.getTime() + 30 * 60 * 1000);
const event = await chronary.events.create(calendar.id, {
title: 'Intro call with Sam',
description: 'Booked by the scheduling assistant',
start_time: start.toISOString(),
end_time: end.toISOString(),
reminders: [15],
});
console.log(event.id, event.status); // evt_… confirmed

reminders: [15] asks for a reminder 15 minutes before the start. If you add a webhook, your agent gets an event.reminder call at that moment, plus event.started and event.ended. The agent doesn’t have to poll the clock.

Before the agent plans its day, it lists what’s coming up:

const weekAhead = new Date(Date.now() + 7 * 24 * 60 * 60 * 1000);
for await (const e of chronary.events.list({
calendarId: calendar.id,
start_after: new Date().toISOString(),
start_before: weekAhead.toISOString(),
})) {
console.log(e.startTime, e.title);
}

Every calendar has a private iCal feed URL. Anyone with the URL can subscribe to it in Google Calendar, Outlook or Apple Calendar and see the agent’s events next to their own.

console.log(calendar.ical_url);

The iCal feeds guide shows how to subscribe in each calendar app.

Your agent now has a calendar that it owns, that can’t be double-booked, and that people can see. From here: