Basic Agents / Lesson 5

Paying for It: API Keys, Credits, and Subscriptions

How billing actually works, pre-paid vs post-paid models, the costs nobody tells you about, and how to keep your spending under control.

Goal

Understand the full cost picture of running agents and know how to prevent surprise bills

What You'll Need

⏱ Time: 10 minutes  |  📋 Tasks:

  • Your API provider account open (OpenAI, Anthropic, etc.)
  • The billing or usage page pulled up

Billing Models: Pre-Paid vs Post-Paid

Every API provider uses one of two billing models, and they work differently than a typical SaaS subscription.

Pre-Paid (Credits)

You add money to your account upfront, then usage deducts from that balance. OpenAI and most providers work this way. You deposit $10, $50, or $100, and your usage draws from that pool.

Pros: You can't accidentally spend more than you deposited. Easy to cap your spending.

Cons: If you run out mid-task, the agent fails with an "insufficient credits" error. Most providers auto-reload, so watch that setting.

Post-Paid (Invoice)

You use the service and get billed at the end of the month. Anthropic and enterprise plans work this way.

Pros: No interruptions. You don't have to guess your usage in advance.

Cons: It's easy to lose track of spending. Without limits, a runaway agent can generate surprising bills.

For your first agent, start with pre-paid. Add a small amount ($10-20) and watch your usage for a week. You'll quickly learn your pattern, and the hard cap prevents surprises.

Rate Limits and Concurrency

Even with money in your account, the provider limits how fast you can make requests. These limits affect how quickly your agent can work.

  • Requests per minute (RPM) — How many API calls you can make in 60 seconds. Typical tiers: 60 RPM (free), 500 RPM (Tier 1), 5000+ RPM (higher tiers).
  • Tokens per minute (TPM) — How many tokens you can process in 60 seconds. This is usually the binding constraint for agents that send large contexts.
  • Concurrency — How many requests can be in flight at once. Lower tiers limit to 1-3 concurrent requests.

If you find your agent is slow, check whether you're hitting rate limits. The solution is usually either: wait (usage-based tiers auto-upgrade), or increase your billing tier. Most providers raise your limits as you spend more.

The Costs Nobody Mentions

Beyond the per-token price, three costs catch new agent users off guard:

1. Context Caching

Every time you start a new agent session, the harness may re-read the same project context — your README, your directory structure, your instructions file. If your project has 50,000 tokens of context and you start 10 sessions, that's 500,000 input tokens you paid for, even if the agent only does a small task.

What to do: Keep your context lean. Only include files the agent actually needs. Some harnesses let you set a project context file explicitly rather than scanning the whole directory.

2. Image and File Inputs

When you ask an agent to read an image, screenshot, or PDF, the model processes it as visual tokens — which are vastly more expensive than text tokens. A single screenshot can cost 100-1000x what a text prompt costs, depending on resolution.

What to do: Don't feed images to the agent unless you need them. If you're sending a PDF, extract the text first rather than attaching the file directly.

3. Tool Call Overhead

Every time the agent decides to call a tool, the model generates "thinking tokens" — internal reasoning about which tool to use, what arguments to pass, and how to interpret the result. These tokens are invisible to you but appear on your bill. A task that makes 50 tool calls might have 30-50% more tokens than you'd estimate from the prompt and response alone.

What to do: Factor 1.5x into your cost estimates. If you calculate a task should cost $1.00, expect about $1.50 in practice.

Setting a Budget

Every major provider lets you set spending limits. Use them. Here's how:

OpenAI

Go to Settings > Billing > Usage limits. Set a hard cap (e.g., $50/month). OpenAI will stop serving requests when you hit it. You can also set email alerts at lower thresholds ($10, $25, etc.).

Anthropic

Go to Console > Billing > Spending limits. Set a monthly budget. Anthropic will alert you at 50%, 80%, and 100% of your budget.

Opencode / Local Budget

Some harnesses let you set a per-task or per-session budget. This is your safety net — even if the provider's limits fail, the harness can stop the agent when it exceeds your configured threshold.

Rule of thumb: Set your first month's budget to $20. After 30 days, check your actual usage. If you used $8, set it to $15 for next month. If you used $35, set it to $50. Adjust after you know your pattern.

Your Takeaway — The Monthly Cost Review

Set a recurring reminder to review your API usage once a month. It takes 2 minutes and prevents surprises. Check three things:

  • Total spend — Did you stay within budget?
  • Top-cost tasks — Which agent tasks cost the most? Are they worth it?
  • Rate limit hits — Did you hit any limits? Would a higher tier help?
← Setting Up Your First Agent When to Stay in the Browser →