Skip to main content
API Reference

Payment Links API

HTTP API reference for Payment Links — shareable pay URLs where an agent pays over x402/USDC or a person pays via Pix, verified before fulfillment.

2 min read
View MarkdownEdit on GitHub

Payment Links API

REST API for Payment Links. A Payment Link is a shareable URL where the product IS the payment: an agent reads it and pays over x402/USDC, or a person pays via a Pix QR. One link can advertise more than one settlement method (rail) at once. The gateway verifies the payment before fulfillment and seals a hash-chained receipt. Served at pay_url = https://gw.codespar.dev/pay/<slug>.

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

All endpoints require authentication. See Authentication. Endpoints marked admin require a bearer api key OR service auth with an x-codespar-user header for an account admin/owner. Payment Links are project-scoped.

FieldTypeDescription
idstringPayment Link ID, pl_<...>
slugstringURL slug; global namespace. Auto-generated when omitted
titlestringDisplay title
descriptionstring | nullOptional description
pay_urlstringhttps://gw.codespar.dev/pay/<slug>
acceptsAccept[]One or more settlement rails (see below)
environment"test" | "live"Environment the link settles in
one_timebooleanCloses after the first successful payment
statusstringLifecycle status
use_countnumberSuccessful payments so far
max_usesnumber | nullCap on total payments; null for unlimited
expires_atstring | nullISO 8601, or null
redirect_urlstring | nullWhere a person is sent after paying
activebooleanPaused links cannot be paid
created_atstringISO 8601

Accept (settlement rail)

accepts[] carries one entry per rail. A link can offer x402/USDC, Pix/BRL, or both; the payer uses whichever they are provisioned for.

x402 / USDC

{
  "rail": "x402",
  "amount": "0.01",
  "currency": "USDC",
  "pay_to": { "kind": "provisioned", "consumer_id": "your-consumer" }
}
  • amount is decimal USDC (up to 6 decimals).
  • pay_to.kind: "provisioned" settles to the CodeSpar wallet of consumer_id.
  • pay_to.kind: "byo" settles to pay_to.address (a 0x EVM address).

Pix / BRL

{
  "rail": "pix",
  "amount": "5.00",
  "currency": "BRL",
  "pix": { "key": "your-pix-key" }
}
  • amount is decimal BRL (up to 2 decimals).
  • pix.key (or pix.celcoin_account) is where the Pix payment lands.

POST /v1/payment-links (admin)

Body

{
  "title": "Coffee",
  "description": "One coffee",
  "accepts": [
    { "rail": "x402", "amount": "0.01", "pay_to": { "kind": "provisioned", "consumer_id": "your-consumer" } },
    { "rail": "pix", "amount": "5.00", "pix": { "key": "your-pix-key" } }
  ],
  "one_time": false,
  "max_uses": 10
}
  • slug is optional; a unique one is generated when omitted.
  • accepts must have at least one rail.
  • one_time, max_uses, expires_at, and redirect_url are all optional.

Response201 Created with the Payment Link object.

GET /v1/payment-links

Response

{ "payment_links": [/* Payment Link */] }

GET /v1/payment-links/:id — the Payment Link object, or 404 payment_link_not_found.

PATCH /v1/payment-links/:id (admin)

Body (at least one field)

{ "title": "...", "description": "...", "active": false, "expires_at": "2026-12-31T00:00:00Z", "redirect_url": "https://..." }

Set active: false to pause the link (it can no longer be paid); true to resume. The accepts rails are fixed at creation and are not editable.

DELETE /v1/payment-links/:id (admin)204 No Content. Payment Links are config, not audit data; settled receipts are retained independently.

Errors

HTTPcodewhen
400invalid_bodybody failed validation (including a malformed x402/Pix amount)
403forbiddennon-admin caller on an admin endpoint
404payment_link_not_foundunknown id in this project
409slug_conflictthe slug is already taken
Payment Links API | CodeSpar