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

> ## Agent Instructions
> Sapiom is for platforms whose agent shops for many users. Each user has their own Sapiom user key and saved cards.
> Use the user's key for every call made on that user's behalf. Never use one user's key for another user, and never give the agent the platform key.
> Backends call the REST API at https://api.sapiom.ai/v1. Agents can also call the hosted MCP tools at https://api.sapiom.ai/v1/mcp/pay. Both take the key in an x-api-key header.
> Keys that start with sk_test_ reach the sandbox, a separate environment with its own users and cards, at the same addresses. Use test card numbers only there.
> Never ask a user for a card number, expiry date or CVV in chat. Users enter card details only on Sapiom's hosted pages.
> Check the merchant before buying. Use purchase.type ucp_checkout only when the merchant check returns supported. Otherwise use browser_checkout.
> Follow the nextAction in each transaction result. Action links are secrets. Send each one only to the person `nextAction.actor` names.
> Use one idempotency key per transaction. Resume an unanswered create with the same request and key. If a UCP update or cancellation is uncertain, stop and hand off to a person. If a browser cancellation is uncertain, read the transaction and resend the same cancellation, with the same key, only if it is not closed. Never start a new transaction to escape an uncertain outcome.
> For a ucp_checkout purchase, report an order as placed only when order.outcome is confirmed; if it is unknown, stop and hand off to a person. A browser_checkout purchase has no order confirmation (order is null): confirm the order on the merchant's page.
> Read https://docs.sapiom.ai/skill.md for Sapiom's rules and purchase steps. To install it as a skill, run npx skills add https://docs.sapiom.ai.

# Create an API key

> Creates an API key for your organization. To create a versioned platform key, send `authorizationVersion: 1` and `accessType: "platform"`, and omit `permissions`. A versioned key must send `authorizationVersion: 1`. To create a key for one user, use [Create a user key](/api-reference/users/create-a-user-key). The response includes `plainKey`, which is shown only once. Requires a key with `org.api_keys.write`, such as a versioned platform key.



## OpenAPI

````yaml /api-reference/openapi.json post /v1/api-keys
openapi: 3.0.0
info:
  title: Sapiom Pay API
  version: '1.0'
  description: >-
    Create users, save their cards and authorize transactions. Send your
    platform key or a user key in the `x-api-key` header.
servers:
  - url: https://api.sapiom.ai
    description: Production
security:
  - api-key: []
tags:
  - name: Users
    description: One Sapiom user for each of your users. Called tenants in the API.
  - name: API keys
    description: >-
      Create, list and revoke your organization's API keys, and see which
      permissions a new key can have.
  - name: Cards
    description: Hosted setup links and the user's saved cards.
  - name: Spending limits
    description: Limits on what each card can spend.
  - name: Merchants
    description: Check whether Sapiom can buy from a merchant.
  - name: Transactions
    description: Create, read, update and cancel a transaction, and drive its UCP checkout.
  - name: Browser Pay relay
    description: The relay Browser Pay uses to send the card, for either purchase type.
paths:
  /v1/api-keys:
    post:
      tags:
        - API keys
      summary: Create an API key
      description: >-
        Creates an API key for your organization. To create a versioned platform
        key, send `authorizationVersion: 1` and `accessType: "platform"`, and
        omit `permissions`. A versioned key must send `authorizationVersion: 1`.
        To create a key for one user, use [Create a user
        key](/api-reference/users/create-a-user-key). The response includes
        `plainKey`, which is shown only once. Requires a key with
        `org.api_keys.write`, such as a versioned platform key.
      operationId: ApiKeyController_createApiKey
      parameters:
        - description: >-
            For a versioned key. At most 255 characters. If a create times out,
            send the same request again with the same value. If the first
            request created a key, Sapiom returns `409 api_key_already_created`
            with its `apiKeyId`, not a second key.
          in: header
          name: Idempotency-Key
          required: false
          schema:
            type: string
        - description: >-
            `tenant:` and a user's ID. A versioned platform key uses it to act
            for that user.
          in: header
          name: Sapiom-Scope
          required: false
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateApiKeyDto'
        required: true
      responses:
        '201':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateApiKeyResponseDto'
          description: API key created successfully
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiKeyErrorResponseDto'
          description: Invalid request data
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiKeyErrorResponseDto'
          description: The key is missing or not valid.
        '403':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiKeyErrorResponseDto'
          description: Forbidden - insufficient permissions
        '409':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiKeyErrorResponseDto'
          description: >-
            `api_key_already_created`: a request with this `Idempotency-Key`
            already created a key, named in `apiKeyId`. Sapiom does not return
            its `plainKey` again. `idempotency_conflict`: this `Idempotency-Key`
            was already used for a request with a different endpoint, `name`,
            `description`, `accessType` or `permissions`.
      security:
        - api-key: []
