Skip to Content
Building agents

Agents are only billed while they're working

You don't pay for compute while your AI agent waits for a user reply, an approval or a webhook. See what stops billing, what keeps an agent billed, and when an idle agent's run ends.

On Trigger.dev Cloud, you pay for an agent's compute while its code is running, not while it waits for a user, an approval or a webhook. By default an agent stays on for 30 seconds after each reply before billing stops, and every run also has a small invocation cost.

When an agent is billed

  • Working means its code is running on a machine. That includes waiting for the model to reply, because your code is still running.
  • Waiting means it's waiting on something outside itself, like the user's next message. Billing stops once the agent is in the wait, after the wait itself is set up (for example, triggerAndWait() first triggers the child task). For the user's next message, it stops once the short idle window below ends. Soon after, we save the agent and switch the machine off, which we call suspending. When there's something to do, we switch it back on and your code carries on from the same line, with its variables intact. Nothing is replayed.

With the settings in the example below, an agent that works for 10 seconds and then waits a day for a person to reply is billed for the 10 seconds, not the day, plus the run's invocation cost.

An agent stays on for 30 seconds after each reply

After each reply, the agent stays on in case the user answers quickly. That time is billed, and the agent keeps its concurrency slot. Set idleTimeoutInSeconds to 0 to skip that window, so billing stops right after each reply, once any onChatSuspend hook has run, unless a message is already waiting. The agent suspends soon after if it's still waiting.

The run ends after an hour without a message

If no message arrives within an hour after that idle window, the run ends. The next message starts a new run that picks the conversation up from transcript storage. That's slower than waking a suspended agent, the new run has its own invocation cost, and it runs on your latest deployed version, unless the session is pinned to a version. Change the hour with turnTimeout.

A refund agent stops billing while it waits for approval

This agent asks before it issues a refund, and billing stops while it waits for the user to approve.

trigger/support-agent.ts
import {  } from "@trigger.dev/sdk/ai";
import { ,  } from "ai";
import {  } from "@ai-sdk/anthropic";
import { z } from "zod";
import {  } from "@/lib/refunds"; // Your own refund code

const issueRefund = ({
  description: "Refund an order after the user approves.",
  inputSchema: z.object({ orderId: z.string() }),
  needsApproval: true,
  execute: async ({ orderId }) => (orderId),
});

export const supportAgent = .({
  : "support-agent",
  : { issueRefund },
  : 0, // Stop billing as soon as each reply ends
  : "24h", // Keep the run open for a day between messages
  : async ({ , , ,  }) => {
    return ({
      : ("claude-sonnet-5-5"),
      messages,
      ,
      : ,
      : (15),
    });
  },
});

See human-in-the-loop for the frontend side.

What stops billing

Billing stops while an agent waits on something outside itself:

What keeps an agent billed

Everything else, including:

  • The idle window after each reply (30 seconds by default)
  • Waiting for a model or API to reply (streamText(), generateText(), fetch())
  • Running tools
  • Polling, setTimeout and sleep helpers
  • Streaming a sub-agent's reply with chat.forwardSubAgent()
  • Listening on an input stream with .once() or .on()
  • A wait.for() or wait.until() of 5 seconds or less, which runs in your process

If your agent polls another system, have that system complete a wait token or send a webhook instead. Your agent then stops billing while it waits.

Other details that affect what you pay

  • Suspended agents don't use your concurrency. An agent keeps its slot during the idle window and until it's suspended. When it wakes up, it keeps its original place in the queue, so it usually runs before newer runs. A newer run with a higher priority can still go first.
  • Subtasks are billed separately. A subtask started with triggerAndWait() is billed for its own working time and has its own invocation cost.
  • Waiting time doesn't count toward maxDuration. The idle window after each reply does.
  • Database connections can be closed while an agent is suspended. Use a pool that reconnects (details).
  • An agent that wakes up runs on the version it started on, even if you deploy while it's waiting (version locking).

Check what an agent cost

Once a run finishes, its details panel in the dashboard shows its usage duration, invocation cost and compute cost. See pricing for rates and how to reduce your spend for other savings.

Was this page helpful?

Last updated

Edit on GitHub

On this page