Skip to main content

Callbacks

The SDK fires callbacks at five moments while a run streams: started, log, checkpoint, completed, failed. They let you forward metrics, evaluate intermediate checkpoints, or trigger your own notifications without leaving TypeScript.
All five are optional. Each callback can return a Promise; the SDK awaits it before firing the next event.

Common uses

  • Forward metrics: in onLog, push step and loss to your own pipeline (PostHog, Datadog, etc.).
  • Evaluate during training: in onCheckpoint, call infer() against a held-out prompt and log the sample so you know early if the run is heading in the right direction.
  • Notify on completion: in onCompleted or onFailed, post to Slack or send an email.
For richer recipes, see Mid-run eval, Early stopping, and Notifications.

Reference

For full type signatures, the rule that throwing inside a callback triggers SSE reconnect rather than a normal rejection, and the per-callback parameter list, see the Callbacks reference. For the conceptual flow of a run, see Run lifecycle.