Actions are the right place for work that involves the outside world: calling external APIs, sending email, processing payments, handling webhooks, or orchestrating a sequence of database changes interleaved with network I/O. Unlike mutations, actions run outside of a database transaction and are not automatically retried by the runtime on conflict. This makes them safe for non-idempotent operations. Actions do not have direct access toDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/nickruigrok/baseflare/llms.txt
Use this file to discover all available pages before exploring further.
ctx.db — all database reads and writes go through ctx.runQuery() and ctx.runMutation().
Defining an Action
Useaction() from baseflare/server. The signature mirrors query() and mutation() — provide args, an optional returns validator, and a handler that receives an ActionCtx:
handler can use await freely, perform multiple network calls, and call ctx.runMutation() to write results back to the database.
ActionCtx Methods
Inside an action handler, ctx provides the following:
| Method / Property | Description |
|---|---|
ctx.runQuery(ref, args) | Run a query and return its typed result. Executes in its own read context. |
ctx.runMutation(ref, args) | Run a mutation in its own transaction. Each call is an independent atomic operation. |
ctx.runAction(ref, args) | Call another action. Useful for composing action logic. |
ctx.auth | Authentication context. Same Auth interface as queries and mutations. |
ctx.scheduler | Schedule future function execution. (Defined in type; implementation planned) |
ctx.storage | File storage access with upload, download, delete, and direct blob store. (Defined in type; implementation planned) |
ctx.runQuery and ctx.runMutation accept a function reference — the exported result of a query(), mutation(), or their internal* counterparts — and return a typed Promise.
Atomic Multi-Write Workflows
Eachctx.runMutation() call creates a separate, independent transaction. There is no shared transaction across multiple runMutation calls within one action. If you need multiple writes to succeed or fail together atomically, put all of the write logic inside a single mutation and call that mutation once from the action:
Use Cases
Calling external APIs (payment processing, email sending)
Calling external APIs (payment processing, email sending)
Actions are the correct place for any call to a third-party API. Because actions are not retried automatically, a charge or an email will not be sent twice if something else fails afterward.
Processing webhook payloads
Processing webhook payloads
Webhook handlers typically need to verify a signature, parse a payload, and write the result to the database. Actions support all of this naturally.
Fetching remote data and storing results
Fetching remote data and storing results
Fetch data from a remote source, transform it, and persist the results via a mutation — all in one action.
Orchestrating multiple mutations in sequence
Orchestrating multiple mutations in sequence
When a workflow requires interleaving reads, external calls, and writes, an action gives you the flexibility to sequence them step by step while keeping each write operation atomic within its own mutation transaction.
Internal Actions
UseinternalAction from baseflare/server to define actions that are callable only from the server — not from the public client API: