commodities.sh

Docs

Authentication

Three lanes: a free key by email, x402 for agents (default, no account), and Pro API keys for operators who prefer Stripe credits. All three keys travel in the same Authorization header.

How do I get a free API key?

POST /v1/signup with {"email":"you@example.com"}, or use the form at /signup. Opening the emailed link verifies the address and shows the key once; it is also emailed. Send it as Authorization: Bearer cs_free_…, the same header a Pro key uses. It allows 50 requests a day and 10 a minute per key, covers the latest print for every instrument plus FX, stats, crack, crush and basis, and returns the last 30 days on /v1/history/{code}. Positioning, inventories, fundamentals, minerals, trade, calculators and the packs answer the ordinary HTTP 402. Past a rate limit the answer is 429 with Retry-After — never 402, because nothing is owed. Upgrading to Pro with the same email rewrites the plan on that key, so the string you have configured keeps working and the cs_free_ prefix stays; read /v1/quota rather than the prefix to learn a key's plan.

How do agents authenticate?

Agents should use x402: probe a paid route, settle USDC on Base from the 402 challenge, retry with X-PAYMENT. No long-lived secret is required.

How do Pro API keys work?

Human operators buy Pro ($19/mo or $180/yr) at /get-started, receive a cs_live_… key once, and send Authorization: Bearer cs_live_… on paid routes. Each call debits credits (1 credit = $0.01 of list price). Exhausted quota returns HTTP 402 QUOTA_EXCEEDED. Checking out with the email that already holds a free key upgrades that key in place rather than issuing a second one.

  1. A

    x402 (agents)

  2. 01

    Request

    GET api.commodities.sh/v1/inventory/eia — or any paid route. No API key.

  3. 02

    402

    Server returns HTTP 402 with USDC payment requirements on Base.

  4. 03

    Pay & retry

    Settle in USDC, attach the X-PAYMENT proof header, receive the observation.

Example request

bash
curl -i https://api.commodities.sh/v1/price/CL
# → HTTP 402 Payment Required (when X402_ENFORCE=true)
# Settle USDC on Base, retry with X-PAYMENT

Sample 402 body

json
{
  "x402Version": 2,
  "error": "PAYMENT_REQUIRED",
  "accepts": [{
    "scheme": "exact",
    "network": "eip155:8453",
    "maxAmountRequired": "10000",
    "resource": "/v1/price/CL",
    "description": "commodities.sh price"
  }]
}

Retry the same URL with header X-PAYMENT: <proof>.

Soft-GO note

When X402_ENFORCE is off (demo / Soft-GO), paid routes may return the observation body without a payment challenge. Treat that as a discovery convenience — production agent infrastructure should run with enforce on and a live facilitator.

Do I need an API key?

Not for discovery — catalog, search, calendar, llms.txt, OpenAPI and the MCP handshake need nothing. For observations, agents can use x402 with no account at all. Otherwise a free key from /signup covers latest prices, FX, stats and spreads, and a Pro key from /get-started ($19/mo or $180/yr, 3,000 credits/month) covers everything. Both send Authorization: Bearer <key>.

Which network and asset for x402?

USDC on Base (eip155:8453). The 402 accepts array describes scheme, network, maxAmountRequired, and the resource path for the call you requested.

What if I get a 200 without paying?

Soft-GO demos may leave X402_ENFORCE off so agents can explore response shapes when no API key is present. Check /health and env posture before assuming payment is verified in production.

← Docs hub

Related