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

# Execute x402 payment-gated API call

> HTTPayer proxy service for x402 payment-gated API calls.

**Flow:**
1. Proxy detects 402 Payment Required from target API
2. HTTPayer wallet executes payment to target API
3. Proxy retries request with payment proof
4. Returns target API response to client

**Error Handling:**
- 502 Bad Gateway: Target API errors (unreachable, malformed, 5xx)
- 500 Internal Server Error: Proxy configuration errors
- 4xx Pass-through: Client errors from target API
- Timeout detection with configurable limits




## OpenAPI

````yaml post /proxy
openapi: 3.0.0
info:
  title: HTTPayer Proxy API
  version: 1.0.0
  description: >-
    HTTPayer is a payment router for 402 response codes and the x402 Protocol.
    Users can access APIs that use the x402 standard through the HTTPayer proxy.
  contact:
    name: HTTPayer Team
    url: https://httpayer.com
servers:
  - url: https://api.httpayer.com
    description: Production server
security: []
tags:
  - name: Relay
    description: Cross-chain payment relay endpoints
  - name: Account
    description: Account balance and limits endpoints
  - name: Webhooks
    description: Async task status and webhooks
  - name: LLM
    description: OpenAI-powered endpoints for translation and chat
  - name: Health
    description: Health check endpoints
paths:
  /proxy:
    post:
      tags:
        - Proxy
      summary: Execute x402 payment-gated API call
      description: |
        HTTPayer proxy service for x402 payment-gated API calls.

        **Flow:**
        1. Proxy detects 402 Payment Required from target API
        2. HTTPayer wallet executes payment to target API
        3. Proxy retries request with payment proof
        4. Returns target API response to client

        **Error Handling:**
        - 502 Bad Gateway: Target API errors (unreachable, malformed, 5xx)
        - 500 Internal Server Error: Proxy configuration errors
        - 4xx Pass-through: Client errors from target API
        - Timeout detection with configurable limits
      parameters:
        - in: header
          name: X-TIMEOUT
          schema:
            type: number
          description: Client timeout in milliseconds (max 120000ms / 2 minutes)
          required: false
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - api_url
                - method
              properties:
                api_url:
                  type: string
                  description: Target API URL to call via proxy
                  example: https://www.x402.org/protected
                method:
                  type: string
                  enum:
                    - GET
                    - POST
                    - PUT
                    - DELETE
                    - PATCH
                  description: HTTP method for target API
                  example: GET
                json:
                  type: object
                  description: >
                    JSON body — serialized and sent with Content-Type:
                    application/json.

                    Mirrors Python requests(json=...) / fetch(body:
                    JSON.stringify(...)).
                  example:
                    city: San Francisco
                data:
                  description: >
                    Form-encoded body when an object, raw string body when a
                    string.

                    Mirrors Python requests(data=...).

                    Object → Content-Type: application/x-www-form-urlencoded.

                    String → passed through as-is; set Content-Type via headers.
                  oneOf:
                    - type: object
                    - type: string
                body:
                  type: string
                  description: >
                    Pre-serialized body string — passed through unchanged,
                    without setting Content-Type.

                    If you pass an object it will be JSON-stringified, but you
                    must manually set

                    Content-Type: application/json via headers. Use json instead
                    for automatic Content-Type handling.
                payload:
                  type: object
                  description: Deprecated alias for json. Use json instead.
                params:
                  type: object
                  description: Query parameters appended to the target URL
                  example:
                    limit: '10'
                    offset: '0'
                headers:
                  type: object
                  description: Custom headers forwarded to the target API
                  example:
                    Accept: application/json
                auth:
                  type: object
                  description: >
                    Basic auth shorthand — converted to Authorization: Basic
                    <base64>.

                    Mirrors Python requests(auth=("user", "pass")).
                  properties:
                    username:
                      type: string
                    password:
                      type: string
                cookies:
                  type: object
                  description: |
                    Cookie shorthand — merged into the Cookie header.
                    Mirrors Python requests(cookies={...}).
                  example:
                    session: abc123
                timeout:
                  type: number
                  description: >-
                    Per-request timeout in seconds (server default applies if
                    omitted; also accepts X-TIMEOUT header in ms)
                  example: 30
      responses:
        '200':
          description: Target API request successful
          content:
            application/json:
              schema:
                type: object
                description: Response from target API (pass-through)
        '400':
          description: Bad request - Invalid parameters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '402':
          description: Payment Required - Insufficient credits or spend limit exceeded
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: Insufficient credits
        '429':
          description: Too Many Requests - Server at capacity
          headers:
            Retry-After:
              description: Seconds to wait before retrying
              schema:
                type: integer
                example: 5
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: Too Many Requests
                  message:
                    type: string
                    example: >-
                      Server is currently processing the maximum number of
                      concurrent requests. Please try again in a moment.
                  details:
                    type: string
                    example: 'Active requests: 100/100'
                  retryAfter:
                    type: integer
                    example: 5
        '500':
          description: Internal Server Error - Proxy configuration error
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: Internal Server Error
                  message:
                    type: string
                    example: The proxy server encountered an internal error
                  details:
                    type: string
        '502':
          description: >
            Bad Gateway - Target API error, unreachable, or refused payment
            after retries.

            When the target API returns 402 after all sync retries, HTTPayer
            returns 502 with

            `message: "Upstream API refused payment after N attempts"`. If
            blockchain polling

            is active, a `webhook_id` field is included — use `GET
            /webhooks/:id` to track

            whether the payment eventually confirmed on-chain. If confirmed,
            credits are charged;

            if not, reserved credits are automatically refunded.
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: Bad Gateway
                  message:
                    type: string
                    example: Upstream API refused payment after 3 attempts
                  details:
                    type: string
                  upstreamStatus:
                    type: number
                    description: HTTP status code from target API (if available)
                  webhook_id:
                    type: string
                    description: >-
                      Webhook ID for tracking async payment detection (present
                      when polling is active)
                    example: 550e8400-e29b-41d4-a716-446655440000
      security:
        - ApiKeyAuth: []
components:
  schemas:
    Error:
      type: object
      properties:
        error:
          type: string
          description: Error message
        details:
          type: string
          description: Additional error details
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: API key for authentication

````