---
title: "API conventions"
description: "Authentication, errors, pagination, money, idempotency, and rate limits across the EdgeCart API."
---

> Documentation Index
> Fetch the complete documentation index at: https://edgecart.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# API conventions

These conventions apply across the Storefront and Admin APIs. The generated
[API reference](https://edgecart.dev/api) currently lists Storefront operations; this page covers
the rules that are the same everywhere.

## Base URL

All routes live under `/api` on your EdgeCart deployment:

```text
https://<your-store-domain>/api
```

## Authentication

| API | Credentials |
|---|---|
| Admin | The signed-in store member's session cookie plus the `x-store-id` header. |
| Storefront | The publishable API key in `x-publishable-api-key`. |
| Storefront bootstrap | No key: `GET /api/storefront-config` returns the publishable key and store profile. |
| Customer account | A signed-in customer session cookie, in addition to the publishable key. |

Admin roles are `owner`, `admin`, `member`, and `viewer`. A request for a store
the member does not belong to returns `404`, not `403`, so it does not reveal
whether the store exists.

> **Keep secret keys on the server**
>
> Publishable keys (`pk_...`) are safe to send to browsers. Secret keys are
> server-side only; EdgeCart stores only their hash.

## Errors

Errors use one JSON shape:

```json
{
  "type": "invalid_data",
  "message": "Price must be a non-negative integer",
  "code": "invalid_price"
}
```

| `type` | HTTP status | Meaning |
|---|---|---|
| `invalid_data` | 400 | The request body or query is invalid. |
| `unauthorized` | 401 | No valid session or API key. |
| `not_found` | 404 | The resource does not exist in this store. |
| `conflict` | 409 | The request conflicts with the current state. |
| `duplicate_error` | 422 | A uniqueness constraint failed. |
| `payment_authorization_error` | 422 | The payment provider refused authorization. |
| `database_error` | 500 | An unexpected database failure. |
| `unknown_error` | 500 | An unexpected server failure. |

`code` is optional and adds a stable, more specific identifier.

## Money

All amounts are integer **minor units** paired with a lowercase ISO currency
code. `2050` with `usd` means `$20.50`. Never send decimals.

## Lists, pagination, and field selection

List responses use a shared envelope:

```json
{
  "products": [],
  "count": 0,
  "offset": 0,
  "limit": 50
}
```

Use `offset` and `limit` for pagination. Use `fields=` to request a subset of
fields where the operation supports it.

## Idempotency

Mutation requests accept an `Idempotency-Key` header. Reuse the same key when
retrying the same request; a different request body with the same key is
rejected. Keys are scoped per store.

## CSRF and origins

Cookie-authenticated mutations check the request `Origin` against
`TRUSTED_ORIGINS`. Browser origins allowed to call the API with credentials must
be configured by the deployment operator; the defaults cover only local
development and the upstream demo origin.

## Rate limits

The deployment applies Cloudflare rate-limit bindings per route:

- **Basic:** 100 requests per minute.
- **Strict:** 3 requests per minute.

When a limit is exceeded, the request fails with the platform's rate-limit
response. Retry after the window resets; do not retry in a tight loop.

## Webhooks

Webhook deliveries are signed with
`x-edgecart-signature: t=<timestamp>,v1=<hmac>`. Verify the HMAC over
`<timestamp>.<body>` before trusting the payload. Delivery is at least once, so
deduplicate by event ID. See the
[Observability module](https://edgecart.dev/modules/observability) for retries, endpoint
deactivation, and event subscriptions.

Source: https://edgecart.dev/reference/api-conventions/index.mdx
