openapi: 3.1.0
info:
  title: Vybe Collect Merchant API
  version: 0.1.0
  description: |
    Public HTTP contract for Vybe Collect sellers — catalog, HTTP 402 pay,
    Native Checkout sessions, business API keys, and webhooks.

    **Human guide:** https://www.vybe.finance/collect/integrate

    Auth for merchant routes: `Authorization: Bearer vybe_col_…`

    Settlement is USDC/USDT on Base, Ethereum, and BNB — not card acquiring.
  contact:
    name: Vybe
    url: https://www.vybe.finance/collect
servers:
  - url: https://www.vybe.finance
    description: Production
tags:
  - name: Agent catalog
    description: Machine-readable offerings and HTTP 402 pay
  - name: Invoke
    description: Pay-then-call proxy for API and MCP offerings
  - name: Checkout
    description: Native Checkout sessions (`/r/{id}`)
  - name: Business API
    description: Keys, offerings, webhooks (Bearer vybe_col_…)
paths:
  /api/agent/collect/{username}:
    get:
      tags: [Agent catalog]
      summary: Agent catalog
      parameters:
        - $ref: '#/components/parameters/username'
      responses:
        '200':
          description: Published offerings with pay URLs
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AgentCatalog'
        '404':
          $ref: '#/components/responses/NotFound'
  /api/agent/collect/{username}/{offeringId}:
    get:
      tags: [Agent catalog]
      summary: Create payment intent (402)
      description: Returns HTTP 402 with x402-shaped body and PAYMENT-REQUIRED header.
      parameters:
        - $ref: '#/components/parameters/username'
        - $ref: '#/components/parameters/offeringId'
      responses:
        '402':
          $ref: '#/components/responses/PaymentRequired'
    post:
      tags: [Agent catalog]
      summary: Create payment intent (402)
      parameters:
        - $ref: '#/components/parameters/username'
        - $ref: '#/components/parameters/offeringId'
      responses:
        '402':
          $ref: '#/components/responses/PaymentRequired'
  /api/agent/collect/{username}/{offeringId}/status:
    get:
      tags: [Agent catalog]
      summary: Poll payment status
      parameters:
        - $ref: '#/components/parameters/username'
        - $ref: '#/components/parameters/offeringId'
        - name: publicId
          in: query
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Intent status
    post:
      tags: [Agent catalog]
      summary: Settle with tx hash
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [publicId, txHash]
              properties:
                publicId:
                  type: string
                txHash:
                  type: string
                chain:
                  type: string
                token:
                  type: string
                  enum: [usdc, usdt]
      responses:
        '200':
          description: Paid or pending verification
  /api/agent/invoke/{username}/{offeringId}/{path}:
    get:
      tags: [Invoke]
      summary: Gated invoke (REST)
      description: Requires X-Vybe-Public-Id after pay or Bearer vapt_… for trial.
      parameters:
        - $ref: '#/components/parameters/username'
        - $ref: '#/components/parameters/offeringId'
        - name: path
          in: path
          required: true
          schema:
            type: string
      responses:
        '402':
          $ref: '#/components/responses/PaymentRequired'
        '502':
          description: Upstream error
    post:
      tags: [Invoke]
      summary: Gated invoke (MCP JSON-RPC or REST)
      parameters:
        - $ref: '#/components/parameters/username'
        - $ref: '#/components/parameters/offeringId'
        - name: path
          in: path
          required: false
          schema:
            type: string
      responses:
        '402':
          $ref: '#/components/responses/PaymentRequired'
  /api/checkout/sessions:
    post:
      tags: [Checkout]
      summary: Create checkout session
      security:
        - CollectApiKey: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CheckoutSessionCreate'
      responses:
        '201':
          description: Session created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CheckoutSession'
  /api/checkout/sessions/{id}:
    get:
      tags: [Checkout]
      summary: Retrieve checkout session
      security:
        - CollectApiKey: []
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Session
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CheckoutSession'
  /api/collect/v1/credentials:
    post:
      tags: [Business API]
      summary: Create Collect API key
      responses:
        '201':
          description: Key created (shown once)
    get:
      tags: [Business API]
      summary: List key prefixes
      parameters:
        - name: crossmintId
          in: query
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Credential list
  /api/collect/v1/offerings:
    get:
      tags: [Business API]
      summary: Read offerings
      security:
        - CollectApiKey: []
      responses:
        '200':
          description: Service page offerings
    put:
      tags: [Business API]
      summary: Upsert offerings
      security:
        - CollectApiKey: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                agentCollectEnabled:
                  type: boolean
                offerings:
                  type: array
                  items:
                    $ref: '#/components/schemas/OfferingUpsert'
      responses:
        '200':
          description: Updated
  /api/collect/v1/webhook:
    get:
      tags: [Business API]
      summary: Webhook config
      security:
        - CollectApiKey: []
      responses:
        '200':
          description: Webhook URL and config
    put:
      tags: [Business API]
      summary: Register webhook URL
      security:
        - CollectApiKey: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [url]
              properties:
                url:
                  type: string
                  format: uri
                rotateSecret:
                  type: boolean
      responses:
        '200':
          description: Saved
