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

# Create a checkout session

> Creates a hosted checkout session and returns a checkoutUrl to redirect the buyer to.



## OpenAPI

````yaml /api-reference/openapi.json post /api/gateway/sessions
openapi: 3.1.0
info:
  title: Open Rails API
  version: 0.1.0
  description: >-
    Hosted checkout, provider routing, runtime schemas, and normalized webhook
    examples for Open Rails merchants and agents.
servers:
  - url: https://dash.getopenrails.com
    description: Production dashboard and API origin
security: []
tags:
  - name: Gateway
  - name: Agent
  - name: Routing
  - name: Webhooks
paths:
  /api/gateway/sessions:
    post:
      tags:
        - Gateway
      summary: Create a checkout session
      description: >-
        Creates a hosted checkout session and returns a checkoutUrl to redirect
        the buyer to.
      operationId: createGatewaySession
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GatewaySessionInput'
      responses:
        '200':
          description: Checkout session created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GatewayCheckoutSession'
        '400':
          description: Invalid input
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorResponse'
components:
  schemas:
    GatewaySessionInput:
      type: object
      additionalProperties: false
      required:
        - product
        - amount
        - customer
      properties:
        product:
          type: string
          minLength: 1
          maxLength: 120
        amount:
          type: number
          exclusiveMinimum: 0
          maximum: 10000
        customer:
          type: string
          format: email
        preferredRoute:
          $ref: '#/components/schemas/RouteKind'
        redirectUrl:
          type: string
          format: uri
        metadata:
          $ref: '#/components/schemas/Metadata'
        environment:
          $ref: '#/components/schemas/Environment'
        idempotencyKey:
          type: string
          minLength: 8
          maxLength: 120
        clientReferenceId:
          type: string
          minLength: 3
          maxLength: 120
    GatewayCheckoutSession:
      type: object
      required:
        - id
        - object
        - checkoutUrl
        - status
        - amount
        - currency
      properties:
        id:
          type: string
          description: Checkout session ID with chk_* prefix.
        object:
          type: string
          enum:
            - checkout_session
        checkoutUrl:
          type: string
          format: uri
        redirectUrl:
          type: string
          format: uri
        status:
          type: string
          enum:
            - routed
            - pending
            - paid
            - failed
            - expired
        amount:
          type: number
        currency:
          type: string
        customer:
          type: string
          format: email
        metadata:
          $ref: '#/components/schemas/Metadata'
        environment:
          $ref: '#/components/schemas/Environment'
    ApiErrorResponse:
      type: object
      required:
        - ok
        - error
      properties:
        ok:
          type: boolean
          enum:
            - false
        error:
          $ref: '#/components/schemas/ActionError'
    RouteKind:
      type: string
      enum:
        - card
        - wallet
        - local
    Metadata:
      type: object
      additionalProperties:
        type: string
        maxLength: 500
      default: {}
    Environment:
      type: string
      enum:
        - sandbox
        - production
      default: sandbox
    ActionError:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: string
        message:
          type: string
        field:
          type: string
        suggestion:
          type: string
        issues:
          type: array
          items:
            type: object
            properties:
              path:
                type: string
              code:
                type: string
              message:
                type: string

````