Track LLM web search costs by assigning each provider request to a customer and recording the billable searches alongside token usage. A single answer can require several searches, and a request that fails to produce a usable answer can still consume model tokens. Counting user messages or successful answers alone leaves those costs out of the ledger.
Record searches separately from model usage
Capture the organization, feature, application operation ID and provider attempt ID when your server submits the request. For each attempt, record the deployed model, tool variant, reported token categories, search count if available, and the pricing schedule in effect. Keep the source of every quantity. A tool event count derived from a partial stream carries less evidence than a count in a final usage object.
The unit of billing depends on the tool and model. OpenAI documents web search call fees and search content tokens. For example, it describes a fixed 8,000-token input charge per call for the non-preview search tool on two specified mini models. Anthropic documents a search fee in addition to token costs for search-generated content. Its tool-use limit and billable count also have different semantics. Failed searches count against the limit. Store the pricing rules for the specific path you use. OpenAI API pricing and Claude web search tool
Keep the search fee separate from the token estimate. Where the reported input total already includes tokens from search results, adding a separate estimate for those tokens counts them twice. Where a provider applies a fixed billing adjustment, record the adjustment under the rule that produced it. This makes a difference explainable when you change tools or compare two providers.
Measure a search limit against finished work
Suppose your SaaS product drafts supplier summaries. In a hypothetical replay, the current configuration handles 100 requests, issues 240 billable searches and produces 90 summaries that pass the team's review rubric. A lower search limit issues 140 searches and produces 84 accepted summaries. Use an illustrative search fee of one cent per search and assume the provider's token charges total three dollars and two dollars respectively.
| Configuration | Search fees | Token charges | Accepted summaries | Cost per accepted summary |
|---|---|---|---|---|
| Current limit | $2.40 | $3.00 | 90 | $0.060 |
| Lower limit | $1.40 | $2.00 | 84 | $0.040 |
The lower limit reduces cost per accepted summary by about two cents. It also leaves six more requests without an accepted result. Review those six cases before changing the default. If most require comparing several suppliers, preserve a higher limit for that feature and test the lower limit on single-supplier searches. If staff finish the failed cases manually, include their time when you compare the policies.
Reconcile missing usage before setting a spending alert
Sum the search and token estimates over the same billing account, product, currency and time window as the provider export. Compare each charge category where the export supports that split. If several customers share a provider project, your request records supply the customer attribution. Keep unmatched provider charges in an explicit unallocated bucket until you identify the source.
A client disconnect can prevent you from seeing terminal usage. If you retry, give the new attempt its own row under the same application operation. Mark unresolved usage as missing and reconcile it with the aggregate bill. Replaying the same usage event should update one row. Submitting a genuine second provider attempt should create a second row. Otherwise a duplicate delivery can inflate the total or a retry can disappear from it.
You can use request-level customer cost tracking for the rest of the ledger. Alectura supports provider tools and organization-level spend policies. Compare the spend recorded for a test request with the provider's search and token charges before using it as an alert for total spend. Review cost tracking and spend limits for the applicable budget controls.
Source documents (2)
- OpenAI API pricingChecked
- Claude web search toolChecked
Trace a request through Alectura.
Bring a sample prompt and a customer policy. See what reaches the model and which decisions appear in the request record.