Skip to content

Registration fails for dynamic-priced endpoints that need request body to generate 402 challenge #781

@fmhall

Description

@fmhall

Problem

Endpoints with dynamic pricing that depend on request body content (e.g. agentcash.dev/api/send) fail to register because the probe sends an empty request and gets a 500 instead of a 402.

$ curl -X POST https://agentcash.dev/api/send
{"success":false,"error":"x402 challenge build failed: Recipient address is required"}

The payment middleware needs fields like address to build the 402 challenge, so it can't respond with a valid payment challenge when probed empty.

Meanwhile, @agentcash/discovery correctly identifies the endpoint from the OpenAPI spec:

{
  "method": "POST",
  "source": "openapi",
  "authMode": "paid",
  "estimatedPrice": "0-10000 USD",
  "protocols": ["x402"],
  "inputSchema": {
    "properties": {
      "amount": { "type": "number", "exclusiveMinimum": 0 },
      "address": { "type": "string", "minLength": 1 },
      "network": { "type": "string", "enum": ["base", "tempo", "solana"] }
    },
    "required": ["amount", "address", "network"]
  }
}

Root cause

registerResourcesFromDiscovery always calls probeX402Endpoint() which requires a live 402 response. When the probe gets a non-402 status (500 in this case), it returns "No valid x402 response found" and the resource is counted as failed.

Proposed fix

When the probe fails but the discovery source is "openapi" and the endpoint has authMode: "paid" with protocols: ["x402"], allow registration using the OpenAPI metadata alone — the pricing info from x-payment-info and the input schema are sufficient to render the resource in the UI without a live 402 body.

Affected endpoints

Any dynamic-priced endpoint where the 402 challenge requires request body content:

  • agentcash.dev/api/send (needs address to build challenge)
  • Likely others with body-dependent pricing

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions