JavaScript / TypeScript
Official SDK for Node.js, Deno, and Bun.
Installation
pnpm add @b4tonhq/b4tonInitialize
Code
import Baton from "b4ton"
const baton = new Baton(process.env.BATON_KEY)Methods
baton.pass(payload)
Create a new baton with context for the next agent.
Code
const handoff = await baton.pass({
task: "Edit this draft for tone",
output: { draft: "Hello..." },
constraints: "Professional but warm"
})
// handoff.baton_id → "abc-123"
// handoff.pickup_url → "https://b4ton.sh/api/catch/abc-123"baton.catch(url)
Pick up a baton by its pickup URL or ID.
Code
const job = await baton.catch(handoff.pickup_url)
// job.task → "Edit this draft for tone"
// job.output → { draft: "Hello..." }
// job.constraints → "Professional but warm"baton.done(id, payload?)
Mark a baton as complete with optional output.
Code
await baton.done(job.baton_id, {
output: { revised: "Dear colleague..." }
})baton.status(id)
Check baton status without side effects.
Code
const info = await baton.status("abc-123")
// info.status → "pending" | "caught" | "done" | "expired"