components:
  schemas:
    CreateApiKeyDto:
      properties:
        accessType:
          description: >-
            Required with `authorizationVersion: 1`. `platform` creates a
            platform key. `tenant` creates a key for one user.
          enum:
            - platform
            - tenant
          type: string
        authorizationVersion:
          description: Send `1` to create a versioned key. A versioned key must send `1`.
          enum:
            - 1
          type: number
        description:
          description: Optional description of the API key
          example: Used for production integrations
          maxLength: 1000
          type: string
        name:
          description: Name of the API key
          example: My Production API Key
          maxLength: 255
          minLength: 1
          type: string
        permissions:
          description: >-
            Only with `authorizationVersion: 1` and `accessType: "tenant"`. Omit
            it for the fixed-key defaults, or send the exact permissions to
            grant. Omit it for a platform key.
          items:
            type: string
          minItems: 1
          type: array
        type:
          description: >-
            Optional. Your key's environment decides the type: `live` for a live
            key, `test` for a sandbox key. Omit it or send that value. Another
            value returns `400`.
          enum:
            - live
            - test
          type: string
      required:
        - name
      type: object
    CreateApiKeyResponseDto:
      properties:
        apiKey:
          allOf:
            - $ref: '#/components/schemas/ApiKeyResponseDto'
          description: Nonsecret metadata of the created API key
        plainKey:
          description: The plain text API key (only shown once)
          example: sk_live_<43-char-base62-string>
          type: string
      required:
        - apiKey
        - plainKey
      type: object
    ApiKeyErrorResponseDto:
      properties:
        apiKeyId:
          description: >-
            Only on `409 api_key_already_created`: the ID of the key that the
            first request created. Sapiom does not return its `plainKey` again.
          format: uuid
          type: string
        code:
          description: Stable public code. Most policy refusals use forbidden.
          type: string
        error:
          description: Existing HTTP error description, when supplied.
          type: string
        message:
          oneOf:
            - type: string
            - items:
                type: string
              type: array
        path:
          type: string
        requestId:
          type: string
        statusCode:
          type: number
        timestamp:
          format: date-time
          type: string
      required:
        - statusCode
        - code
        - message
        - requestId
        - timestamp
        - path
      type: object
    ApiKeyResponseDto:
      properties:
        accessType:
          description: '`platform` or `tenant`.'
          enum:
            - platform
            - tenant
          nullable: true
          type: string
          example: tenant
        authorizationVersion:
          description: '`1` for a versioned key.'
          type: number
          example: 1
        createdAt:
          format: date-time
          type: string
        createdByApiKeyId:
          format: uuid
          nullable: true
          type: string
        createdByUserId:
          format: uuid
          nullable: true
          type: string
        deletedAt:
          format: date-time
          nullable: true
          type: string
        description:
          type: string
          nullable: true
        effectivePermissions:
          description: >-
            The permissions the key has. `null` means that Sapiom cannot resolve
            them. This field does not show whether the key is revoked or
            expired.
          items:
            type: string
          nullable: true
          type: array
          example:
            - org.card_spending_limits.read
            - org.transactions.read
            - org.transactions.write
        expiresAt:
          format: date-time
          nullable: true
          type: string
        id:
          format: uuid
          type: string
        keyPrefix:
          type: string
        lastUsedAt:
          format: date-time
          nullable: true
          type: string
        name:
          type: string
        permissionMode:
          description: >-
            `shared` for a user key that follows your organization's default
            permissions. `fixed` for all other keys.
          enum:
            - fixed
            - shared
          type: string
        permissions:
          description: >-
            The stored permissions, including the permissions that they include.
            A versioned platform key stores `[]`.
          items:
            type: string
          nullable: true
          type: array
          example:
            - org.card_spending_limits.read
            - org.transactions.read
            - org.transactions.write
        revokedAt:
          format: date-time
          nullable: true
          type: string
        source:
          enum:
            - dashboard
            - cli-oauth
            - device-oauth
            - oauth
            - derived
            - auto-payment
          type: string
        tenantId:
          format: uuid
          type: string
        type:
          enum:
            - live
            - test
            - development
          type: string
          example: live
        updatedAt:
          format: date-time
          type: string
      required:
        - id
        - name
        - keyPrefix
        - type
        - source
        - permissions
        - authorizationVersion
        - accessType
        - effectivePermissions
        - permissionMode
        - expiresAt
        - tenantId
        - createdAt
        - updatedAt
      type: object
  securitySchemes:
    api-key:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        Your platform key for user management, or a user key for everything
        else.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.