# x402-shipping
[](./LICENSE)
[](https://x402.org)
[](https://x402.org)
> Rate-shop every carrier and buy the label in two paid calls โ the label PDF comes back base64 in the response body.
`POST /rates` prices a parcel across every carrier service available for the route and tells you which is cheapest and which is fastest. `POST /label` buys one of those rates and hands you the label โ a real PDF, base64-encoded, **in the 200 body** โ along with the tracking number. There is no download link to poll and no webhook to wait on.
## Why x402 for this
Shipping APIs gate on an account, a business verification and often a monthly minimum โ which is fine for a warehouse and absurd for an agent that needs to mail one thing. x402 prices the two operations that matter at $0.003 and $0.02 and settles them in USDC per call, so an agent with a wallet can rate-shop and ship without anyone opening an account for it. The settlement receipt in each response is the audit trail linking the spend to the label it bought.
## Quickstart
```bash
git clone https://github.com/nirholas/x402-shipping
cd x402-shipping
npm install
npm run dev # http://localhost:4023
```
No configuration needed โ the server ships with the suite's receive addresses and a deterministic fixture rater that quotes seven real carrier services and issues a valid PDF label, so the demo works before you have any carrier account. Set `PAY_TO_ADDRESS` / `SOLANA_PAY_TO_ADDRESS` to receive funds yourself.
```bash
# 1. Unpaid โ 402 listing both rails
curl -i -X POST http://localhost:4023/rates \
-H 'Content-Type: application/json' \
-d '{"from":{"street1":"215 Clayton St","city":"San Francisco","state":"CA","zip":"94117","country":"US"},"to":{"street1":"1600 Pennsylvania Ave NW","city":"Washington","state":"DC","zip":"20500","country":"US"},"parcel":{"length":10,"width":8,"height":4,"weight":32}}'
# 2. Paid, via any x402 client
npm run client
```
## API
| Route | Price | What you get back |
|---|---|---|
| `POST /rates` | **$0.003** | the full carrier rate table with prices, transit days, and `cheapest` / `fastest` flags |
| `POST /label` | **$0.02** | the label as base64 PDF plus tracking number, tracking URL, carrier, service and the amount charged |
| `GET /health` | free | Liveness, active data source, configured rails |
| `GET /.well-known/x402` | free | Machine-readable discovery manifest |
Every paid route returns the purchased artifact **in the 200 body**. Nothing is deferred to a webhook or a later fetch.
Full reference: [docs/api.md](docs/api.md) ยท [openapi.json](openapi.json) ยท [skill.md](skill.md)
## How x402 works
```
agent x402-shipping facilitator
โ GET /rates โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโถโ โ
โ 402 + accepts[base, solana] โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ
โ sign USDC authorization โ โ
โ retry + X-PAYMENT โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโถโ verify + settle โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโถโ
โ 200 + artifact โ โ
โ + X-PAYMENT-RESPONSE โ โโโ tx hash / signature โโโโโโโค
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ
```
**Pay in USDC on Base or Solana โ your client picks the rail.** The 402 challenge always lists both:
| Rail | Network | Asset | payTo |
|---|---|---|---|
| EVM | `base-sepolia` (`base` via `NETWORK=base`) | USDC | `0x40252CFDF8B20Ed757D61ff157719F33Ec332402` |
| Solana | `solana` | USDC (SPL) | `WwwuGbqHrwF5RG89KhUbmRWEvjnRH9k5kVM5p7T3WwW` |
The Solana rail's `extra.feePayer` is a public facilitator sponsor account that pays the SOL network fee, so a buyer needs only USDC โ no SOL for gas. Wallets that sign serialized transactions (Phantom, most agent SDKs) can use the built-in helpers at `POST /api/x402-checkout?action=prepare|encode`.
## Real backend / API keys
Two providers are supported; either is free to try.
| Env var | Unlocks |
|---|---|
| `SHIPPO_API_TOKEN` | Live [Shippo](https://goshippo.com) rating + label purchase. Test tokens start `shippo_test_`. |
| `EASYPOST_API_KEY` | Live [EasyPost](https://easypost.com) rating + label purchase. Test keys start `EZTK`. |
| `SHIPPO_BASE_URL` / `EASYPOST_BASE_URL` | Point at a different host โ rarely needed. |
Shippo wins if both are set. **Test mode is the default and the safe path**: rates are real rate-table lookups and labels are real PDFs, but nothing ships and no carrier account is charged. The `testMode` field in every response tells you which mode produced it โ a production key flips it to `false` and the startup banner says `LIVE โ labels cost real money`.
**Without either key, everything still works.** The fixture rater prices seven carrier services on real weight, volume and zone arithmetic, and `POST /label` returns a valid one-page PDF stamped `TEST LABEL - NOT VALID FOR SHIPPING`. Every response is marked `"source": "fixture"`, in the JSON, in the OpenAPI schema and in `skill.md`.
One difference worth knowing: a live `rateId` references a shipment the provider already stored, so `POST /label` needs only the `rateId`. A fixture `rateId` references nothing, so fixture mode asks you to re-send `from`/`to`/`parcel` โ the service will not invent an address it was never given.
## Human checkout
For a browser-facing checkout, drop in [`@three-ws/x402-payment-modal`](https://www.npmjs.com/package/@three-ws/x402-payment-modal) โ it reads the 402 challenge and drives the whole connect โ sign โ settle flow for **both** rails (Phantom on Solana, any injected wallet on EVM), with SIWX re-entry so a returning buyer skips the wallet prompt, and client-side spending caps that stop an agent or a mis-click from over-spending. Reference it from npm or the CDN; it is a separate proprietary package and is never vendored here.
## For AI agents
- **[`skill.md`](skill.md)** โ the agent-facing contract: every endpoint, its price, its response schema, and how to pay. Point your agent at this file.
- **`GET /.well-known/x402`** โ machine-readable discovery ([manifest](public/.well-known/x402)). Lists both rails per resource.
- **[`examples/mcp-tool.md`](examples/mcp-tool.md)** โ expose this service as an MCP tool for Claude in about 30 lines.
- **[`examples/agent-client.ts`](examples/agent-client.ts)** โ a complete paid call with `x402-fetch`, printing the artifact and the decoded settlement receipt.
- **Discovery/listing** โ indexable by [x402scan.com](https://x402scan.com), the [x402 Bazaar](https://x402.org), and [agentic.market](https://agentic.market). Deploy, then submit your public base URL; all three read `/.well-known/x402`.
## Docs
<https://nirholas.github.io/x402-shipping/> โ [tutorial](docs/tutorial.md) ยท [API reference](docs/api.md) ยท [for agents](docs/agents.md)
## Support
nichxbt@gmail.com
## License
Apache-2.0 โ see [LICENSE](LICENSE).
Part of the [x402 Suite](https://github.com/nirholas/x402-suite).
## Star History
[](https://www.star-history.com/#nirholas/x402-shipping&Date)
<!-- three.ws:growth -->
## Support the project
If x402-shipping saves you time, **[star it on GitHub](https://github.com/nirholas/x402-shipping)**. Stars are how other developers and AI agents find the repositories worth trusting, and they cost you one click.
Know someone who would use it? [Post on X](https://twitter.com/intent/tweet?text=x402-shipping%3A%20Rate%20shopping%20and%20label%20generation%20via%20Shippo%2FEasyPost%20test%20mode%3A%20agents%20ship%20things%2C%20label&url=https%3A%2F%2Fgithub.com%2Fnirholas%2Fx402-shipping) ยท [Share on Bluesky](https://bsky.app/intent/compose?text=x402-shipping%3A%20Rate%20shopping%20and%20label%20generation%20via%20Shippo%2FEasyPost%20test%20mode%3A%20agents%20ship%20things%2C%20label%20https%3A%2F%2Fgithub.com%2Fnirholas%2Fx402-shipping) ยท [Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fgithub.com%2Fnirholas%2Fx402-shipping) ยท [Submit to Hacker News](https://news.ycombinator.com/submitlink?u=https%3A%2F%2Fgithub.com%2Fnirholas%2Fx402-shipping&t=x402-shipping%3A%20Rate%20shopping%20and%20label%20generation%20via%20Shippo%2FEasyPost%20test%20mode%3A%20agents%20ship%20things%2C%20label) ยท [Share on Reddit](https://www.reddit.com/submit?url=https%3A%2F%2Fgithub.com%2Fnirholas%2Fx402-shipping&title=x402-shipping%3A%20Rate%20shopping%20and%20label%20generation%20via%20Shippo%2FEasyPost%20test%20mode%3A%20agents%20ship%20things%2C%20label)
## Built for AI agents too
Coding agents and LLM tooling can read this repo directly: [AGENTS.md](./AGENTS.md), [llms.txt](./llms.txt), [llms-full.txt](./llms-full.txt). Point an agent at `https://github.com/nirholas/x402-shipping` and it has the context it needs.
## More from the same author
- [All repositories by nirholas](https://github.com/nirholas/nirholas#readme): the full catalog, grouped by topic
- [three.ws](https://three.ws): the platform for 3D AI agents with Solana wallets, a skill marketplace and x402 payments
- Questions or ideas: [open an issue](https://github.com/nirholas/x402-shipping/issues) or [start a discussion](https://github.com/nirholas/x402-shipping/discussions)
## Contributors
[](https://github.com/nirholas/x402-shipping/graphs/contributors)
<!-- /three.ws:growth -->
<!-- nirholas:watermark -->
---
<p align="center">
Built by <a href="https://github.com/nirholas"><b>nirholas</b></a> ยท <a href="https://x.com/nichxbt">@nichxbt</a> ยท <a href="https://github.com/nirholas">github.com/nirholas</a>
</p>
<!-- /nirholas:watermark -->