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

# Create a checkout session

Creates a checkout session (DB only, no order, no external API calls). The order is created separately via POST /orders with checkoutSessionId.

` POST /checkout-sessions `

Create a checkout session

Creates a checkout session (DB only, no order, no external API calls). The order is created separately via POST /orders with checkoutSessionId.

## Servers

- ` https://mainnet.anyspend.com ` — Production server

## Request body (required)

Content type: ` application/json `

- ` value `: type ` object ` — Request body for creating a checkout session

  - ` success_url `: type ` string `; format ` uri ` — URL to redirect to on successful payment. Supports {SESSION_ID} and {ORDER_ID} template variables.

    - example: ` "https://merchant.com/success?session_id={SESSION_ID}" `

  - ` cancel_url `: type ` string `; format ` uri ` — URL to redirect to on cancellation. Supports {SESSION_ID} and {ORDER_ID} template variables.

    - example: ` "https://merchant.com/cancel" `

  - ` metadata `: type ` object ` — Arbitrary key-value metadata returned unchanged on retrieval

    - example: ` {"sku":"widget-1","customer_id":"cust-123"} `

  - ` client_reference_id `: type ` string ` — Optional merchant-side reference ID

    - maxLength: ` 255 `

  - ` expires_in `: type ` number ` — Session TTL in seconds (min 300, max 86400, default 1800)

    - default: ` 1800 `

    - example: ` 1800 `

    - minimum: ` 300 `

    - maximum: ` 86400 `

## Responses

### ` 200 ` — Checkout session created successfully

Content type: ` application/json `

- ` value `: type ` object `

  - Required fields: ` success `, ` message `, ` data `, ` statusCode `

  - ` success `: type ` boolean `

    - example: ` true `

  - ` message `: type ` string `

    - example: ` "Checkout session created" `

  - ` data `: type ` object ` — Response from creating a checkout session. No order_id, checkout_url, or deposit_address — those come after order creation.

    - Required fields: ` id `, ` status `, ` success_url `, ` cancel_url `, ` metadata `, ` expires_at `, ` created_at `

    - ` id `: type ` string `; format ` uuid ` — Checkout session UUID

      - example: ` "550e8400-e29b-41d4-a716-446655440000" `

    - ` status `: type ` string ` — Checkout session status

      - enum: ` ["open","processing","complete","expired"] `

    - ` success_url `: type ` string `; nullable — Success redirect URL (unresolved template)

    - ` cancel_url `: type ` string `; nullable — Cancel redirect URL (unresolved template)

    - ` metadata `: type ` object `

    - ` expires_at `: type ` string `; format ` date-time ` — ISO 8601 expiry timestamp

    - ` created_at `: type ` string `; format ` date-time ` — ISO 8601 creation timestamp

  - ` statusCode `: type ` number `

    - example: ` 200 `

### ` 400 ` — Bad request

Content type: ` application/json `

- ` value `: type ` object `

  - Required fields: ` success `, ` message `, ` statusCode `

  - ` success `: type ` boolean `

    - example: ` false `

  - ` message `: type ` string `

    - example: ` "Bad request" `

  - ` statusCode `: type ` number `

    - example: ` 400 `

## Request examples

### cURL

```curl
curl -X POST 'https://mainnet.anyspend.com/checkout-sessions' \
  -H 'Content-Type: application/json' \
  -d '{
  "success_url": "https://merchant.com/success?session_id={SESSION_ID}",
  "cancel_url": "https://merchant.com/cancel",
  "metadata": {
    "sku": "widget-1",
    "customer_id": "cust-123"
  },
  "client_reference_id": "string",
  "expires_in": 1800
}'
```

### JavaScript

```javascript
const response = await fetch('https://mainnet.anyspend.com/checkout-sessions', {
  method: 'POST',
  headers: {
      "Content-Type": "application/json"
  },
  body: JSON.stringify({
    "success_url": "https://merchant.com/success?session_id={SESSION_ID}",
    "cancel_url": "https://merchant.com/cancel",
    "metadata": {
      "sku": "widget-1",
      "customer_id": "cust-123"
    },
    "client_reference_id": "string",
    "expires_in": 1800
  })
});

const data = await response.json();
console.log(data);
```

### Python

```python
import requests

response = requests.post('https://mainnet.anyspend.com/checkout-sessions', json={
  "success_url": "https://merchant.com/success?session_id={SESSION_ID}",
  "cancel_url": "https://merchant.com/cancel",
  "metadata": {
    "sku": "widget-1",
    "customer_id": "cust-123"
  },
  "client_reference_id": "string",
  "expires_in": 1800
})
print(response.json())
```