82trust / 100

Compress

by Maha Context Compiler in Onchain & crypto

x402 APIPassing, checked 3 h ago

Compress long documents and RAG inputs into token-budgeted, deduplicated context packs with source-linked provenance. Returns original and compiled token counts, so the saving is verifiable. Net-positive above N = fee / (r x p) tokens: r your reduction, p your input price. Extractive and budget-bound, so check includedPassages before relying on it. Ranks Latin, Cyrillic, Greek, Arabic and CJK; CJK coarser (bigrams). Not for tabular or heavily-structured payloads.

POST https://www.mahastrategies.com/api/v1/compress

Last 30 days

All checks passedSome failedAll failedNot checked
Uptime
100%
Response time
202 ms typical, 444 ms slowest 5%
Last check
3 h ago
Next check
any minute now

How to call it

# See the payment challenge (nothing is charged)
curl -i -X POST "https://www.mahastrategies.com/api/v1/compress" \
  -H "content-type: application/json" \
  -d '{"budgetMode":"guaranteed","clientRequestId":"req_rag_release_001","documents":[{"id":"release-notes","text":"Release may proceed after the security owner attaches credential-rotation evidence. The production canary passed in every region.\n\nRoutine notes cover staffing, dashboards, meeting cadence, maintenance calendars, regional handoffs, historical capacity, and documentation formatting.","title":"Release notes"},{"id":"rollback-runbook","text":"Rollback if API errors exceed 2 percent for five minutes or payment failures breach the alert threshold. Restore the last-known-good deployment before reopening traffic.\n\nRoutine notes cover staffing, dashboards, meeting cadence, maintenance calendars, regional handoffs, historical capacity, and documentation formatting.","title":"Rollback runbook"}],"provenance":"compact","scoring":"bm25","task":"Find the release condition and rollback trigger while removing duplicate operational background.","tokenBudget":128}'
import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { ExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";

const client = new x402Client().register(
  "eip155:8453",
  new ExactEvmScheme(privateKeyToAccount(process.env.AGENT_KEY)),
);
const pay = wrapFetchWithPayment(fetch, client);

// Not sure it's safe to pay? Preflight it first for $0.005:
// GET https://toolvet.app/api/v1/check?url=https%3A%2F%2Fwww.mahastrategies.com%2Fapi%2Fv1%2Fcompress
const res = await pay("https://www.mahastrategies.com/api/v1/compress", {
  method: "POST",
  headers: { "content-type": "application/json" },
  body: JSON.stringify({"budgetMode":"guaranteed","clientRequestId":"req_rag_release_001","documents":[{"id":"release-notes","text":"Release may proceed after the security owner attaches credential-rotation evidence. The production canary passed in every region.\n\nRoutine notes cover staffing, dashboards, meeting cadence, maintenance calendars, regional handoffs, historical capacity, and documentation formatting.","title":"Release notes"},{"id":"rollback-runbook","text":"Rollback if API errors exceed 2 percent for five minutes or payment failures breach the alert threshold. Restore the last-known-good deployment before reopening traffic.\n\nRoutine notes cover staffing, dashboards, meeting cadence, maintenance calendars, regional handoffs, historical capacity, and documentation formatting.","title":"Rollback runbook"}],"provenance":"compact","scoring":"bm25","task":"Find the release condition and rollback trigger while removing duplicate operational background.","tokenBudget":128}),
});
console.log(await res.json());

Example input

{
  "budgetMode": "guaranteed",
  "clientRequestId": "req_rag_release_001",
  "documents": [
    {
      "id": "release-notes",
      "text": "Release may proceed after the security owner attaches credential-rotation evidence. The production canary passed in every region.\n\nRoutine notes cover staffing, dashboards, meeting cadence, maintenance calendars, regional handoffs, historical capacity, and documentation formatting.",
      "title": "Release notes"
    },
    {
      "id": "rollback-runbook",
      "text": "Rollback if API errors exceed 2 percent for five minutes or payment failures breach the alert threshold. Restore the last-known-good deployment before reopening traffic.\n\nRoutine notes cover staffing, dashboards, meeting cadence, maintenance calendars, regional handoffs, historical capacity, and documentation formatting.",
      "title": "Rollback runbook"
    }
  ],
  "provenance": "compact",
  "scoring": "bm25",
  "task": "Find the release condition and rollback trigger while removing duplicate operational background.",
  "tokenBudget": 128
}

Example output

{
  "clientRequestId": "req_rag_release_001",
  "compiledContextStored": false,
  "context": "# Context Pack\n\nTask: Find the release condition and rollback tr…",
  "includedPassages": [
    {
      "passageHash": "sha256:4d5e66efdcf5f8dba63a89b40af6ce17f3f42948c48b731732e47f5dc…",
      "passageId": "release-notes:1",
      "sourceId": "release-notes",
      "text": "Release may proceed after the security owner attaches credential…"
    }
  ],
  "inputHash": "sha256:288dd5cacd92158f9460346ba6e931f6d0d52f2598bd55e748fc30a18…",
  "metrics": {
    "compiledBytes": 461,
    "compiledEstimatedTokens": 83,
    "duplicatePassagesRemoved": 1,
    "estimatedReductionPercent": 14.4,
    "originalBytes": 606,
    "originalEstimatedTokens": 97,
    "sourceCount": 2,
    "sourceCoveragePercent": 100,
    "tokensSaved": 14
  },
  "outputHash": "sha256:80a337617475688482476a469f9fa7b489ef3e1ad15b4a9756fdc1aa7…",
  "packId": "ctxpack_6a5464df2ce14e9b9e16571c7d814821",
  "retentionBoundaries": {
    "claimVerificationPerformed": false,
    "completenessGuaranteed": false,
    "evidenceRetention": "best_effort",
    "hallucinationPreventionGuaranteed": false,
    "selectionType": "extractive",
    "tokenCountType": "model_neutral_estimate"
  },
  "sourceTextStored": false,
  "sources": [
    {
      "includedEstimatedTokens": 21,
      "includedPassageIds": [
        "release-notes:1"
      ],
      "originalEstimatedTokens": 44,
      "passageCount": 2,
      "sourceHash": "sha256:288ded29ae161d3d11effd7161edf7c51ef1320e7ba0a8d2feaaed7ab…",
      "sourceId": "release-notes",
      "title": "Release notes"
    }
  ],
  "task": "Find the release condition and rollback trigger while removing d…",
  "tokenBudget": 128,
  "version": "0.1.0",
  "warningCodes": [
    "model_neutral_token_estimates",
    "extractive_selection_not_verification"
  ],
  "warnings": [
    "Token counts are model-neutral estimates, not provider tokenizer…"
  ]
}

Security scan

  • No findings. We scan names, descriptions and tool definitions for hidden instructions and other prompt-injection patterns.

Recent checks

WhenResultHTTPTimePrice
3 h agoPassed402202 ms$0.001
7 h agoPassed40275 ms$0.001
10 h agoPassed40281 ms$0.001
14 h agoPassed402113 ms$0.001
17 h agoPassed402135 ms$0.001
21 h agoPassed402178 ms$0.001
25 h agoPassed402444 ms$0.001
28 h agoPassed402345 ms$0.001
33 h agoPassed4021.4 s$0.001
35 h agoPassed402204 ms$0.001
39 h agoPassed402337 ms$0.001
44 h agoPassed402321 ms$0.001