Agent Utilities
← Commerce data

commerce.unit-price · v1.0.0

Unit Price
for your agent.

Compare up to 50 explicit pack prices with exact arithmetic across compatible mass, volume or count units; no currency conversion.

$0.0005 / call500 micro-dollar credits
131,072 bytes max input65,536 bytes max output
Works on supplied inputNo external network fetch

Example input

{
  "currency": "USD",
  "reference": {
    "quantity": "100",
    "unit": "g"
  },
  "offers": [
    {
      "id": "500g-bag",
      "price": "8.99",
      "quantity": "500",
      "unit": "g"
    },
    {
      "id": "1kg-bag",
      "price": "16.49",
      "quantity": "1",
      "unit": "kg"
    }
  ]
}

Example output

{
  "currency": "USD",
  "reference": {
    "quantity": "100",
    "unit": "g"
  },
  "offers": [
    {
      "id": "500g-bag",
      "totalQuantity": {
        "numerator": "500",
        "denominator": "1",
        "unit": "g"
      },
      "pricePerReference": "1.798000",
      "exactPricePerReference": {
        "numerator": "899",
        "denominator": "500"
      }
    },
    {
      "id": "1kg-bag",
      "totalQuantity": {
        "numerator": "1000",
        "denominator": "1",
        "unit": "g"
      },
      "pricePerReference": "1.649000",
      "exactPricePerReference": {
        "numerator": "1649",
        "denominator": "1000"
      }
    }
  ],
  "cheapestIds": [
    "1kg-bag"
  ],
  "scope": "Price is for the entire pack. Exact rational comparisons; displayed prices round half up to six decimals. Supplied currency label only, no exchange conversion, tax, shipping or product-equivalence checks."
}

Generated from the actual handler using this example input; this is a preview, not a paid API call. Paid responses wrap the result with a receipt and recovery expiry.

Call it from your agent

Add credits in the workspace and keep your API key in private environment storage. Use the same request ID and exact body to recover a lost response within ten minutes.

// Node.js 22+. Read the key from your private environment.
const requestId = Date.now() + '_' + crypto.randomUUID();
const response = await fetch('https://agent-utilities.agent-utilities.workers.dev/v1/tools/commerce.unit-price', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer ' + process.env.AGENT_UTILITIES_API_KEY,
    'Idempotency-Key': requestId
  },
  body: JSON.stringify({
  "currency": "USD",
  "reference": {
    "quantity": "100",
    "unit": "g"
  },
  "offers": [
    {
      "id": "500g-bag",
      "price": "8.99",
      "quantity": "500",
      "unit": "g"
    },
    {
      "id": "1kg-bag",
      "price": "16.49",
      "quantity": "1",
      "unit": "kg"
    }
  ]
})
});
const data = await response.json();
if (!response.ok) throw new Error(data.error?.message ?? 'Request failed');
console.log(data);
// On response loss, retry this SAME requestId, tool and body.
// Do not rerun the line that generates requestId for a retry.
Input JSON Schema
{
  "type": "object",
  "properties": {
    "currency": {
      "type": "string",
      "pattern": "^[A-Z]{3}$"
    },
    "reference": {
      "type": "object",
      "properties": {
        "quantity": {
          "type": "string",
          "pattern": "^(0|[1-9]\\d{0,11})(\\.\\d{1,6})?$",
          "maxLength": 19
        },
        "unit": {
          "type": "string",
          "enum": [
            "mg",
            "g",
            "kg",
            "oz",
            "lb",
            "ml",
            "l",
            "each"
          ]
        }
      },
      "required": [
        "quantity",
        "unit"
      ],
      "additionalProperties": false
    },
    "offers": {
      "type": "array",
      "minItems": 1,
      "maxItems": 50,
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100
          },
          "price": {
            "type": "string",
            "pattern": "^(0|[1-9]\\d{0,11})(\\.\\d{1,6})?$",
            "maxLength": 19
          },
          "quantity": {
            "type": "string",
            "pattern": "^(0|[1-9]\\d{0,11})(\\.\\d{1,6})?$",
            "maxLength": 19
          },
          "unit": {
            "type": "string",
            "enum": [
              "mg",
              "g",
              "kg",
              "oz",
              "lb",
              "ml",
              "l",
              "each"
            ]
          },
          "packCount": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10000
          }
        },
        "required": [
          "id",
          "price",
          "quantity",
          "unit"
        ],
        "additionalProperties": false
      }
    }
  },
  "required": [
    "currency",
    "reference",
    "offers"
  ],
  "additionalProperties": false
}
Output JSON Schema
{
  "type": "object",
  "properties": {
    "currency": {
      "type": "string"
    },
    "reference": {
      "type": "object",
      "properties": {
        "quantity": {
          "type": "string",
          "pattern": "^(0|[1-9]\\d{0,11})(\\.\\d{1,6})?$",
          "maxLength": 19
        },
        "unit": {
          "type": "string",
          "enum": [
            "mg",
            "g",
            "kg",
            "oz",
            "lb",
            "ml",
            "l",
            "each"
          ]
        }
      },
      "required": [
        "quantity",
        "unit"
      ],
      "additionalProperties": false
    },
    "offers": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "totalQuantity": {
            "type": "object",
            "properties": {
              "numerator": {
                "type": "string"
              },
              "denominator": {
                "type": "string"
              },
              "unit": {
                "type": "string"
              }
            },
            "required": [
              "numerator",
              "denominator",
              "unit"
            ],
            "additionalProperties": false
          },
          "pricePerReference": {
            "type": "string"
          },
          "exactPricePerReference": {
            "type": "object",
            "properties": {
              "numerator": {
                "type": "string"
              },
              "denominator": {
                "type": "string"
              }
            },
            "required": [
              "numerator",
              "denominator"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "id",
          "totalQuantity",
          "pricePerReference",
          "exactPricePerReference"
        ],
        "additionalProperties": false
      }
    },
    "cheapestIds": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "scope": {
      "type": "string"
    }
  },
  "required": [
    "currency",
    "reference",
    "offers",
    "cheapestIds",
    "scope"
  ],
  "additionalProperties": false
}

Before you integrate

Prices are experimental. The service currently allows 1,000 new calls per day across all accounts. Failed operations return reserved credits. Successful results are encrypted for ten-minute retry recovery. Review data handling and service limits.

Related tools

commerce $0.0003 / call

GTIN Validate

Validate GTIN-8, UPC/GTIN-12, EAN/GTIN-13 and GTIN-14 check digits; no product lookup.

commerce.gtin-validate

commerce $0.0005 / call

Variant Compare

Compare requested product attributes with an offered variant and list missing or mismatched fields.

commerce.variant-compare

commerce $0.0008 / call

Pack Plan

Choose the lowest-cost whole-pack combination for a required count with exact prices and explicit pack limits; up to 20 interchangeable offers.

commerce.pack-plan