Coding Tools
Control coding agent costs
Use real usage data to spend less without weakening every task
Coding agents repeatedly send instructions, conversation history, code, and tool results. Long sessions can therefore cost much more than a single chat request. The useful levers are model choice, context size, output length, and caching when the selected model supports it.
Start with your own usage
Open Usage in the workspace that owns your API key and compare requests by model or key. Compare similar tasks rather than relying on a generic hourly estimate.
Record at least:
- input, output, and cached tokens
- cost per completed task
- failed or repeated requests
- the model and API key used
Match the model to the work
The most expensive model does not need to handle every step.
| Work | What to optimize |
|---|---|
| Architecture or difficult debugging | Reasoning quality and enough context |
| Focused edits and routine review | Reliable instruction following at a lower price |
| Search, classification, and boilerplate | Speed and low input cost |
| Final review | Quality on a smaller, carefully selected context |
Use the Models page for current prices and capabilities. Test candidate models on the same representative task before changing a production tool.
Keep context intentional
- Include the files and logs needed for the current task, not the whole repository by default.
- Start a new conversation when old history no longer helps.
- Let the agent search for code instead of pasting large directories into every prompt.
- Keep reusable instructions short and remove duplicated rules.
Limit unnecessary output
Set the output limit supported by your selected API format when the task has a predictable answer length. Chat Completions and Messages use different request shapes from Responses; use the endpoint’s documented field.
A limit prevents accidental long responses, but it should still leave enough room for the task to finish.
Use caching only when it is documented
Some models charge less for cached input. Check the model's price details before counting on a cache discount, and confirm cached-token usage in the response or Usage. Cache behavior and prices differ by model.
Separate projects with API keys
Use a different API key for each project or coding tool when you need separate limits and usage history. A key-level limit can stop one tool from consuming the full account balance.
Compare changes with real tasks
- Choose a small set of tasks that represents your normal work.
- Run the same tasks with each candidate model and the same context.
- Compare completion quality, retries, total tokens, and final cost in Usage.
The lowest price per token is not always the lowest cost per completed task. A cheaper request that needs several retries may cost more.