# Agent Cost Calculator (`skilled_glee/agent-cost-calculator`) Actor

Calculate what your AI agent runs cost, broken down by model, tool, task and run, from your token usage and price list. Flags any model or tool with no price. $0.001 per run.

- **URL**: https://apify.com/skilled_glee/agent-cost-calculator.md
- **Developed by:** [EchoEmpire Machine Foundry (EchoEmpire LLC)](https://apify.com/skilled_glee) (community)
- **Categories:** Developer tools
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$0.001 / actor start

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

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

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
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.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## 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.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Agent Cost Calculator

Calculate decimal cost breakdowns by model, tool, task and run from supplied usage and versioned prices, with explicit missing-price findings.

This Actor runs **Agent Cost Calculator only**. Supply its native JSON object directly; no utility selector or dispatcher wrapper is accepted. Core computation is deterministic and offline: no LLM calls, remote schema retrieval or target-site requests. Apify runtime storage is used to save the result.

### Behavior and limits

Exact resource/unit pairs choose prices; amount is per positive supplied per units (default 1). No unit conversion or live prices. Nonnegative numeric values or plain decimal strings (≤100 chars); strings recommended. Up to 10,000 usage and price records. Currency is a supplied three-letter uppercase code. Arithmetic uses 50 significant digits, half-even rounding, including nonterminating ratios. Missing prices produce a partial total with complete=false, never implicit zero. Supplied data is not provider billing proof.

Every request is limited to 2,000,000 bytes of canonical UTF-8 JSON. Runtime validation uses the bundled exact [input schema](input_schema.json). The Console form is a supported Apify schemaVersion 1 presentation: root fields/types are retained, while nested and cross-field constraints run inside the Actor. Inputs containing arbitrary JSON or boolean schemas stay native JSON, without string encoding or forced object conversion. Schema evaluation is intended for bounded trusted workloads; it is not an adversarial multi-tenant sandbox.

### Input

| Field | Required | JSON type | Meaning |
|---|---|---|---|
| `usage` | yes | `"array"` | Native utility field; exact nested shape is in input_schema.json. |
| `pricing` | yes | `"object"` | Versioned caller-supplied prices with currency and explicit resource/unit rates; no live prices. |

Example input ([example-input.json](example-input.json)):

```json
{
  "usage": [
    {
      "resource": "model/input",
      "unit": "token",
      "quantity": 1000,
      "model": "model"
    }
  ],
  "pricing": {
    "version": "example-v1",
    "currency": "USD",
    "prices": [
      {
        "resource": "model/input",
        "unit": "token",
        "amount": "0.25",
        "per": 1000000
      }
    ]
  }
}
```

### Output and status

The Actor stores one result envelope in the default dataset and the same envelope under key `OUTPUT` in the default key-value store. Data fields for this utility: `total`, `currency`, `pricing_version`, `complete`, `breakdown`, `by_dimension`, `unassigned`, `errors`.

- `status: pass`: execution completed and the result/check passed.
- `status: fail`: execution completed and found a failed check, policy or retention constraint. This is a completed Actor run, not a runtime crash.
- `status: error`: execution could not complete, with stable `errors[].code`, message and JSON Pointer path; the local process exits 2.

The envelope also contains utility, version, request_id, data, errors, warnings and provenance. See the [exact data output schema](output_schema.json), [dataset envelope schema and views](.actor/dataset_schema.json), and [Apify output links](.actor/output_schema.json). Fields named errors inside data are check findings; envelope errors describe execution failures. Do not treat a platform run's success flag alone as a passing policy/check.

Actual core output for the example ([example-output.json](example-output.json)):

```json
{
  "utility": "agent-cost-calculator",
  "version": "1.0.0",
  "request_id": "documented-example",
  "status": "pass",
  "data": {
    "total": "0.00025",
    "currency": "USD",
    "pricing_version": "example-v1",
    "complete": true,
    "breakdown": [
      {
        "usage_index": 0,
        "resource": "model/input",
        "unit": "token",
        "quantity": "1000",
        "cost": "0.00025"
      }
    ],
    "by_dimension": {
      "model": {
        "model": "0.00025"
      },
      "tool": {},
      "task": {},
      "run": {}
    },
    "unassigned": {
      "model": "0",
      "tool": "0.00025",
      "task": "0.00025",
      "run": "0.00025"
    },
    "errors": []
  },
  "errors": [],
  "warnings": [
    "Costs use caller-supplied usage and prices; no billing attestation. Decimal arithmetic uses 50 significant digits and half-even rounding."
  ],
  "provenance": {
    "engine": "deterministic-python",
    "network_access": false,
    "input_hash": "sha256:0303a1d1caac263b0b09e67ea132d256a6fc29d35a8919ef6dd0bfc56070b288"
  }
}
```

The request ID above is fixed for illustration; actual Actor runs generate their own request IDs. Runtime provenance additionally identifies local or Apify storage; the example shows the utility's computed envelope before that storage annotation. Hashes identify supplied data, not independently verified facts.

### Run through the API

Replace `YOUR_APIFY_USERNAME` with the namespace of this Actor's published listing. The fixed Actor name is `agent-cost-calculator`. This example assumes the Actor has been built and made accessible in that namespace; this README does not itself establish deployment or publication.

```bash
curl --fail-with-body --request POST \
  --header "Authorization: Bearer $APIFY_TOKEN" \
  --header 'Content-Type: application/json' \
  --data-binary @example-input.json \
  'https://api.apify.com/v2/acts/YOUR_APIFY_USERNAME~agent-cost-calculator/run-sync-get-dataset-items?format=json'
```

The response is an array containing the result envelope. Inspect its `status` and findings before consuming `data`. For asynchronous integrations, start a run, wait for completion and retrieve the default dataset or key-value-store `OUTPUT`. API authorization credentials belong in your client environment, never in utility input or captured fixtures.

### Run locally

From this self-contained Actor directory, with Python 3.11 or newer:

```bash
python3 -m venv .venv
.venv/bin/python -m pip install -r requirements.txt
.venv/bin/python -m app --input example-input.json --storage-dir ./storage
```

This executes the fixed utility using real local SDK filesystem storage. It does not start another Actor or dispatch to another portfolio utility. A completed finding has envelope status fail while completing the storage run normally; execution errors exit 2. Inspect the stored envelope rather than assuming that a zero process exit means a check passed.

### Compose with other utilities

Map trace usage into explicit resource/unit records; keep currency and pricing version. Pass the computed total and caller-measured run summaries into Agent Run Regression Comparator after aligning units and scope.

Composition is explicit caller orchestration: this Actor does not invoke other Actors. Pass only documented data fields between contracts and check every envelope status. Offline core tests use supplied fixtures; the Actor does not fabricate evidence or verify that supplied events, usage or artifact references occurred.

# Actor input Schema

## `pricing` (type: `object`):

Versioned caller-supplied prices with currency and explicit resource/unit rates; no live prices.

## `usage` (type: `array`):

Native usage input for Agent Cost Calculator. See the README and input_schema.json for nested fields and limits.

## Actor input object example

```json
{
  "pricing": {
    "currency": "USD",
    "prices": [
      {
        "amount": "0.25",
        "per": 1000000,
        "resource": "model/input",
        "unit": "token"
      }
    ],
    "version": "example-v1"
  },
  "usage": [
    {
      "model": "model",
      "quantity": 1000,
      "resource": "model/input",
      "unit": "token"
    }
  ]
}
```

# Actor output Schema

## `result` (type: `string`):

The same result envelope stored under OUTPUT.

## `results` (type: `string`):

JSON array containing one utility result envelope.

# 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 = {
    "pricing": {
        "currency": "USD",
        "prices": [
            {
                "amount": "0.25",
                "per": 1000000,
                "resource": "model/input",
                "unit": "token"
            }
        ],
        "version": "example-v1"
    },
    "usage": [
        {
            "model": "model",
            "quantity": 1000,
            "resource": "model/input",
            "unit": "token"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("skilled_glee/agent-cost-calculator").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 = {
    "pricing": {
        "currency": "USD",
        "prices": [{
                "amount": "0.25",
                "per": 1000000,
                "resource": "model/input",
                "unit": "token",
            }],
        "version": "example-v1",
    },
    "usage": [{
            "model": "model",
            "quantity": 1000,
            "resource": "model/input",
            "unit": "token",
        }],
}

# Run the Actor and wait for it to finish
run = client.actor("skilled_glee/agent-cost-calculator").call(run_input=run_input)

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

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

```

## CLI example

```bash
echo '{
  "pricing": {
    "currency": "USD",
    "prices": [
      {
        "amount": "0.25",
        "per": 1000000,
        "resource": "model/input",
        "unit": "token"
      }
    ],
    "version": "example-v1"
  },
  "usage": [
    {
      "model": "model",
      "quantity": 1000,
      "resource": "model/input",
      "unit": "token"
    }
  ]
}' |
apify call skilled_glee/agent-cost-calculator --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,skilled_glee/agent-cost-calculator"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/Yn1Pc0fzuKWSpNmXv/builds/QScbINNXeTrPb6pm0/openapi.json
