By · · Updated

Spend Control for AI Agents: See the Price Before Anything Runs

Stop agents and automations from running up surprise bills: price every generation first, approve the USD amount, then generate, with limits the agent cannot raise.

A brass ticket dispenser in a dark room pushing out a long paper strip, with one red ticket on the floor.Türkçe oku ↗

Raywake shows the price first. Every generation, from the API or through the MCP server, is priced for its exact input before anything runs, and nothing is spent until something approves that price. This guide shows how to put that approval into your own code, how the MCP server applies the same flow in Claude, ChatGPT and Cursor, and how to see afterwards which agent spent what. The same rules cover all 500+ models on Raywake, from image and video to audio.

The rule: quote, approve, generate

One Raywake generation is three steps:

  1. Quote. POST /v1/quotes with a model ID and the complete input. The response carries quote_id, price_usd and expires_at (at most 10 minutes away). Requesting a quote does not start a job or spend funds.

  2. Approve. Your code, your budget rule or a person looks at price_usd and says yes or no.

  3. Generate. POST /v1/generate with the same model, the same input, the quote_id and an Idempotency-Key header. Change one field of the input or wait past expires_at, and the API answers 409 instead of running something you never priced.

For models billed by what they produce, such as seconds of video, the quote is an upper bound: you are charged the measured amount and a generation never costs more than its quote. Details are in Quotes and funds and the quotes reference.

Put the approval gate in code

Quoting and generating both need the key's generate permission, so the approval step has to live in your code (or in your MCP client, covered below). The pattern is short: quote, compare against a hard ceiling, ask, then generate with the quoted input.

MODEL="nano-banana-pro"
INPUT='{"prompt":"A red ceramic cup on a wooden table, soft morning light","aspect_ratio":"1:1"}'
MAX_USD="0.50"

# 1. Quote: prices this exact input. No job starts, nothing is spent.
QUOTE=$(curl -s https://api.raywake.com/v1/quotes \
  -H "Authorization: Bearer $RAYWAKE_API_KEY" \
  -H "Content-Type: application/json" \
  -d "$(jq -n --arg m "$MODEL" --argjson i "$INPUT" '{model: $m, input: $i}')")
PRICE=$(echo "$QUOTE" | jq -r .price_usd)
QUOTE_ID=$(echo "$QUOTE" | jq -r .quote_id)
echo "$MODEL: $PRICE USD, valid until $(echo "$QUOTE" | jq -r .expires_at)"

# 2. Budget rule, then a human yes. Anything else stops here.
awk -v p="$PRICE" -v m="$MAX_USD" 'BEGIN { exit !(p <= m) }' || { echo "Over budget"; exit 1; }
read -r -p "Generate for $PRICE USD? [y/N] " OK
[ "$OK" = "y" ] || exit 0

# 3. Generate with the SAME model, input and quote_id.
#    Keep KEY: retrying with it returns the same job instead of starting a second one.
KEY=$(uuidgen)
curl -s "https://api.raywake.com/v1/generate?wait=true" \
  -H "Authorization: Bearer $RAYWAKE_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $KEY" \
  -d "$(jq -n --arg m "$MODEL" --argjson i "$INPUT" --arg q "$QUOTE_ID" '{model: $m, input: $i, quote_id: $q}')"
# If the job is not terminal yet: GET https://api.raywake.com/v1/jobs/JOB_ID every 2-5 seconds.

Three details make this safe in production:

  • The ceiling is a number. price_usd is a decimal string; compare it with Decimal (Python) or a parsed number before anyone is asked.

  • One idempotency key per intended generation. If the generate call times out, retry with the same key and body: you get the original job back, not a second paid one. The same key with a different body returns 409.

  • A timeout is not a failure. submission_unknown, needs_review and needs_reconciliation are held states: the funds stay reserved and the job can still turn succeeded or failed. The loops above stop on them so a person can look; check the job again later and never submit a replacement automatically. The statuses are listed in Generations.

Limits the agent cannot raise