components:
  securitySchemes:
    CollectApiKey:
      type: http
      scheme: bearer
      bearerFormat: vybe_col_
  parameters:
    username:
      name: username
      in: path
      required: true
      schema:
        type: string
    offeringId:
      name: offeringId
      in: path
      required: true
      schema:
        type: string
  responses:
    NotFound:
      description: Not found
    PaymentRequired:
      description: Payment required — settle then retry with X-Vybe-Public-Id
      headers:
        PAYMENT-REQUIRED:
          schema:
            type: string
        X-Vybe-Public-Id:
          schema:
            type: string
  schemas:
    AgentCatalog:
      type: object
      properties:
        username:
          type: string
        offerings:
          type: array
          items:
            type: object
            properties:
              id:
                type: string
              title:
                type: string
              priceUsd:
                type: string
              type:
                type: string
              payUrl:
                type: string
              invoke:
                type: object
                properties:
                  invokeUrl:
                    type: string
    OfferingUpsert:
      type: object
      properties:
        id:
          type: string
        title:
          type: string
        priceUsd:
          type: string
        kind:
          type: string
          enum: [session, api, mcp, asset, credit, membership, event, license, retainer, tip]
        integration:
          type: object
          properties:
            invokeBaseUrl:
              type: string
            mcpServerUrl:
              type: string
            openapiUrl:
              type: string
        trialFreeRequests:
          type: integer
          minimum: 0
          maximum: 100
    CheckoutSessionCreate:
      type: object
      properties:
        mode:
          type: string
          enum: [payment]
        line_items:
          type: array
          maxItems: 1
          items:
            type: object
            properties:
              price:
                type: string
                description: Collect offering id
              price_data:
                type: object
                properties:
                  currency:
                    type: string
                    enum: [usdc, usdt]
                  unit_amount:
                    type: string
        amount:
          type: string
        currency:
          type: string
          enum: [usdc, usdt]
        memo:
          type: string
        success_url:
          type: string
          format: uri
        cancel_url:
          type: string
          format: uri
        metadata:
          type: object
          additionalProperties:
            type: string
            maxLength: 500
    CheckoutSession:
      type: object
      properties:
        id:
          type: string
        object:
          type: string
          enum: [checkout.session]
        url:
          type: string
          format: uri
        agent_pay_url:
          type: string
          format: uri
        payment_status:
          type: string
          enum: [paid, unpaid]
        metadata:
          type: object
          additionalProperties:
            type: string
    CollectWebhookEvent:
      type: object
      properties:
        protocol:
          type: string
          example: vybe-agent-collect
        version:
          type: string
          example: "0.1"
        type:
          type: string
          enum: [payment.paid, payment.expired, webhook.test]
        publicId:
          type: string
        offeringId:
          type: string
          nullable: true
        amount:
          type: string
        token:
          type: string
        settlementTxHash:
          type: string
          nullable: true
        paidAt:
          type: string
          format: date-time
        metadata:
          type: object
          additionalProperties:
            type: string
