Skip to Content
hronika

API Reference

Every method of the SDK.

createHronika(options?)

Creates a client. It reads the API URL from the HRONIKA_API environment variable and throws HRONIKA_API is not set if it is missing.

import { createHronika } from 'hronika';

const hronika = createHronika();
OptionTypeDefaultDescription
fetchtypeof fetchglobal fetchCustom fetch implementation, for example in tests.

Every method below returns a promise.

init()

Creates a loop and returns its id.

const { loopId } = await hronika.init();

save(input)

Appends a checkpoint to the loop and moves the cursor to it. Returns the saved checkpoint.

type CheckpointInput =
  | { loopId: string; type: 'inference_request' | 'tool_call_request'; parameters: unknown; agentState?: unknown }
  | { loopId: string; type: 'inference_result' | 'tool_call_result'; result: unknown; agentState?: unknown };

get({ loopId, checkpointId })

Returns one checkpoint by id.

current(loopId)

Returns the checkpoint under the cursor.

undo(loopId)

Moves the cursor one checkpoint back and returns that checkpoint.

redo(loopId)

Moves the cursor one checkpoint forward and returns that checkpoint.

Checkpoint

The value returned by save, get, current, undo and redo:

type Checkpoint = {
  id: string;
  type: 'inference_request' | 'tool_call_request' | 'inference_result' | 'tool_call_result';
  parameters?: unknown; // requests
  result?: unknown; // results
  agentState?: unknown;
  createdAt: string; // ISO date
};

Errors

A failed request throws a HronikaError with the HTTP status and the API's message.

import { HronikaError } from 'hronika';

try {
  await hronika.undo(loopId);
} catch (error) {
  if (error instanceof HronikaError && error.status === 404) {
    // e.g. "No checkpoint to undo" or "Loop <id> not found"
  }
}
MessageStatusWhen
Loop <id> not found404The loop does not exist.
Checkpoint <id> not found404get with an id that is not in the loop.
No checkpoint to undo404undo on the first checkpoint.
No checkpoint to redo404redo on the last checkpoint.
No checkpoint to get404current before anything has been saved.

On this page