Code-level gates are only as good as the code. Raywake adds account-level limits that sit outside the agent:

  • Spending limits per hour or per 24 hours. Set them on the Alerts page in the studio. A generation that would cross one returns 429 with X-Limit-Reason: spend_limit and a Retry-After header. The limits cover the studio and every API key, and they can only be changed from the studio, so an agent holding an API key cannot lift its own ceiling. See Errors and limits.

  • Key permissions and expiry. Each key carries only the permissions you pick: models:read, generate, jobs:read, wallet:read. A reporting job only needs jobs:read and wallet:read. A key can expire after 30 days, 90 days or 1 year, and you can revoke it at any time. See Authentication.

  • Not enough funds is a hard stop. If the available balance does not cover the quote, generate returns 402.

The same flow through MCP

The Raywake MCP server gives Claude, ChatGPT, Claude Code, Cursor and other MCP clients the full catalog with the same quote-first rule. generate is the only tool that spends balance, and it needs a quote for the exact model and input. The others, such as search_models, get_model, quote, get_job, list_jobs and get_account, only read or price. For a comparison with other MCP servers for media generation, see MCP servers for image and video generation.

Hosted connector, nothing to install:

bash
claude mcp add --transport http raywake https://mcp.raywake.com/v1

When you connect with your Raywake account, you choose a spending limit per generation, so even an approved generation cannot go past that cap. The connection expires after 30 days, and you can disconnect it in settings at any time.

Local package over stdio (Node.js 20+), with the key in the environment, not in your prompt:

bash
claude mcp add raywake -e RAYWAKE_API_KEY=$RAYWAKE_API_KEY -- npx -y @raywake/mcp

The assistant is instructed to quote, show you the USD price and expiry, and wait for your approval before calling generate. Know the limit of that: the server cannot verify that a person actually said yes in the chat. So also set your MCP client to ask for confirmation before the paid generate tool. Then a model that skips the rule still hits a confirmation prompt, and the spending limits above still apply.

A prompt that works well:

text
Quote a 5-second Kling 4.0 video of a burger assembling itself. Show me the price in USD and ask me before generating.

Which agent is spending the budget?

Give every agent or scheduled workflow its own API key. Each job records source (api or studio) and the api_key_id that started it, so attribution is a filter, not a guess:

# Available and reserved balance (needs wallet:read)
curl -s https://api.raywake.com/v1/wallet \
  -H "Authorization: Bearer $RAYWAKE_API_KEY"

# Last 7 days: totals, per day, per model, failure reasons (needs jobs:read)
curl -s "https://api.raywake.com/v1/usage?days=7" \
  -H "Authorization: Bearer $RAYWAKE_API_KEY"

# Every job one agent's key started since Monday, with charged_usd on each
curl -s "https://api.raywake.com/v1/jobs?api_key_id=AGENT_KEY_ID&since=2026-11-30T00:00:00Z&limit=500" \
  -H "Authorization: Bearer $RAYWAKE_API_KEY"
  • GET /v1/wallet returns available_usd, reserved_usd (held by running jobs) and debt_usd. See Wallet.

  • GET /v1/usage?days=7 (also 30 or 90) returns totals, a per-day series, a per-model breakdown sorted by spend and failure reasons with counts. See Usage.

  • GET /v1/jobs filters by api_key_id, source, model, status, since and until, and every job carries charged_usd. See Jobs.

Checklist

  • One API key per agent or workflow, with only the permissions it needs and an expiry.

  • Hourly and daily spending limits set on the Alerts page.

  • Every generate call preceded by a quote and a check against a ceiling.

  • One saved Idempotency-Key per intended generation, reused on retries.

  • Held statuses checked later, never resubmitted automatically.

  • For MCP: a per-generation limit chosen at connect, plus client confirmation on generate.

The same flow as an importable n8n workflow waits for a human approval link before it generates. For a worked example with real models, see product photos with an API, without breaking the label.

Read the API quickstart
← All articles