Skip to main content

Gate

1 operation under /v1/gate/stats (GET): parameters, status codes, refusal bodies, and the same request in curl, HTTP, Python and TypeScript.

4 min read
View MarkdownEdit on GitHub

Base URL: https://api.codespar.dev

Every operation below requires a Bearer token. See Authentication.

GET /v1/gate/stats

GEThttps://api.codespar.dev/v1/gate/stats

Gate earnings and 402 conversion for the project

Everything the project sells through gw.codespar.dev in one read: its paywalls and the tools of its MCP servers, over the last 30 Sao Paulo calendar days including today. Scope paywalls:read, and mcp-servers:read as well, checked by the handler because the body carries the MCP tools: a key without it gets the same 403 forbidden the scope gate sends.

Earnings, paid calls and paying agents are aggregated at read time from the settlement evidence, with the attribution rule GET /v1/paywalls/{id}/stats uses; x402 settlements only. A sale of an item deleted since still counts toward the totals and has no row in items.

earnings_atomic is what the seller kept: net of metered refunds and of the MCP platform fee recorded on each sale; gross_earnings_atomic is before the fee.

challenges_issued, payment_attempts and challenges_paid come from a per-day counter the gateway keeps. The conversion is challenges_paid / payment_attempts, at most 100% by construction: every settle is counted on the row of its own attempt. No ratio should be built on challenges_issued, since a client that knows the terms pays without receiving a 402.

Query parameters

NameTypeRequiredDescription
window"30d"no—

Responses

StatusBodyDescription
200objectOK
400objectwindow is not 30d.

Response 200

FieldTypeRequiredDescription
challenges_issuedinteger,nullyes402 responses carrying PAYMENT-REQUIRED that the gateway sent in the window, for any reason (no payment, an unusable or refused one, a replay outside the re-delivery window). Recorded since migration 0295; days before it count zero. Not a conversion denominator: a client that knows the terms pays without receiving one.
challenges_paidinteger,nullyesGenuine x402 settles (a re-delivered replay is not one) recorded by the same counter over the same days. Each is counted on the row and day of its own attempt, so it never exceeds payment_attempts: challenges_paid / payment_attempts is the conversion, at most 100%. It is NOT linked to a 402 and can exceed challenges_issued. It differs from paid_calls only by what the counter did not see: days before migration 0295 and increments lost to a replica that died between flushes.
earnings_atomicstringyesWhat the seller kept in the window: settled amounts minus metered refunds owed ('claimed', 'sent', 'confirmed') minus the MCP platform fee recorded for each sale. The fee is the accrual taken on that very sale, not the server's current rate. A sale made before migration 0295 has no linked accrual, and nothing is subtracted for it. USDC atomic.
fromstring (date-time)yesWindow start: Sao Paulo midnight, 29 days before today.
gross_earnings_atomicstringyesSettled amounts in the window minus metered refunds owed, before the platform fee. USDC atomic.
itemsarray of objectyesEvery current paywall, and every tool of every current MCP server, of the project.
new_paying_agents_this_monthintegeryesOf paying_agents, those whose first settled call on this project's Gate falls in the current Sao Paulo calendar month.
paid_callsintegeryesSettled x402 calls in the window.
paying_agentsintegeryesDistinct payer addresses (the x402 signer) with a settled call in the window.
payment_attemptsinteger,nullyesRequests in the window that arrived carrying an x402 payment (a non-empty PAYMENT-SIGNATURE or X-PAYMENT header) at an active paywall, or at a priced MCP tool on the Mode B path, whatever became of them: settled, undecodable, underpriced, refused by the settle pipeline, a replay of an earlier authorization, or answered from the Idempotency-Key store. Counted before the header is read. A Mode A (mandate) MCP call is not counted. Recorded since migration 0295.
previous_earnings_atomicstring,nullyesearnings_atomic (net of the fee) over the span of equal length ending at from. Null when nothing on the project's Gate predates the window: no settlement before from and no current paywall or MCP server created before it.
published_linksintegeryesGate links published at some point in the window, a link being a paywall or an MCP server (/mcp/<slug>, not each tool). Nothing records when an item was switched on or off, so this counts the links the window PROVES were published: every paywall or MCP server of the project that is active now (to is now, so it is published inside the window), plus every one, inactive or since deleted, with at least one settled call in the window (the gateway only settles for an active item). An item that is inactive now and sold nothing in the window is not counted, although it may have been live for part of it. So every link that produced a paid_calls entry is in this count, and paid_calls / published_links is the web's payments-per-link (it can exceed 1).
tostring (date-time)yesWindow end: the time of the read.
window"30d"yes—
Example request
curl -X GET https://api.codespar.dev/v1/gate/stats \
  -H "Authorization: Bearer $CODESPAR_API_KEY"
GET /v1/gate/stats HTTP/1.1
Host: api.codespar.dev
Authorization: Bearer $CODESPAR_API_KEY
import os
import requests

res = requests.get(
    "https://api.codespar.dev/v1/gate/stats",
    headers={"Authorization": f"Bearer {os.environ['CODESPAR_API_KEY']}"},
)
res.raise_for_status()
data = res.json()
const res = await fetch("https://api.codespar.dev/v1/gate/stats", {
  method: "GET",
  headers: {
    Authorization: `Bearer ${process.env.CODESPAR_API_KEY}`,
  },
});

const data = await res.json();
const result = await cs.api.get("/v1/gate/stats");
Example response 200
application/json
{
  "window": "30d",
  "from": "2026-01-15T12:00:00.000Z",
  "to": "2026-01-15T12:00:00.000Z",
  "earnings_atomic": "string",
  "gross_earnings_atomic": "string",
  "previous_earnings_atomic": "string",
  "paid_calls": 0,
  "published_links": 0,
  "paying_agents": 0,
  "new_paying_agents_this_month": 0,
  "challenges_issued": 0,
  "payment_attempts": 0,
  "challenges_paid": 0,
  "items": [
    {
      "kind": "paywall",
      "id": "obj_0000000000000000",
      "tool_name": "Example",
      "paid_calls_24h": 0,
      "earnings_atomic": "string",
      "gross_earnings_atomic": "string"
    }
  ]
}

On this page

Gate | CodeSpar