How to Monitor Your OpenClaw API Spend in Real Time

Your OpenClaw agent is making API calls. You need to know what that costs, right now. This article shows you how to see your usage and cost in real time, so you don’t get surprised by a monthly bill.

If you’re using a cheap provider like DeepSeek via OpenRouter, you might spend pennies a day. But if your agent is misconfigured or stuck in a loop on a premium model, that can turn into dollars per hour. The goal is to see the cost, not necessarily eliminate it.

We’ll cover three methods. First, using your provider’s dashboard. Second, setting up a simple logging command for your Claw. Third, using a community tool for tracking token spend across all your agents.

What You Need

To monitor your spend, you need to know where your agent is sending its API calls. The setup depends on your provider.

  • An OpenRouter API key: If you use OpenRouter as your gateway (the community default), you need your key to access its dashboard. The free tier works. Get it from openrouter.ai.
  • Your DeepSeek API key: If you call DeepSeek directly (not through OpenRouter), you need this key to check usage on their platform. Get it from platform.deepseek.com.
  • A running OpenClaw gateway: Your agent needs to be active and making calls for there to be any spend to monitor. Check this with openclaw gateway status in your terminal.
  • Your OpenClaw config file path: It’s at ~/.openclaw/openclaw.json. You or your Claw will need to read it to see which provider is configured as the default.

Setting Up Your Environment

1. Identify Your Current API Provider

Before you can check a dashboard, you need to know which provider your Claw is actually using. Your config file holds the answer.

You are my OpenClaw agent. Do the following:
1. Read my OpenClaw configuration file at ~/.openclaw/openclaw.json.
2. Find and tell me the current 'primary' model ID under 'agents.defaults.model'.
3. Also, check the 'models.providers' section and tell me which provider that model ID corresponds to (e.g., 'openrouter', 'deepseek', 'ollama').

What the Claw does: It reads your JSON5 config and parses the model settings. What you see: A response like “Your primary model is ‘openrouter/auto’. This uses the ‘openrouter’ provider.” or “Your primary model is ‘ollama/glm-4.7-flash’. This uses the ‘ollama’ provider.”

2. Get Your API Keys Ready

If your provider is a paid cloud API (OpenRouter, DeepSeek), you need your key to log into their usage dashboard. Your Claw can show you if the key is already saved in your config.

You are my OpenClaw agent. Do the following:
1. Safely check the OpenClaw config at ~/.openclaw/openclaw.json for any 'apiKey' fields under 'models.providers'.
2. For each provider you find (like 'openrouter' or 'deepseek'), tell me the first 6 characters of the API key and the last 4 characters, so I can identify it. Do NOT output the full key.
3. If no API key is found for a provider, tell me clearly.

What the Claw does: It scans the providers section and masks your API keys for security. What you see: Something like “Found key for ‘openrouter’: sk-or-v1-abc123…defg” or “No API key found for provider ‘deepseek’.”

If your Claw reports no key for your cloud provider, you need to add it. For OpenRouter, get a free key at openrouter.ai. Then have your Claw set it.

You are my OpenClaw agent. I need to set my OpenRouter API key. My key is: [PASTE_YOUR_FULL_KEY_HERE].
1. Update the OpenClaw config at ~/.openclaw/openclaw.json.
2. Set the API key for the 'openrouter' provider under 'models.providers.openrouter.apiKey'.
3. Confirm the change was made and remind me to restart the gateway with 'openclaw gateway restart'.

Step-by-Step: Monitor Your Spend

Here’s where you get the numbers. We’ll check your provider’s dashboard, set up a simple logging command, and look at a community tool for tracking everything.

Step 1: Check Your Provider’s Usage Dashboard

This is the most direct method. Your API provider tracks every call and shows you a running total.

You are my OpenClaw agent. Do the following:
1. Determine my current primary API provider by reading ~/.openclaw/openclaw.json.
2. Based on the provider, give me the exact URL to check my usage and spending.
 - If it's 'openrouter', the URL is: https://openrouter.ai/usage
 - If it's 'deepseek', the URL is: https://platform.deepseek.com/usage
 - If it's 'ollama' (local), tell me my cost is $0 and no dashboard exists.
 - If it's 'ollama' (cloud), the URL is: https://ollama.com/account/usage
