agent-context-api
v0.1.0
Published
A deterministic x402 API for LLM context budgets and secret redaction.
Maintainers
Readme
Agent Context API
A small paid API for coding agents that need a deterministic context preflight before sending repository text to an LLM. It counts GPT-family tokens, applies an optional model-aware budget, and redacts likely credentials.
Local development
npm install
npm test
X402_FACILITATOR=https://facilitator.openx402.ai npm startThe service listens on http://localhost:8787 by default. GET /health is free. POST /v1/context-preflight returns an x402 402 Payment Required response until the caller supplies a valid Base USDC payment.
API example
curl -X POST http://localhost:8787/v1/context-preflight \
-H 'content-type: application/json' \
-d '{"text":"const token = \"sk-example\";","model":"claude-sonnet","token_budget":1000}'The default price is $0.005 per request. Set PAY_TO to change the public payout address and X402_FACILITATOR to select a compatible facilitator. Do not put private keys or facilitator credentials in this repository; the service does not need a signing key to receive payments.
MCP integration
The repository also includes a local stdio MCP server for Cline and other MCP clients:
npm run start:mcpThe preflight_context tool provides a free local tier up to 12,000 characters. Larger inputs return the paid HTTP endpoint and its x402 price. Set PAID_ENDPOINT to the currently deployed endpoint when launching the MCP server. See llms-install.md for a copy-paste client configuration.
Design notes
server.jscontains the Express app, x402 payment middleware, discovery metadata, and analysis logic.test/server.test.jscovers redaction, budgets, and the health route.- The API intentionally does not send submitted text to a third party; processing is local.
- This is an experiment. Revenue must be verified from settlement records, not inferred from 402 responses, requests, or directory listings.
