Start free →
n8n guide

How to set a hard OpenAI budget limit in n8n (without writing a single line of code)

2026-05-02 · 6 min read · PromptCost team

If you run AI workflows in n8n, you've probably noticed there's no built-in way to say "stop this workflow if it spends more than $50 this month." n8n's OpenAI and Anthropic nodes don't expose a budget knob. The provider's own dashboard offers alerts, not stops. And if you're running a dozen workflows on a single API key, you can't even tell which one is burning the budget.

Here's the fix, end-to-end, in under five minutes — and it doesn't require touching code.

What you'll end up with

Why n8n's native nodes won't work for this

n8n's OpenAI and Anthropic nodes are convenient but they don't let you change the base URL, and they don't expose any kind of cost field. You can read the response, sure, but to know what a call cost you'd have to maintain your own pricing table per model — and even then, you can't block calls based on a running total.

The cleanest path is the one n8n itself uses for every "we don't have a node for that" case: the generic HTTP Request node.

Step-by-step setup

01 —

Get a PromptCost key

Sign up free at admin.promptcost.io, create a workspace, and generate a key starting with sk-pc-. Takes about 60 seconds. No credit card required.

02 —

Replace your AI node with HTTP Request

In your n8n workflow, delete the OpenAI/Anthropic node and drop in a generic HTTP Request node in its place.

Configure it like this (Anthropic example):

Method:           POST
URL:              https://api.promptcost.io/anthropic/v1/messages
Authentication:   None  # we use header auth instead
Send Headers:     Yes
Send Body:        Yes
Body Content Type: JSON

For OpenAI, use https://api.promptcost.io/openai/v1/chat/completions.

03 —

Add the headers

Three headers do the work:

x-api-key:    sk-ant-••••••••••     # your provider key
cg-key:       sk-pc-••••3f9a         # your PromptCost key
cg-agent:     {{$workflow.name}}      # tag this workflow
Content-Type: application/json

The clever bit: use n8n's expression {{$workflow.name}} as the cg-agent value and every workflow auto-tags itself. No manual setup per workflow.

04 —

Paste the body unchanged

The body is identical to Anthropic's or OpenAI's API. If you were already using the native node, copy the JSON shape into the HTTP Request node's body:

{
  "model": "claude-haiku-4-5",
  "max_tokens": 1000,
  "messages": [
    { "role": "user", "content": "{{$json.prompt}}" }
  ]
}
05 —

Set the budget cap

In the PromptCost dashboard, go to your agent (it'll appear automatically after the first request), set a monthly USD cap, and save. Done. The next request that pushes the total over the cap gets a 429 from the proxy, and your workflow handles it like any other HTTP error.

Bonus: how to handle the 429 in n8n

You'll want your workflow to do something graceful when the budget is exceeded — send a Slack alert, fall back to a cheaper model, or just skip the run. The HTTP Request node returns a 429 with a body like:

{
  "error": "budget_exceeded",
  "message": "Monthly cap of $50 reached for agent 'lead-scorer'",
  "agent": "lead-scorer"
}

In n8n, set the HTTP Request node's "On Error" setting to "Continue (using error output)", then branch on the error output to a Slack node, an email, or a fallback path.

What about streaming responses?

n8n's HTTP Request node doesn't support SSE streaming, so you'll use non-streaming responses. PromptCost handles both, but for n8n specifically, just leave the body as standard non-streaming JSON.

What about Make.com, Python, or anywhere else?

Same pattern. The proxy is a thin layer in front of OpenAI and Anthropic, so anywhere you can make an HTTP request — Make.com's HTTP module, a Python requests.post(), a curl command — works identically. See the Make.com guide for that flow.

Stop guessing which workflow is burning your AI budget.

Per-workflow cost tracking. Hard budget caps. 60 seconds to set up. Free forever.

Start free →

Further reading