3. Also, tell me the current pricing per million tokens for my primary model if it's a cloud API.

What the Claw does: It reads your config and gives you the direct link to your bill. What you see: A response like “Your provider is OpenRouter. Check your usage at https://openrouter.ai/usage. Your model ‘deepseek-chat’ costs $0.14 per million input tokens.”

You need to open that link in a browser and log in with your API key. The dashboard shows your usage for the current period, usually the last 30 days.

Gotcha: OpenRouter’s free tier has a usage limit. If you hit it, your calls will fail. The dashboard shows how close you are to the limit. For heavy use, you need to add billing credits.

Step 2: Set Up a Simple Logging Command

Dashboards are great, but you might want to see the cost as your agent works. You can have your Claw run a quick check after tasks.

This command fetches your usage from the OpenRouter API and calculates an estimated cost. It gives you a snapshot.

You are my OpenClaw agent. Do the following:
1. Read my OpenRouter API key from ~/.openclaw/openclaw.json.
2. Use curl to fetch my current usage data from the OpenRouter API.
3. Parse the response and show me: total tokens used today, total cost today (in USD), and my remaining free tier credits (if applicable).
Run this command:
curl -s -H "Authorization: Bearer YOUR_API_KEY" https://openrouter.ai/api/v1/auth/key | jq '.data.usage'

What the Claw does: It calls the OpenRouter key endpoint, which returns usage stats. What you see: A JSON block with fields like usage.today and credits. The cost is calculated from the token counts.

If you use DeepSeek directly, the API endpoint is different. Your Claw can adapt.

You are my OpenClaw agent. Do the following:
1. Read my DeepSeek API key from ~/.openclaw/openclaw.json.
2. Fetch my usage from the DeepSeek platform API.
3. Show me my total usage and estimated cost for the current billing period.
Run this command:
curl -s -H "Authorization: Bearer YOUR_DEEPSEEK_KEY" https://api.deepseek.com/user/balance | jq '.'
Gotcha: The DeepSeek API returns usage in their own credit units, not directly in tokens. As of April 2026, 1 credit ≈ 1,000 input tokens for DeepSeek-V3. Check their latest pricing page for the exact conversion.

Step 3: Install and Use the Community Monitoring Tool

For tracking multiple agents or getting detailed token-level logs, the community built a tool. It’s a Node.js script that tails your OpenClaw gateway logs and calculates spend in real time. It’s called `openclaw-cost-monitor`.

Your Claw can install and run it for you.

You are my OpenClaw agent. Do the following:
1. Install the 'openclaw-cost-monitor' npm package globally: npm install -g @openclaw/usage-monitor
2. Find the path to my OpenClaw gateway log file. It's usually at ~/.openclaw/logs/gateway.log.
3. Start the monitor tool, pointing it at my log file and my primary provider (e.g., 'openrouter').
4. Let it run for a few seconds while you perform a small task, then show me the output lines that display token counts and cost estimates.

What the Claw does: It installs the package, starts the monitor, and shows you sample output. What you see: Lines like [2026-04-08 10:15:23] Model: deepseek-chat | Input: 245 tokens | Output: 89 tokens | Est. Cost: $0.00005.

The tool reads each API call from the logs, looks up the model’s price per token, and does the math. It supports OpenRouter, DeepSeek, and Ollama Cloud pricing. This is a community package, not officially maintained by OpenClaw.

Doing it manually?

If you prefer to run the tool directly from your terminal:

# Install the monitor
npm install -g openclaw-cost-monitor

# Run it, specifying your log file and provider
openclaw-usage-monitor --log ~/.openclaw/logs/gateway.log --provider openrouter

