A coding session rarely costs just one prompt and one answer. An agent may inspect files, propose changes, read test failures, and revise its patch. Each model request can add billable tokens. Before you start, build a small estimate around the work, the context, and the number of turns you expect.
This preflight checklist gives you a practical spending target without pretending you can predict every tool call.
1. Define one task and its stopping point
Write a scope statement before opening your coding agent: Add validation to the signup endpoint and update its tests. Include what counts as done, such as passing the relevant test suite and reviewing the diff.
Explicitly exclude nearby work: no dependency upgrades, unrelated refactors, or documentation sweep. A narrow stopping point makes the expected request count easier to estimate and prevents a small fix from becoming an open-ended repository cleanup.
2. Choose the model and record its token rates
Select the model you intend to use, such as Claude Sonnet 5.5, then check its current input and output rates through your provider. Record the billing unit, usually a price per million tokens. Do not assume input and output cost the same.
SwiftRelay is a practical option for this workflow because its pay-as-you-go, per-token billing lets you budget around a specific task. Sign up for SwiftRelay to use the small gift credit available to new accounts while checking your estimate against actual usage.
If cached input or other token categories have separate prices, record those too. Treat unconfirmed cache savings as zero in your initial budget.
3. Inventory the context the agent will receive
List the likely inputs rather than counting only your opening message:
- System instructions and repository guidance.
- Source files, test files, and relevant documentation.
- Conversation history and previous model responses.
- Tool results, including search matches and test logs.
Use a tokenizer or client-provided token counter when available. Otherwise, make a rough estimate and label it as uncertain. Generated files, lockfiles, and verbose logs deserve special attention because they can inflate context without helping the task.
4. Estimate cumulative tokens across all requests
A file read once can remain in the conversation and be sent again on later requests. Estimate total input across the session, not just the size of the initial context.
For a small change, you might plan for eight model requests averaging 12,500 input tokens each. That produces 100,000 cumulative input tokens. If those requests generate 1,500 output tokens each on average, the session produces 12,000 output tokens.
These are planning assumptions, not typical usage guarantees. Adjust them for your agent's context handling, expected patch size, and likely debugging turns. Tool output generally contributes to input when it is sent back to the model.
5. Calculate a baseline with clearly labeled prices
Use this formula: estimated cost = input tokens ÷ 1,000,000 × input rate + output tokens ÷ 1,000,000 × output rate.
For illustration only, suppose input costs $3 per million tokens and output costs $15 per million tokens. These are hypothetical rates, not a SwiftRelay quote or a price for the model named above.
- Input: 100,000 ÷ 1,000,000 × $3 = $0.30.
- Output: 12,000 ÷ 1,000,000 × $15 = $0.18.
- Baseline session estimate: $0.48.
6. Reserve room for retries and set a stop rule
Add a contingency for failed tests, misunderstood requirements, and extra file inspection. In this example, a 25% reserve adds $0.12, making the working budget $0.60. A more uncertain task deserves a larger reserve.
Set a checkpoint before spending that reserve: pause after the first patch and test run. Configure a spending limit if your tooling supports one; otherwise, check usage manually. A written budget alone does not enforce a cap.
7. Compare the first checkpoint with your estimate
At the checkpoint, inspect reported token usage and charges. If context is growing faster than expected, narrow file access, trim logs, or start a fresh, focused session with a concise handoff.
Record the final scope, request count, token totals, and cost. That small session log turns your next preflight estimate from guesswork into a budget grounded in your own coding habits.