# API overview

Base URL: `https://razcryptogateway.com/v1` (self-hosted: your own API host).

## Authentication
Every request uses your **secret key** as a Bearer token:
```bash
curl https://razcryptogateway.com/v1/payments \
  -H "Authorization: Bearer sk_test_xxxxxxxxxxxxxxxxxxxxxxxx"
```
| Key | Prefix | Where to use |
|---|---|---|
| Secret | `sk_live_` / `sk_test_` | Your server only. Full API access. Shown once at creation. |
| Publishable | `pk_live_` / `pk_test_` | Browser / app (`checkout.js`). Can only open checkout for payments you created. |

Keys belong to an **API app** (Dashboard → Developers). The app also holds your webhook URL and
secret. Roll keys any time; the old key can stay valid for up to 24 h.

### Check your key — `GET /v1/merchant`
Captured from a running server (test mode, 2026-10-02; key shortened):
```bash
curl https://razcryptogateway.com/v1/merchant   -H "Authorization: Bearer sk_test_…"
```
```
HTTP/1.1 200 OK
request-id: req_MRNiZ1U3W4ljn4QS
```
```json
{"object":"merchant","id":"mer_yaMdYjqWhoxgESBSxWOJ","business_name":"Docs Demo Store","livemode":false,"key_kind":"secret"}
```
Basic auth also works (`-u sk_test_…:`), like Stripe. A publishable key may call this endpoint too
(`key_kind: "publishable"`); every other `/v1` endpoint needs the secret key.

Without a key:
```json
{"error":{"type":"authentication_error","code":"authentication_required","message":"Send your secret key as \"Authorization: Bearer sk_…\"","request_id":"req_pLxlukLR5fqAI0fT","doc_url":"https://razcryptogateway.com/docs/errors#authentication_required"}}
```
Wrong or revoked key:
```json
{"error":{"type":"authentication_error","code":"api_key_invalid","message":"Invalid API key","request_id":"req_o7enKA3ZKNLnlFrN","doc_url":"https://razcryptogateway.com/docs/errors#api_key_invalid"}}
```
(`doc_url` points to the docs on this site: `https://razcryptogateway.com/docs/errors#…`.)

## Test mode
`*_test_` keys use a fully separate sandbox: test wallets activate instantly, no blockchain is touched,
and you move a payment to `paid`, `underpaid`, `overpaid`, `expired` or `cancelled` with
`POST /v1/payments/{id}/simulate` — real signed webhooks are sent. Test mode works even without an active
subscription. Every object has `"livemode"`.

## Conventions
- JSON request and response bodies, UTF-8. Field names are `snake_case`.
- **Amounts are decimal strings** (`"25.00"`, `"0.001234"`), never numbers.
- Timestamps: ISO-8601 UTC (`"2026-10-02T10:15:00Z"`).
- Ids are prefixed: `pay_`, `lnk_`, `evt_`, `whd_`, `app_`, `wal_`, `trf_`.
- Every object has `"object"` (e.g. `"payment"`).
- `metadata`: up to 50 keys, key ≤ 40 chars, value ≤ 500 chars (strings).
- Unknown fields in requests → `400 invalid_request` (prevents typos silently passing).
- New fields may be added to responses at any time; never removed or renamed inside `/v1`.

## Pagination (cursor)
List endpoints accept `limit` (1–100, default 20), `starting_after` or `ending_before` (an object id).
```json
{ "object": "list", "data": [ … ], "has_more": true, "next_cursor": "pay_…" }
```

## Idempotency
Send `Idempotency-Key: <uuid>` on any `POST`. Keys are kept 24 h per mode.
- Same key + same body → the original response is replayed (header `Idempotent-Replayed: true`).
- Same key + different body → `409 idempotency_key_reused`.
- Same key while the first request is still running → `409 idempotency_key_in_progress`.
SDKs add keys automatically.

## Errors
One shape for every error (details in [errors.md](/docs/errors)):
```json
{
  "error": {
    "type": "invalid_request_error",
    "code": "amount_invalid",
    "message": "amount must be a positive decimal string",
    "param": "amount",
    "request_id": "req_7Hc2kP0qWm3e",
    "doc_url": "https://razcryptogateway.com/docs/errors#amount_invalid"
  }
}
```

## Rate limits
Default 100 requests / 10 s per key (live), 25 / 10 s (test); admin-tunable. Headers:
`RateLimit-Limit`, `RateLimit-Remaining`, `RateLimit-Reset`. Over the limit → `429 rate_limited`
with `Retry-After`.

## Request ids
Every response has `Request-Id`. Include it when contacting support.

## Versioning
The path version (`/v1`) is stable. Additive changes only. A future `/v2` would run in parallel.

## Endpoints
| Area | Doc |
|---|---|
| Payments | [payments.md](/docs/payments) |
| Checkout (`checkout.js`, hosted page, custom checkout, callback signature) | [checkout.md](/docs/checkout) |
| Payment links | [payment-links.md](/docs/payment-links) |
| Webhooks | [webhooks.md](/docs/webhooks) |
| Chains, coins & rates | [chains-and-rates.md](/docs/chains-and-rates) |
| Errors | [errors.md](/docs/errors) |

OpenAPI: `GET https://razcryptogateway.com/v1/openapi.json`.
