Token Cost (OpenRouter)
AI-generatedSummary
Calculate the cost of language model token usage based on current OpenRouter pricing data fetched from the OpenRouter API.
Inputs
- openRouterApi (required) — API credentials including an API key to authenticate requests to the OpenRouter API.
Output shape
a list of JSON objects with the original input data augmented to include an array of LLM calls with detailed cost breakdowns (prompt cost, completion cost, total cost) and a totalCost summary object per item.
Each input item should contain an 'llmCalls' array describing token usage per call; if absent or invalid, costs default to zero. Pricing data is fetched live per execution and models must match OpenRouter model IDs. Returned costs are rounded to 8 decimal places in USD. Errors are thrown if the API key is missing or pricing data retrieval fails.
