OpenRouter Inference Cost

The idea is:

The existing OpenRouter node be extended to capture the inference costs that OpenRouter returns with calls to their API. Right now the inference statistics do not seem to be surfacing (or maybe I just don’t know how to get it??)

My use case:

I’m using OpenRouter to perform inference. I want to know the exact cost of each inference and be able to aggregate it across a workflow.

I think it would be beneficial to add this because:

Knowing how much stuff costs is important. Tracking costs on the OpenRouter access token level is not granular enough and also require going through OR to get the spend which is aggregated across all projects/flows. It would be very nice to know the execution of a workflow cost exactly so much.

Any resources to support this?

Are you willing to work on this?

Yes, I’m willing to help, but I’ve not done any n8n Node development yet.

You want to go further than just outputting the cost in the data and have it directly visible at the workflow execution level (in the UI or execution metadata).

That’s trickier, because today n8n doesn’t have a native “cost” field attached to an execution, nor a standard mechanism to display custom metrics in the execution list. The most realistic approach is to store the cost as “execution metadata” (if/when this is exposed); otherwise, write it during the run via a node (Data Store, database, logs) and display it through an external dashboard. To make this a real feature, you’d need to open a request on the n8n core side for “custom execution metrics” and propose that the OpenRouter node pushes usage/cost into those metrics.

Good points. I agree that tracking cost as an execution metric would be awesome.

I’m just getting started with n8n, so haven’t fully explored everything yet.

Some googling around indicated that I could roughly approximate this as it seems some of the AI inference nodes emit something along the lines of [ item.json.usage.prompt_tokens, item.json.usage.completion_tokens] and then use a lookup table to roughly approximate how much the inference was, but I’ve found an example workflow demonstrating this

Yes, you can already approximate the cost with OpenRouter: the node returns the model plus usage.prompt_tokens and usage.completion_tokens, and then you can call the OpenRouter API to fetch the model pricing and compute a cost per execution.

But it’s still incomplete, because it’s specific to OpenRouter and doesn’t cover other LLM providers, or the cost of other actions in the workflow. That’s why having a global “cost” concept or “custom execution metrics” at the n8n execution level would be a really nice feature, usable everywhere and visible directly in the UI.

On my channel, I share quite a few videos for anyone who wants to learn n8n, there are probably some that you’d find useful: https://www.youtube.com/@ocade-fusion