> ## 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.

# General chat endpoint

> Send messages to OpenAI and receive AI responses.

**Note**: The AI model is configured server-side and cannot be specified in the request.
The `max_tokens` parameter is capped to the server-configured limit.

**x402 Payment Required**: This endpoint requires payment via the x402 protocol (version 1).
- First request: Returns 402 with payment requirements in `x-payment` header
- Second request: Include `X-Payment` header with signed payment authorization




## OpenAPI

````yaml post /llm/chat
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:
  /llm/chat:
    post:
      tags:
        - LLM
      summary: General chat endpoint
      description: >
        Send messages to OpenAI and receive AI responses.


        **Note**: The AI model is configured server-side and cannot be specified
        in the request.

        The `max_tokens` parameter is capped to the server-configured limit.


        **x402 Payment Required**: This endpoint requires payment via the x402
        protocol (version 1).

        - First request: Returns 402 with payment requirements in `x-payment`
        header

        - Second request: Include `X-Payment` header with signed payment
        authorization
      parameters:
        - in: header
          name: X-Payment
          schema:
            type: string
          description: >-
            x402 v1 payment authorization header (base64-encoded JSON). Include
            on second request after receiving 402.
          required: false
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - messages
              properties:
                messages:
                  type: array
                  description: Array of chat messages
                  items:
                    type: object
                    properties:
                      role:
                        type: string
                        enum:
                          - system
                          - user
                          - assistant
                      content:
                        type: string
                temperature:
                  type: number
                  default: 0.7
                  minimum: 0
                  maximum: 2
                  description: >-
                    Sampling temperature (0-2). Controls randomness in
                    responses.
                max_tokens:
                  type: integer
                  description: >-
                    Maximum tokens in response (will be capped to
                    server-configured limit)
                  example: 500
            example:
              messages:
                - role: system
                  content: You are a helpful assistant
                - role: user
                  content: Hello, how are you?
              temperature: 0.7
      responses:
        '200':
          description: Chat successful
          content:
            application/json:
              schema:
                type: object
                properties:
                  response:
                    type: string
                    description: AI-generated response
                    example: >-
                      I'm doing well, thank you for asking! How can I help you
                      today?
                  model:
                    type: string
                    description: OpenAI model used (server-configured)
                    example: gpt-4o-mini-2024-07-18
        '400':
          description: Bad request - missing or invalid messages
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: Messages field is required and must be an array
        '402':
          description: Payment Required - x402 v1 payment needed
          headers:
            x-payment:
              schema:
                type: string
              description: >-
                Base64-encoded x402 v1 payment requirements (includes network,
                amount, payTo address, etc.)
          content:
            application/json:
              schema:
                type: object
                properties:
                  x402Version:
                    type: integer
                    example: 1
                  error:
                    type: string
                    example: Payment Required
                  accepts:
                    type: array
                    items:
                      type: object
                      properties:
                        scheme:
                          type: string
                          example: exact
                        network:
                          type: string
                          example: base
                        payTo:
                          type: string
                        asset:
                          type: string
                        maxAmountRequired:
                          type: string
        '500':
          description: Chat request failed
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    example: Chat request failed
                  message:
                    type: string
        '503':
          description: OpenAI service not configured

````