[All posts](https://hostlinku.com/en/blog)

Guides 3 min read

# Trace an API charge back to the request

Give each workload its own key, capture the request ID, and use Console to explain a spike without logging prompts.

By the Hostlinku team

On this page

Suppose a nightly job costs more than usual. Its application logs show 500 completed records, and yesterday’s run also shows 500. The difference can still come from longer inputs, fewer cached tokens, or retries that made additional model calls. With a key dedicated to that job and a request ID for each attempt, you can check which of those happened.

## Give each workload an identifiable key

Create separate keys for production workers, interactive tools, and local experiments. Use names that reflect what they run, and set a spending limit for each workload where appropriate. Keep the key value in your secret store. In application logs, write an internal workload label and the attempt number, without copying the key or request headers.

From job attempt to recorded cost

Application logs`Job ID + attempt number`

Workload

Key label and job ID

Correlation

Attempt number and timestamp

-   Attempt identified
    
    Read the request ID from its response metadata.
    
-   Job retried
    
    Keep the attempts separate. Each can have a different request ID.
    

Select a checkpoint to follow a single attempt from the application to Console.

## Follow a single attempt into Request Logs

1.  Capture the response’s `x-request-id` when available. Pair it with the application job ID and the time of the attempt so you can follow retries individually.
2.  In Console, find that ID in Request Logs. Read the model, status, usage, latency, and recorded cost together. Where available, compare cache token fields and time to first token with a normal run.
3.  Check how many attempts the application made for the same job. For streaming requests, use the recorded cost in Console once usage has settled. A partial stream can leave the application with little usage information.

## Explain the spike before changing limits

Use Analytics for the trend and individual requests for the explanation. If output grew, inspect whether a template or model setting changed. If cached input fell, compare the repeated portion of the prompt and cache conditions. If errors rose, check the API status and your retry policy. For historical billing, use the cost stored on the request because some analytics breakdowns reflect current rates.

A `402` can indicate insufficient organization balance or an exhausted key limit. Read the error before changing either. A `429` calls for checking the applicable rate limit and retrying with backoff. A key that identifies the workload makes those decisions easier to verify with the next run. [Usage and limits](https://docs.hostlinku.com/en/usage-and-limits)

## Sources

1.  [Usage and limits](https://docs.hostlinku.com/en/usage-and-limits) · Hostlinku Docs

## More to read

-   [
    
    Guides · 3 min read
    
    How to tell when your prompt cache is working
    
    
    
    ](https://hostlinku.com/en/blog/measure-prompt-cache-hits)
-   [
    
    Guides · 4 min read
    
    Connect OpenCode to the models your key can use
    
    
    
    ](https://hostlinku.com/en/blog/open-code-catalog-by-key)
