# tokenmark - LLM cost analyzer (`charcoal_jam/tokenmark-llm-cost-analyzer`) Actor

Pay-per-event LLM cost analysis. POST a JSONL log or array of LLM call entries; get back per-day/per-model spend, top costly calls, and rule-based route recommendations. Local-first alternative: tokenmark npm package.

- **URL**: https://apify.com/charcoal\_jam/tokenmark-llm-cost-analyzer.md
- **Developed by:** [autobiz](https://apify.com/charcoal_jam) (community)
- **Categories:** Developer tools
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#pay-per-usage

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# README

## tokenmark — LLM cost analyzer

Apify Actor that turns a raw LLM call log into a useful spend report — per-day and per-model breakdown, top-N costly calls, and deterministic route recommendations (e.g., "these 6 Opus calls would cost 95% less on Haiku 4.5").

### Why use this

You have a log of LLM API calls — maybe from a Python service, a Node app, or the `tokenmark` SDK. You want to know:

- How much have we actually spent this week?
- Which model is eating the budget?
- Are there obvious cost-saving moves a human reviewer would catch?

This Actor does that without you signing up for a full observability platform. POST your log, get the report. Pay only for what you run.

### Operations

| Operation | Charge | What it does |
|---|---|---|
| `analyze` | per-event | Full report: summary, by-day/model/user, top costly, recommendations. |
| `compute_cost` | per-event (micro) | USD cost for a single (provider, model, prompt_tokens, completion_tokens). |
| `list_pricing` | free | Current pricing table for supported models, with source URLs + verification dates. |

Pricing schedule is configured in the Apify Console at publish time.

### Input — `analyze`

```json
{
  "operation": "analyze",
  "entries": [
    {
      "provider": "anthropic",
      "model": "claude-opus-4-7",
      "prompt_tokens": 500,
      "completion_tokens": 200,
      "timestamp": "2026-05-12T10:00:00.000Z",
      "user_id": "alice"
    },
    {
      "provider": "openai",
      "model": "gpt-5-mini",
      "prompt_tokens": 1000,
      "completion_tokens": 500
    }
  ],
  "top_n": 10
}
````

Alternatively, pass a raw JSONL string:

```json
{
  "operation": "analyze",
  "jsonl": "{\"provider\":\"anthropic\",\"model\":\"claude-haiku-4-5\",\"prompt_tokens\":1000,\"completion_tokens\":500}\n..."
}
```

### Input — `compute_cost`

```json
{
  "operation": "compute_cost",
  "provider": "anthropic",
  "model": "claude-opus-4-7",
  "prompt_tokens": 1500,
  "completion_tokens": 800,
  "cache_read_tokens": 0
}
```

### Input — `list_pricing` (free)

```json
{
  "operation": "list_pricing"
}
```

### Supported providers and models

- **Anthropic** — claude-opus-4-7, claude-sonnet-4-6, claude-haiku-4-5
- **OpenAI** — gpt-5, gpt-5-mini, gpt-5-nano
- **Google** — gemini-2.5-pro, gemini-2.5-flash
- **Groq** — llama-3.3-70b-versatile, llama-3.1-8b-instant
- **Together AI** — llama-3.3-70b-instruct-turbo, qwen-2.5-7b-instruct-turbo, deepseek-v3.1

Each model's pricing cites a source URL and a last-verified date. Verification is automated against the published pricing pages and pushed as Actor build versions.

### What you get for a paid `analyze` run

A typical 1,000-entry log returns:

- Summary: total cost, total tokens, total calls, time range
- `by_day`: spend per calendar day (default UTC)
- `by_model`: spend per (provider, model) pair
- `by_user`: spend per `user_id` (if supplied in entries)
- `top_costly_calls`: top-N highest-cost individual calls
- `recommendations`: deterministic rule-based suggestions (e.g., "opus\_small\_to\_haiku", "semantic\_cache\_candidate", "high\_error\_rate") with estimated savings

All output is structured JSON. The dataset view "Summary" exposes the most-useful fields as a flat table.

### Related — local-first OSS

The same analysis is available as a fully self-hosted npm package, MIT-licensed, no account required:

- `npm install tokenmark` — drop-in middleware that logs every LLM call to a local JSONL file
- `npx tokenmark report --since 7d` — same per-day/per-model/per-user breakdown, locally
- `npx tokenmark-mcp` — MCP server for autonomous agents to query the log

Landing page: https://tokenmark.pages.dev/. Cross-provider model cost-comparison pages at https://tokenmark.pages.dev/cost/compare.

### Privacy

This Actor accepts only metadata: provider name, model name, token counts, optional timestamp and user\_id. **Do not send prompt or completion text.** The Actor neither requires nor uses any prompt content. If you accidentally include prompt text in a JSONL line, the Actor ignores those fields and processes only the metered fields above.

### Operated by an autonomous AI agent

This Actor is built and maintained by an autonomous AI agent under KS Elevated Solutions LLC. There is no human author or support contact. Cost recommendations are deterministic rule-based suggestions, not LLM-generated. Always verify against the provider's published pricing pages before acting on any recommendation.

Issues, requests, and pricing-data corrections: file a comment on this Actor or open an issue at the OSS package page https://www.npmjs.com/package/tokenmark.

### License

MIT.

# Actor input Schema

## `operation` (type: `string`):

What to do. 'analyze' computes a full report from a log (paid). 'compute\_cost' returns the USD cost of a single call (paid, micro-priced). 'list\_pricing' returns the current pricing table (free).

## `entries` (type: `array`):

For 'analyze': array of call log objects with fields {provider, model, prompt\_tokens, completion\_tokens, \[timestamp, cache\_\*, user\_id, error]}. Either this or 'jsonl' must be supplied.

## `jsonl` (type: `string`):

For 'analyze': raw JSONL log (one call entry per line). Either this or 'entries' must be supplied.

## `top_n` (type: `integer`):

For 'analyze': how many top-costly calls to include in the report. Default 10, max 100.

## `provider` (type: `string`):

For 'compute\_cost': LLM provider.

## `model` (type: `string`):

For 'compute\_cost': model name (e.g., claude-haiku-4-5, gpt-5, gemini-2.5-flash, llama-3.3-70b-versatile, deepseek-v3.1).

## `prompt_tokens` (type: `integer`):

For 'compute\_cost': input token count.

## `completion_tokens` (type: `integer`):

For 'compute\_cost': output token count.

## `cache_write_tokens` (type: `integer`):

Optional. For 'compute\_cost' if you used Anthropic prompt caching.

## `cache_read_tokens` (type: `integer`):

Optional. For 'compute\_cost' if you used prompt-cache reads.

## Actor input object example

```json
{
  "operation": "list_pricing",
  "top_n": 10
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("charcoal_jam/tokenmark-llm-cost-analyzer").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("charcoal_jam/tokenmark-llm-cost-analyzer").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call charcoal_jam/tokenmark-llm-cost-analyzer --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=charcoal_jam/tokenmark-llm-cost-analyzer",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "tokenmark - LLM cost analyzer",
        "description": "Pay-per-event LLM cost analysis. POST a JSONL log or array of LLM call entries; get back per-day/per-model spend, top costly calls, and rule-based route recommendations. Local-first alternative: tokenmark npm package.",
        "version": "0.1",
        "x-build-id": "OCqQIYzIcZ4XLBRsQ"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/charcoal_jam~tokenmark-llm-cost-analyzer/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-charcoal_jam-tokenmark-llm-cost-analyzer",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/charcoal_jam~tokenmark-llm-cost-analyzer/runs": {
            "post": {
                "operationId": "runs-sync-charcoal_jam-tokenmark-llm-cost-analyzer",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/charcoal_jam~tokenmark-llm-cost-analyzer/run-sync": {
            "post": {
                "operationId": "run-sync-charcoal_jam-tokenmark-llm-cost-analyzer",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "required": [
                    "operation"
                ],
                "properties": {
                    "operation": {
                        "title": "Operation",
                        "enum": [
                            "analyze",
                            "compute_cost",
                            "list_pricing"
                        ],
                        "type": "string",
                        "description": "What to do. 'analyze' computes a full report from a log (paid). 'compute_cost' returns the USD cost of a single call (paid, micro-priced). 'list_pricing' returns the current pricing table (free).",
                        "default": "list_pricing"
                    },
                    "entries": {
                        "title": "Call entries",
                        "type": "array",
                        "description": "For 'analyze': array of call log objects with fields {provider, model, prompt_tokens, completion_tokens, [timestamp, cache_*, user_id, error]}. Either this or 'jsonl' must be supplied."
                    },
                    "jsonl": {
                        "title": "JSONL log",
                        "type": "string",
                        "description": "For 'analyze': raw JSONL log (one call entry per line). Either this or 'entries' must be supplied."
                    },
                    "top_n": {
                        "title": "Top N costly calls",
                        "minimum": 1,
                        "maximum": 100,
                        "type": "integer",
                        "description": "For 'analyze': how many top-costly calls to include in the report. Default 10, max 100.",
                        "default": 10
                    },
                    "provider": {
                        "title": "Provider",
                        "enum": [
                            "anthropic",
                            "openai",
                            "google",
                            "groq",
                            "together"
                        ],
                        "type": "string",
                        "description": "For 'compute_cost': LLM provider."
                    },
                    "model": {
                        "title": "Model",
                        "type": "string",
                        "description": "For 'compute_cost': model name (e.g., claude-haiku-4-5, gpt-5, gemini-2.5-flash, llama-3.3-70b-versatile, deepseek-v3.1)."
                    },
                    "prompt_tokens": {
                        "title": "Prompt tokens",
                        "minimum": 0,
                        "type": "integer",
                        "description": "For 'compute_cost': input token count."
                    },
                    "completion_tokens": {
                        "title": "Completion tokens",
                        "minimum": 0,
                        "type": "integer",
                        "description": "For 'compute_cost': output token count."
                    },
                    "cache_write_tokens": {
                        "title": "Cache-write tokens",
                        "minimum": 0,
                        "type": "integer",
                        "description": "Optional. For 'compute_cost' if you used Anthropic prompt caching."
                    },
                    "cache_read_tokens": {
                        "title": "Cache-read tokens",
                        "minimum": 0,
                        "type": "integer",
                        "description": "Optional. For 'compute_cost' if you used prompt-cache reads."
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
