openapi: 3.1.0
info:
  title: AgentPatch API
  version: 1.0.0
  description: API for discovering, registering, and invoking tools on AgentPatch.
servers:
  - url: https://agentpatch.ai
    description: Production
components:
  schemas: {}
  parameters: {}
paths:
  /api/track/pageview:
    post:
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                path:
                  type: string
                  minLength: 1
                  maxLength: 512
              required:
                - path
      responses:
        '204':
          description: Tracked
        '400':
          description: Invalid input
        '429':
          description: Rate limited
  /api/track/attribution:
    post:
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                ref:
                  type: string
                  minLength: 1
                  maxLength: 256
              required:
                - ref
      responses:
        '204':
          description: Tracked
        '401':
          description: Not authenticated
  /api/search:
    get:
      description: >-
        Search for context-optimized APIs. Omitting the q parameter returns all
        active public tools.
      parameters:
        - schema:
            type: string
          required: false
          name: q
          in: query
        - schema:
            type: number
            nullable: true
            minimum: 0
            maximum: 1
          required: false
          name: min_success_rate
          in: query
        - schema:
            type: integer
            nullable: true
            minimum: 0
          required: false
          name: max_price_credits
          in: query
        - schema:
            type: integer
            minimum: 1
            maximum: 100
            default: 20
          required: false
          name: limit
          in: query
      responses:
        '200':
          description: Search results
          content:
            application/json:
              schema:
                type: object
                properties:
                  tools:
                    type: array
                    items:
                      type: object
                      properties:
                        slug:
                          type: string
                        name:
                          type: string
                        description:
                          type: string
                        price_credits_per_call:
                          type: number
                        input_schema:
                          type: object
                          additionalProperties:
                            nullable: true
                        output_schema:
                          type: object
                          additionalProperties:
                            nullable: true
                        owner_name:
                          type: string
                          nullable: true
                        owner_username:
                          type: string
                          nullable: true
                        is_featured:
                          type: boolean
                        success_rate:
                          type: number
                          nullable: true
                        total_calls:
                          type: number
                          nullable: true
                        avg_latency_ms:
                          type: number
                          nullable: true
                        invocation_path:
                          type: string
                        invocation_example:
                          type: object
                          properties:
                            method:
                              type: string
                            url:
                              type: string
                            headers:
                              type: object
                              additionalProperties:
                                type: string
                            body:
                              type: object
                              additionalProperties:
                                nullable: true
                          required:
                            - method
                            - url
                            - headers
                            - body
                        sample_output:
                          type: object
                          properties:
                            job_id:
                              type: string
                            status:
                              type: string
                            output:
                              nullable: true
                            credits_used:
                              type: number
                          required:
                            - job_id
                            - status
                            - credits_used
                      required:
                        - slug
                        - name
                        - description
                        - price_credits_per_call
                        - input_schema
                        - output_schema
                        - is_featured
                        - success_rate
                        - total_calls
                        - avg_latency_ms
                        - invocation_path
                        - invocation_example
                        - sample_output
                  count:
                    type: number
                required:
                  - tools
                  - count
        '400':
          description: Invalid search parameters
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  details:
                    nullable: true
                required:
                  - error
  /api/tools:
    get:
      description: List all active public tools.
      responses:
        '200':
          description: All tools
          content:
            application/json:
              schema:
                type: object
                properties:
                  tools:
                    type: array
                    items:
                      type: object
                      properties:
                        slug:
                          type: string
                        name:
                          type: string
                        description:
                          type: string
                        price_credits_per_call:
                          type: number
                        input_schema:
                          type: object
                          additionalProperties:
                            nullable: true
                        output_schema:
                          type: object
                          additionalProperties:
                            nullable: true
                        owner_name:
                          type: string
                          nullable: true
                        owner_username:
                          type: string
                          nullable: true
                        success_rate:
                          type: number
                          nullable: true
                        total_calls:
                          type: number
                          nullable: true
                        avg_latency_ms:
                          type: number
                          nullable: true
                        invocation_path:
                          type: string
                        invocation_example:
                          type: object
                          properties:
                            method:
                              type: string
                            url:
                              type: string
                            headers:
                              type: object
                              additionalProperties:
                                type: string
                            body:
                              type: object
                              additionalProperties:
                                nullable: true
                          required:
                            - method
                            - url
                            - headers
                            - body
                        sample_output:
                          type: object
                          properties:
                            job_id:
                              type: string
                            status:
                              type: string
                            output:
                              nullable: true
                            credits_used:
                              type: number
                          required:
                            - job_id
                            - status
                            - credits_used
                      required:
                        - slug
                        - name
                        - description
                        - price_credits_per_call
                        - input_schema
                        - output_schema
                        - success_rate
                        - total_calls
                        - avg_latency_ms
                        - invocation_path
                        - invocation_example
                        - sample_output
                  count:
                    type: number
                required:
                  - tools
                  - count
  /api/tools/{slug}:
    get:
      parameters:
        - schema:
            type: string
            description: Tool slug (e.g., 'send-email')
          required: true
          name: slug
          in: path
      responses:
        '200':
          description: Tool details
          content:
            application/json:
              schema:
                type: object
                properties:
                  slug:
                    type: string
                  name:
                    type: string
                  description:
                    type: string
                  price_credits_per_call:
                    type: number
                  input_schema:
                    type: object
                    additionalProperties:
                      nullable: true
                  output_schema:
                    type: object
                    additionalProperties:
                      nullable: true
                  owner_name:
                    type: string
                    nullable: true
                  owner_username:
                    type: string
                    nullable: true
                  success_rate:
                    type: number
                    nullable: true
                  total_calls:
                    type: number
                    nullable: true
                  avg_latency_ms:
                    type: number
                    nullable: true
                  default_timeout_seconds:
                    type: number
                    nullable: true
                  max_timeout_seconds:
                    type: number
                    nullable: true
                  invocation_path:
                    type: string
                  invocation_example:
                    type: object
                    properties:
                      method:
                        type: string
                      url:
                        type: string
                      headers:
                        type: object
                        additionalProperties:
                          type: string
                      body:
                        type: object
                        additionalProperties:
                          nullable: true
                    required:
                      - method
                      - url
                      - headers
                      - body
                  sample_output:
                    type: object
                    properties:
                      job_id:
                        type: string
                      status:
                        type: string
                      output:
                        nullable: true
                      credits_used:
                        type: number
                    required:
                      - job_id
                      - status
                      - credits_used
                  platform:
                    type: object
                    properties:
                      name:
                        type: string
                      description:
                        type: string
                      browse_url:
                        type: string
                      docs_url:
                        type: string
                      mcp_url:
                        type: string
                    required:
                      - name
                      - description
                      - browse_url
                      - docs_url
                      - mcp_url
                required:
                  - slug
                  - name
                  - description
                  - price_credits_per_call
                  - input_schema
                  - output_schema
                  - success_rate
                  - total_calls
                  - avg_latency_ms
                  - default_timeout_seconds
                  - max_timeout_seconds
                  - invocation_path
                  - invocation_example
                  - sample_output
                  - platform
        '404':
          description: Tool not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  details:
                    nullable: true
                  required:
                    type: number
                  balance:
                    type: number
                required:
                  - error
    post:
      parameters:
        - schema:
            type: string
            description: Tool slug (e.g., 'send-email')
          required: true
          name: slug
          in: path
        - schema:
            type: integer
            minimum: 1
            maximum: 3600
          required: false
          name: timeout_seconds
          in: query
      requestBody:
        content:
          application/json:
            schema:
              type: object
              additionalProperties:
                nullable: true
      responses:
        '200':
          description: Synchronous success
          content:
            application/json:
              schema:
                type: object
                properties:
                  job_id:
                    type: string
                  status:
                    type: string
                    enum:
                      - success
                  output:
                    nullable: true
                  latency_ms:
                    type: number
                  credits_used:
                    type: number
                  credits_remaining:
                    type: number
                required:
                  - job_id
                  - status
                  - latency_ms
                  - credits_used
                  - credits_remaining
        '202':
          description: Async job started
          content:
            application/json:
              schema:
                type: object
                properties:
                  job_id:
                    type: string
                  status:
                    type: string
                    enum:
                      - pending
                  poll_url:
                    type: string
                  credits_reserved:
                    type: number
                  credits_remaining:
                    type: number
                required:
                  - job_id
                  - status
                  - poll_url
                  - credits_reserved
                  - credits_remaining
        '400':
          description: Invalid input
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  details:
                    nullable: true
                  required:
                    type: number
                  balance:
                    type: number
                required:
                  - error
        '402':
          description: Insufficient credits
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  details:
                    nullable: true
                  required:
                    type: number
                  balance:
                    type: number
                required:
                  - error
        '404':
          description: Tool not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  details:
                    nullable: true
                  required:
                    type: number
                  balance:
                    type: number
                required:
                  - error
        '502':
          description: Tool execution failed
          content:
            application/json:
              schema:
                type: object
                properties:
                  job_id:
                    type: string
                  status:
                    type: string
                    enum:
                      - failed
                  error:
                    type: string
                  latency_ms:
                    type: number
                  credits_used:
                    type: number
                  credits_remaining:
                    type: number
                required:
                  - job_id
                  - status
                  - error
                  - latency_ms
                  - credits_used
                  - credits_remaining
  /api/tools/{username}/{slug}:
    get:
      parameters:
        - schema:
            type: string
            description: Owner username (ignored, kept for backwards compatibility)
          required: true
          name: username
          in: path
        - schema:
            type: string
            description: Tool slug (e.g., 'send-email')
          required: true
          name: slug
          in: path
      responses:
        '200':
          description: Tool details
          content:
            application/json:
              schema:
                type: object
                properties:
                  slug:
                    type: string
                  name:
                    type: string
                  description:
                    type: string
                  price_credits_per_call:
                    type: number
                  input_schema:
                    type: object
                    additionalProperties:
                      nullable: true
                  output_schema:
                    type: object
                    additionalProperties:
                      nullable: true
                  owner_name:
                    type: string
                    nullable: true
                  owner_username:
                    type: string
                    nullable: true
                  success_rate:
                    type: number
                    nullable: true
                  total_calls:
                    type: number
                    nullable: true
                  avg_latency_ms:
                    type: number
                    nullable: true
                  default_timeout_seconds:
                    type: number
                    nullable: true
                  max_timeout_seconds:
                    type: number
                    nullable: true
                  invocation_path:
                    type: string
                  invocation_example:
                    type: object
                    properties:
                      method:
                        type: string
                      url:
                        type: string
                      headers:
                        type: object
                        additionalProperties:
                          type: string
                      body:
                        type: object
                        additionalProperties:
                          nullable: true
                    required:
                      - method
                      - url
                      - headers
                      - body
                  sample_output:
                    type: object
                    properties:
                      job_id:
                        type: string
                      status:
                        type: string
                      output:
                        nullable: true
                      credits_used:
                        type: number
                    required:
                      - job_id
                      - status
                      - credits_used
                  platform:
                    type: object
                    properties:
                      name:
                        type: string
                      description:
                        type: string
                      browse_url:
                        type: string
                      docs_url:
                        type: string
                      mcp_url:
                        type: string
                    required:
                      - name
                      - description
                      - browse_url
                      - docs_url
                      - mcp_url
                required:
                  - slug
                  - name
                  - description
                  - price_credits_per_call
                  - input_schema
                  - output_schema
                  - success_rate
                  - total_calls
                  - avg_latency_ms
                  - default_timeout_seconds
                  - max_timeout_seconds
                  - invocation_path
                  - invocation_example
                  - sample_output
                  - platform
        '404':
          description: Tool not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  details:
                    nullable: true
                  required:
                    type: number
                  balance:
                    type: number
                required:
                  - error
    post:
      parameters:
        - schema:
            type: string
            description: Owner username (ignored, kept for backwards compatibility)
          required: true
          name: username
          in: path
        - schema:
            type: string
            description: Tool slug (e.g., 'send-email')
          required: true
          name: slug
          in: path
        - schema:
            type: integer
            minimum: 1
            maximum: 3600
          required: false
          name: timeout_seconds
          in: query
      requestBody:
        content:
          application/json:
            schema:
              type: object
              additionalProperties:
                nullable: true
      responses:
        '200':
          description: Synchronous success
          content:
            application/json:
              schema:
                type: object
                properties:
                  job_id:
                    type: string
                  status:
                    type: string
                    enum:
                      - success
                  output:
                    nullable: true
                  latency_ms:
                    type: number
                  credits_used:
                    type: number
                  credits_remaining:
                    type: number
                required:
                  - job_id
                  - status
                  - latency_ms
                  - credits_used
                  - credits_remaining
        '202':
          description: Async job started
          content:
            application/json:
              schema:
                type: object
                properties:
                  job_id:
                    type: string
                  status:
                    type: string
                    enum:
                      - pending
                  poll_url:
                    type: string
                  credits_reserved:
                    type: number
                  credits_remaining:
                    type: number
                required:
                  - job_id
                  - status
                  - poll_url
                  - credits_reserved
                  - credits_remaining
        '400':
          description: Invalid input
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  details:
                    nullable: true
                  required:
                    type: number
                  balance:
                    type: number
                required:
                  - error
        '402':
          description: Insufficient credits
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  details:
                    nullable: true
                  required:
                    type: number
                  balance:
                    type: number
                required:
                  - error
        '404':
          description: Tool not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  details:
                    nullable: true
                  required:
                    type: number
                  balance:
                    type: number
                required:
                  - error
        '502':
          description: Tool execution failed
          content:
            application/json:
              schema:
                type: object
                properties:
                  job_id:
                    type: string
                  status:
                    type: string
                    enum:
                      - failed
                  error:
                    type: string
                  latency_ms:
                    type: number
                  credits_used:
                    type: number
                  credits_remaining:
                    type: number
                required:
                  - job_id
                  - status
                  - error
                  - latency_ms
                  - credits_used
                  - credits_remaining
  /api/jobs/{job_id}:
    get:
      parameters:
        - schema:
            type: string
            description: Job ID
          required: true
          name: job_id
          in: path
      responses:
        '200':
          description: Job details
          content:
            application/json:
              schema:
                type: object
                properties:
                  job_id:
                    type: string
                  tool_id:
                    type: string
                  status:
                    type: string
                  output:
                    nullable: true
                  error:
                    type: string
                  latency_ms:
                    type: number
                    nullable: true
                  credits_used:
                    type: number
                  credits_remaining:
                    type: number
                  created_at:
                    type: string
                    nullable: true
                  completed_at:
                    type: string
                    nullable: true
                required:
                  - job_id
                  - tool_id
                  - status
                  - latency_ms
                  - credits_used
                  - credits_remaining
                  - created_at
                  - completed_at
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                required:
                  - error
        '404':
          description: Job not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                required:
                  - error
  /api/my/tools:
    get:
      responses:
        '200':
          description: User's tools
          content:
            application/json:
              schema:
                type: object
                properties:
                  tools:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                        owner_id:
                          type: string
                        name:
                          type: string
                        slug:
                          type: string
                        description:
                          type: string
                        endpoint_url:
                          type: string
                        endpoint_secret:
                          type: string
                          nullable: true
                        input_schema:
                          type: object
                          additionalProperties:
                            nullable: true
                        output_schema:
                          type: object
                          additionalProperties:
                            nullable: true
                        price_credits_per_call:
                          type: number
                        default_timeout_seconds:
                          type: number
                          nullable: true
                        max_timeout_seconds:
                          type: number
                          nullable: true
                        is_active:
                          type: number
                          nullable: true
                        is_public:
                          type: number
                          nullable: true
                        created_at:
                          type: string
                          nullable: true
                        updated_at:
                          type: string
                          nullable: true
                      required:
                        - id
                        - owner_id
                        - name
                        - slug
                        - description
                        - endpoint_url
                        - endpoint_secret
                        - input_schema
                        - output_schema
                        - price_credits_per_call
                        - default_timeout_seconds
                        - max_timeout_seconds
                        - is_active
                        - is_public
                        - created_at
                        - updated_at
                required:
                  - tools
    post:
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 100
                slug:
                  type: string
                  minLength: 1
                  maxLength: 100
                  pattern: ^[a-z0-9-]+$
                description:
                  type: string
                  minLength: 1
                  maxLength: 2000
                endpoint_url:
                  type: string
                  format: uri
                endpoint_secret:
                  type: string
                input_schema:
                  type: object
                  additionalProperties:
                    nullable: true
                output_schema:
                  type: object
                  additionalProperties:
                    nullable: true
                price_credits_per_call:
                  type: integer
                  minimum: 1
                default_timeout_seconds:
                  type: integer
                  minimum: 1
                  maximum: 600
                  default: 60
                max_timeout_seconds:
                  type: integer
                  minimum: 1
                  maximum: 600
                  default: 600
                is_public:
                  type: integer
                  minimum: 0
                  maximum: 1
                  default: 1
              required:
                - name
                - slug
                - description
                - endpoint_url
                - input_schema
                - output_schema
                - price_credits_per_call
      responses:
        '201':
          description: Tool created
          content:
            application/json:
              schema:
                type: object
                properties:
                  slug:
                    type: string
                required:
                  - slug
        '400':
          description: Invalid input
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  details:
                    nullable: true
                required:
                  - error
        '403':
          description: Provider access required
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  details:
                    nullable: true
                required:
                  - error
        '409':
          description: Slug already taken
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  details:
                    nullable: true
                required:
                  - error
  /api/my/tools/{slug}:
    put:
      parameters:
        - schema:
            type: string
            description: Tool slug
          required: true
          name: slug
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 100
                description:
                  type: string
                  minLength: 1
                  maxLength: 2000
                endpoint_url:
                  type: string
                  format: uri
                endpoint_secret:
                  type: string
                input_schema:
                  type: object
                  additionalProperties:
                    nullable: true
                output_schema:
                  type: object
                  additionalProperties:
                    nullable: true
                price_credits_per_call:
                  type: integer
                  minimum: 1
                default_timeout_seconds:
                  type: integer
                  minimum: 1
                  maximum: 600
                max_timeout_seconds:
                  type: integer
                  minimum: 1
                  maximum: 600
                is_public:
                  type: integer
                  minimum: 0
                  maximum: 1
      responses:
        '200':
          description: Tool updated
          content:
            application/json:
              schema:
                type: object
                properties:
                  slug:
                    type: string
                  updated:
                    type: boolean
                required:
                  - slug
                  - updated
        '400':
          description: Invalid input
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  details:
                    nullable: true
                required:
                  - error
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  details:
                    nullable: true
                required:
                  - error
        '404':
          description: Tool not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  details:
                    nullable: true
                required:
                  - error
    delete:
      parameters:
        - schema:
            type: string
            description: Tool slug
          required: true
          name: slug
          in: path
      responses:
        '200':
          description: Tool deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  slug:
                    type: string
                  deleted:
                    type: boolean
                required:
                  - slug
                  - deleted
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  details:
                    nullable: true
                required:
                  - error
        '404':
          description: Tool not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  details:
                    nullable: true
                required:
                  - error
  /api/my/balance:
    get:
      responses:
        '200':
          description: Current balance
          content:
            application/json:
              schema:
                type: object
                properties:
                  balance_credits:
                    type: number
                  pending_payout_credits:
                    type: number
                  cleared_payout_credits:
                    type: number
                required:
                  - balance_credits
                  - pending_payout_credits
                  - cleared_payout_credits
  /api/my/transactions:
    get:
      responses:
        '200':
          description: Transaction history
          content:
            application/json:
              schema:
                type: object
                properties:
                  transactions:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                        user_id:
                          type: string
                        amount_credits:
                          type: number
                        type:
                          type: string
                        reference_id:
                          type: string
                          nullable: true
                        balance_after_credits:
                          type: number
                        description:
                          type: string
                          nullable: true
                        created_at:
                          type: string
                          nullable: true
                      required:
                        - id
                        - user_id
                        - amount_credits
                        - type
                        - reference_id
                        - balance_after_credits
                        - description
                        - created_at
                required:
                  - transactions
  /api/my/topup:
    post:
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                amount_credits:
                  type: integer
                  minimum: 100000
                  maximum: 5000000
              required:
                - amount_credits
      responses:
        '200':
          description: Checkout session created
          content:
            application/json:
              schema:
                type: object
                properties:
                  checkout_url:
                    type: string
                  session_id:
                    type: string
                required:
                  - checkout_url
                  - session_id
  /api/my/profile:
    get:
      responses:
        '200':
          description: User profile
          content:
            application/json:
              schema:
                type: object
                properties:
                  name:
                    type: string
                    nullable: true
                  email:
                    type: string
                  username:
                    type: string
                    nullable: true
                  is_provider:
                    type: boolean
                required:
                  - name
                  - email
                  - username
                  - is_provider
    put:
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 100
                username:
                  type: string
                  minLength: 3
                  maxLength: 30
      responses:
        '200':
          description: Updated profile
          content:
            application/json:
              schema:
                type: object
                properties:
                  name:
                    type: string
                    nullable: true
                  email:
                    type: string
                  username:
                    type: string
                    nullable: true
                  is_provider:
                    type: boolean
                required:
                  - name
                  - email
                  - username
                  - is_provider
  /api/my/api-keys:
    get:
      responses:
        '200':
          description: List of API keys
          content:
            application/json:
              schema:
                type: object
                properties:
                  keys:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                        name:
                          type: string
                        key_prefix:
                          type: string
                        last_used_at:
                          type: string
                          nullable: true
                        created_at:
                          type: string
                          nullable: true
                      required:
                        - id
                        - name
                        - key_prefix
                        - last_used_at
                        - created_at
                required:
                  - keys
    post:
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 100
              required:
                - name
      responses:
        '201':
          description: API key created
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                  name:
                    type: string
                  api_key:
                    type: string
                  key_prefix:
                    type: string
                required:
                  - id
                  - name
                  - api_key
                  - key_prefix
  /api/my/api-keys/:key_id:
    delete:
      parameters:
        - schema:
            type: string
          required: true
          name: key_id
          in: path
      responses:
        '200':
          description: Key deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  deleted:
                    type: boolean
                required:
                  - deleted
        '404':
          description: Key not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                required:
                  - error
  /api/my/pending-key:
    get:
      responses:
        '200':
          description: Pending API key
          content:
            application/json:
              schema:
                type: object
                properties:
                  api_key:
                    type: string
                required:
                  - api_key
        '404':
          description: No pending key
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                required:
                  - error
  /api/my/auto-topup:
    get:
      responses:
        '200':
          description: Auto-topup settings
          content:
            application/json:
              schema:
                type: object
                properties:
                  enabled:
                    type: boolean
                  threshold_credits:
                    type: number
                    nullable: true
                  amount_credits:
                    type: number
                    nullable: true
                  has_payment_method:
                    type: boolean
                required:
                  - enabled
                  - threshold_credits
                  - amount_credits
                  - has_payment_method
    put:
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                enabled:
                  type: boolean
                threshold_credits:
                  type: integer
                  minimum: 0
                  maximum: 1000000
                amount_credits:
                  type: integer
                  minimum: 100000
                  maximum: 5000000
              required:
                - enabled
      responses:
        '200':
          description: Updated settings
          content:
            application/json:
              schema:
                type: object
                properties:
                  enabled:
                    type: boolean
                  threshold_credits:
                    type: number
                    nullable: true
                  amount_credits:
                    type: number
                    nullable: true
                  has_payment_method:
                    type: boolean
                required:
                  - enabled
                  - threshold_credits
                  - amount_credits
                  - has_payment_method
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                required:
                  - error
  /api/my/payment-methods:
    get:
      responses:
        '200':
          description: List of payment methods
          content:
            application/json:
              schema:
                type: object
                properties:
                  payment_methods:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                        brand:
                          type: string
                        last4:
                          type: string
                        exp_month:
                          type: number
                        exp_year:
                          type: number
                        is_default:
                          type: boolean
                      required:
                        - id
                        - brand
                        - last4
                        - exp_month
                        - exp_year
                        - is_default
                required:
                  - payment_methods
  /api/my/payment-methods/:payment_method_id:
    delete:
      parameters:
        - schema:
            type: string
          required: true
          name: payment_method_id
          in: path
      responses:
        '200':
          description: Payment method deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  deleted:
                    type: boolean
                required:
                  - deleted
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                required:
                  - error
        '404':
          description: Not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                required:
                  - error
  /api/my/connect/status:
    get:
      responses:
        '200':
          description: Connect account status
          content:
            application/json:
              schema:
                type: object
                properties:
                  connected:
                    type: boolean
                  payouts_enabled:
                    type: boolean
                  details_submitted:
                    type: boolean
                  account_id:
                    type: string
                    nullable: true
                required:
                  - connected
                  - payouts_enabled
                  - details_submitted
                  - account_id
  /api/my/connect/onboard:
    post:
      responses:
        '200':
          description: Onboarding URL
          content:
            application/json:
              schema:
                type: object
                properties:
                  onboarding_url:
                    type: string
                required:
                  - onboarding_url
  /api/my/connect/refresh:
    post:
      responses:
        '200':
          description: New onboarding URL
          content:
            application/json:
              schema:
                type: object
                properties:
                  onboarding_url:
                    type: string
                required:
                  - onboarding_url
        '400':
          description: No Connect account
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                required:
                  - error
  /api/my/earnings-schedule:
    get:
      responses:
        '200':
          description: Pending earnings schedule
          content:
            application/json:
              schema:
                type: object
                properties:
                  buckets:
                    type: array
                    items:
                      type: object
                      properties:
                        clears_date:
                          type: string
                        amount_credits:
                          type: number
                      required:
                        - clears_date
                        - amount_credits
                  total_pending_credits:
                    type: number
                  total_cleared_credits:
                    type: number
                required:
                  - buckets
                  - total_pending_credits
                  - total_cleared_credits
  /api/my/payout-eligibility:
    get:
      responses:
        '200':
          description: Payout eligibility
          content:
            application/json:
              schema:
                type: object
                properties:
                  eligible:
                    type: boolean
                  reason:
                    type: string
                  pending_amount_credits:
                    type: number
                  cleared_amount_credits:
                    type: number
                  min_payout_credits:
                    type: number
                required:
                  - eligible
                  - pending_amount_credits
                  - cleared_amount_credits
                  - min_payout_credits
  /api/my/payouts:
    get:
      responses:
        '200':
          description: Payout history
          content:
            application/json:
              schema:
                type: object
                properties:
                  payouts:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                        gross_amount_credits:
                          type: number
                        platform_fee_credits:
                          type: number
                        net_amount_credits:
                          type: number
                        status:
                          type: string
                          nullable: true
                        created_at:
                          type: string
                          nullable: true
                        completed_at:
                          type: string
                          nullable: true
                      required:
                        - id
                        - gross_amount_credits
                        - platform_fee_credits
                        - net_amount_credits
                        - status
                        - created_at
                        - completed_at
                required:
                  - payouts
    post:
      responses:
        '200':
          description: Payout created
          content:
            application/json:
              schema:
                type: object
                properties:
                  payout_id:
                    type: string
                  gross_amount_credits:
                    type: number
                  platform_fee_credits:
                    type: number
                  net_amount_credits:
                    type: number
                required:
                  - payout_id
                  - gross_amount_credits
                  - platform_fee_credits
                  - net_amount_credits
        '400':
          description: Payout failed
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                required:
                  - error
  /api/my/provider-waitlist:
    get:
      responses:
        '200':
          description: Provider waitlist status
          content:
            application/json:
              schema:
                type: object
                properties:
                  is_provider:
                    type: boolean
                  on_waitlist:
                    type: boolean
                required:
                  - is_provider
                  - on_waitlist
    post:
      responses:
        '200':
          description: Joined waitlist
          content:
            application/json:
              schema:
                type: object
                properties:
                  joined:
                    type: boolean
                required:
                  - joined
        '409':
          description: Already on waitlist
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                required:
                  - error
  /api/callbacks/{job_id}:
    post:
      parameters:
        - schema:
            type: string
            description: Job ID to complete
          required: true
          name: job_id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                status:
                  type: string
                  enum:
                    - success
                    - failed
                status_code:
                  type: number
                output:
                  nullable: true
                error:
                  type: string
              required:
                - status
      responses:
        '200':
          description: Callback accepted
          content:
            application/json:
              schema:
                type: object
                properties:
                  received:
                    type: boolean
                required:
                  - received
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                required:
                  - error
        '401':
          description: Invalid token or signature
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                required:
                  - error
        '404':
          description: Job not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                required:
                  - error