# For DeepSeek direct API
openclaw-usage-monitor --log ~/.openclaw/logs/gateway.log --provider deepseek --price-input 0.00000014 --price-output 0.00000028
Gotcha: The tool needs accurate pricing data. For OpenRouter’s auto model router, the cost shown is an estimate based on the model that was actually selected for each call. For custom providers, you must specify the --price-input and --price-output flags in dollars per token.

Step 4: Create a Regular Spend Report

You can automate a daily or weekly summary. Have your Claw check your usage and send you a report via your preferred messaging surface, like Telegram or Discord.

This instruction sets up a cron job via your Claw that runs the check and can message you.

You are my OpenClaw agent. Do the following:
1. Create a shell script at ~/openclaw_spend_report.sh that fetches my OpenRouter usage and formats a simple message.
2. Make the script executable.
3. Set up a cron job to run this script every day at 9 AM and pipe the output to a command that sends a Telegram message (or store it in a file if I don't have a bot set up).
4. Show me the script content and the cron line you added so I can verify it.

Use this script template:
#!/bin/bash
API_KEY=$(jq -r '.models.providers.openrouter.apiKey' ~/.openclaw/openclaw.json)
DATA=$(curl -s -H "Authorization: Bearer $API_KEY" https://openrouter.ai/api/v1/auth/key)
TODAY_TOKENS=$(echo $DATA | jq -r '.data.usage.today.total_tokens // 0')
TODAY_COST=$(echo $DATA | jq -r '.data.usage.today.total_cost_usd // 0')
echo "OpenClaw Spend Report: Used $TODAY_TOKENS tokens today, estimated cost: \$$TODAY_COST"

What the Claw does: It writes the script, sets permissions, and edits your crontab. What you see: The script source and a confirmation like “Cron job added: 0 9 * * * ~/openclaw_spend_report.sh >> ~/spend.log”.

If you use Telegram, you can extend the script to use curl to call the Telegram Bot API with your message.

Safety Note: The script reads your API key from your config file. This is safe if your user account is secure. Do not run this on a shared or insecure system. For better security, your Claw can help you set environment variables instead of storing the key in the script.

Verifying Everything Works

You’ve set up monitoring. Now you need to know it’s actually working and reporting accurate numbers. A broken monitor is worse than no monitor. It gives you false confidence.

Run these checks to confirm your setup is live and capturing data.

Check 1: Verify the Gateway is Logging API Calls

This confirms the source data for your monitoring tools exists. If the gateway isn’t logging, the community monitor and your scripts will show zero usage. Run this check.

# Check if the gateway log file exists and has recent entries
tail -n 5 ~/.openclaw/logs/gateway.log | grep -E "(model|tokens|provider)"

What good output looks like: You’ll see recent JSON lines containing model names like "model":"openrouter/auto" and token counts. What bad output looks like: An error that the file doesn’t exist, or no matching lines. If the file is empty, your gateway might not be running or your log level is set too high.

Check 2: Verify Your Provider Dashboard Connection

This confirms your API key is valid and the dashboard is receiving data.

# Test OpenRouter key (replace $OPENROUTER_API_KEY with your key or use jq)
curl -s -H "Authorization: Bearer $(jq -r '.models.providers.openrouter.apiKey // empty' ~/.openclaw/openclaw.json)" https://openrouter.ai/api/v1/auth/key | jq -r '.data?.credits // "Error or no credits field"'

What good output looks like: A number representing your remaining credits (e.g., 10000 for the free tier). What bad output looks like: A JSON error message like {"error": {"message": "Invalid API key"}} or a null response. This means your key in the config is wrong or expired.

Check 3: Verify the Community Monitor is Calculating Costs

This confirms the installed tool can parse logs and apply correct pricing. Run it for a short burst while your agent is active. Use this command.

# Run the monitor for 10 seconds, then exit. Look for cost lines.
timeout 10 openclaw-usage-monitor --log ~/.openclaw/logs/gateway.log --provider openrouter 2>&1 | grep -i "est. cost"

What good output looks like: One or more lines with cost estimates, e.g., Est. Cost: $0.00012. What bad output looks like: No output, or error messages like “Provider pricing not found for model: openrouter/auto”. This usually means you need to specify custom pricing flags or the tool can’t map your model.

If Something Goes Wrong: Rollback

If a verification step fails, you need to cleanly undo changes without breaking your working OpenClaw setup. The goal is to return to a known-good state. Follow these steps.

Your agent’s configuration and message history are stored separately. They will survive these rollbacks.

Undo the Community Monitor Installation

If the openclaw-usage-monitor tool is causing errors or you don’t want it, uninstall it.

# Uninstall the global npm package
npm uninstall -g openclaw-cost-monitor

# Remove any leftover cron jobs you created for reporting
crontab -l | grep -v "openclaw_spend_report" | crontab -

This removes the tool and any automated reporting cron jobs. Your OpenClaw gateway and config remain untouched.

Undo Script and Cron Job Creation

If you created the ~/openclaw_spend_report.sh script and cron job, remove them.

# Delete the script file
rm -f ~/openclaw_spend_report.sh

# Remove the specific cron job without editing other entries
crontab -l | grep -v "openclaw_spend_report" | crontab -

This deletes the script file and cleans your crontab. Your API keys remain in your OpenClaw config.

Reset Your OpenClaw Configuration

If you suspect changes to your openclaw.json config file are causing issues (like a bad API key), you can revert just the provider settings while keeping your agent and connection configs.

First, back up your current config. Then, if you know your previous working provider (like Ollama), have your Claw switch back.

You are my OpenClaw agent. Do the following:
1. Create a backup of my current config: cp ~/.openclaw/openclaw.json ~/.openclaw/openclaw.json.backup_$(date +%s)
2. Change my primary model provider back to a known-working setup. Set the primary model to 'ollama/glm-4.7-flash'.
3. Confirm the change and tell me to restart the gateway with: openclaw gateway restart

This reverts your model to a default local/cloud Ollama model, which has zero cost and will stop all cloud API spending immediately. Your chat histories and agent setup are preserved.

When Things Break

This section covers common problems and how to fix them quickly.

Problem: Dashboard shows zero usage, but my agent is working

What’s happening: Your OpenClaw agent is using a different provider than you think. The most common cause is a fallback to the bootstrap provider, like OpenAI, because your primary provider, such as Ollama Cloud, is down or hitting rate limits.

Fix:

You are my OpenClaw agent. Do the following:
1. Check the last 10 entries in the gateway log: tail -n 10 ~/.openclaw/logs/gateway.log | grep -o '"model":"[^"]*"' | head -5
2. Tell me which model is actually being called in the logs.
3. Cross-check this with my configured primary model in ~/.openclaw/openclaw.json.

Why this works: The logs show the real API calls. If you see `gpt-4` but your config says `ollama/kimi-k2.5:cloud`, your agent fell back. You need to check the health of your primary provider.

Problem: “Invalid API key” error when running the curl check

What’s happening: The API key stored in your `openclaw.json` config is incorrect, expired, or has extra whitespace or newline characters. JSON5 is picky about string formatting.

Fix:

You are my OpenClaw agent. Do the following:
1. View the raw apiKey value for my openrouter provider: jq -r '.models.providers.openrouter.apiKey | tostring' ~/.openclaw/openclaw.json | cat -A
2. If you see a `$` at the end of the line (a newline), fix it by setting the key again.
3. Use this command to set it cleanly: openclaw config set models.providers.openrouter.apiKey "sk-or-v1-abc123..." (using my actual key).
4. Restart the gateway: openclaw gateway restart.

Why this works: The `cat -A` command reveals invisible characters. Setting the key via the `openclaw config` CLI ensures it’s written as a clean JSON string.

Problem: Community monitor shows “Provider pricing not found for model: openrouter/auto”

What’s happening: The `openclaw-usage-monitor` tool cannot map the routed model name, like `deepseek-chat`, to a price. This happens because OpenRouter’s `auto` router doesn’t log the selected model in the standard log field.

Fix:

# Run the monitor with a default price for estimation
openclaw-usage-monitor --log ~/.openclaw/logs/gateway.log --provider openrouter --price-input 0.00000014 --price-output 0.00000028

# Or, switch your config to a specific model for predictable pricing
openclaw config set agents.defaults.model.primary "openrouter/deepseek-chat"

Why this works: Specifying the `–price-input/output` flags gives the tool a fallback price (DeepSeek’s rate). Better yet, locking your agent to a specific model like `deepseek-chat` makes costs predictable and logs clear.

Problem: DeepSeek balance API returns credits, but I need token counts

What’s happening: DeepSeek’s `/user/balance` endpoint returns credit units, not token counts. As of April 2026, 1 credit is about 1,000 input tokens for DeepSeek-V3. But you need the token-level detail to match your logs.

Fix:

You are my OpenClaw agent. Do the following:
1. The gateway log has the true token counts. Parse the last 5 calls for DeepSeek: jq -r 'select(.model | contains("deepseek")) | "Input: \(.usage.prompt_tokens), Output: \(.usage.completion_tokens)"' ~/.openclaw/logs/gateway.log | tail -5
2. Calculate the estimated cost: (Input Tokens * 0.00000014) + (Output Tokens * 0.00000028).
3. Report the total tokens and cost for these recent calls.

Why this works: The OpenClaw gateway logs the exact token usage from the API response. Calculating from the logs is more accurate than converting credits.

Problem: Cron job for daily report runs but sends no message

What’s happening: The script is likely failing silently. This could be due to a missing `jq` command, an incorrect API key path, or a permissions issue. Cron runs in a minimal environment.

Fix:

# 1. Check for errors by logging stderr
# Edit your cron job to redirect all output to a file
# In crontab: 0 9 * * * ~/openclaw_spend_report.sh >> ~/spend.log 2>&1

# 2. Manually run the script with the full cron environment
env -i bash -c "~/openclaw_spend_report.sh"

# 3. Common fix: Provide the full path to `jq` in your script
# Replace `jq` with `/usr/bin/jq` or wherever it's installed (find with `which jq`)

Why this works: Cron doesn’t load your user’s `$PATH`. Using full paths to binaries, like `/usr/bin/curl` and `/usr/bin/jq`, and logging errors reveals the root cause.

Frequently Asked Questions

My dashboard shows a charge, but I use Ollama locally. Why?

You are not using Ollama locally for all calls. Check your gateway logs. Your configuration likely has a fallback provider (like OpenAI or Anthropic) that is being used when the local Ollama model times out, errors, or when a specific tool requires a more capable model. Run: grep -o '"model":"[^"]*"' ~/.openclaw/logs/gateway.log | sort | uniq -c to see all models called.

Can I monitor spend across multiple OpenClaw agents on one server?

Yes, if they all log to the same gateway log file (the default). The `openclaw-usage-monitor` tool will aggregate all calls. If you run separate gateway instances with different log files, you need to run the monitor tool for each log file and sum the costs manually, or write a script to tail multiple logs.

OpenRouter’s free tier credits reset monthly. How do I track my cycle?

The OpenRouter dashboard at openrouter.ai/usage shows your credit reset date. Your Claw can also fetch this via API. Ask it: “Fetch my OpenRouter credit info and tell me my total credits, used credits, and the reset date.” It will use the `curl` command from Step 2 and parse the `data.credits` and `data.usage.period` fields.

Is there a way to set a hard spending limit and stop the agent?

OpenClaw itself does not have a built-in budget cut-off. However, you can create a safety script. Have your Claw check usage every hour via API; if the cost exceeds a threshold, it can run openclaw config set agents.defaults.model.primary "ollama/gemma4" to switch to a zero-cost local model and notify you. This requires setting up a cron job or a loop within a supervised process.

The community monitor tool is no longer maintained. What’s the alternative?

The state-of-the-art alternative is to use the provider’s official API directly, as shown in Step 2. For real-time alerts, pipe your gateway logs to a simple script that uses `grep` and `jq` to extract token counts and calculate cost, then send a notification via a messaging webhook when a single call exceeds a set threshold (e.g., $0.10).

Keep Reading

Similar Posts