Installation
Quick setup
The easiest way to get started is with the safeFetch() convenience function. It reads your API key from the SAFEFETCH_API_KEY environment variable automatically.
safeFetch() — convenience function
safeFetch(opts) sends an action using a shared instance configured from environment variables. It accepts all SendOptions and returns a Promise<Action>.
The function also has shorthand methods for the other operations:
new SafeFetch() — class API
Use the class directly when you need multiple instances, custom base URLs, or explicit key management.
The class exposes the same set of methods: send, get, list, approve, cancel, retry.
SendOptions
All options for safeFetch() / sf.send():
sync: true cannot be combined with approve: true — actions waiting for human approval cannot be awaited synchronously.
Sync mode
Pass sync: true to wait for the action to finish before returning:
Human approval
Pass approve: true to require a human to approve the action before it is dispatched:
See Human Approval for the full workflow.
ListOptions
Options for safeFetch.list() / sf.list():
The Action object
Every method returns an Action object:
ActionStatus values: pending, active, awaiting_approval, completed, failed, cancelled.
Error handling
The SDK throws SafeFetchError for all failures:
SafeFetchError properties:
TypeScript types
All types are exported from the safefetch package:
Environment variables