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

# OpenAI Format - Tool Calling Chat

> - Generic Chat Completions API reference with tool calling for all OpenAI-compatible models
- Supports Function Calling: define tools the model can invoke
- Structured output: supports JSON Object / JSON Schema format
- Multimodal input: supports text + image mixed input
- Supports streaming and non-streaming responses




## OpenAPI

````yaml openapi/en/openai-format-chat-completions.json POST /v1/chat/completions
openapi: 3.1.0
info:
  title: OpenAI Format - Tool Calling Chat
  version: '1.0'
servers:
  - url: https://api.aihubmax.com
security:
  - BearerAuth: []
paths:
  /v1/chat/completions:
    post:
      tags:
        - Text Series > OpenAI Format
      summary: OpenAI Format - Tool Calling Chat
      description: >
        - Generic Chat Completions API reference with tool calling for all
        OpenAI-compatible models

        - Supports Function Calling: define tools the model can invoke

        - Structured output: supports JSON Object / JSON Schema format

        - Multimodal input: supports text + image mixed input

        - Supports streaming and non-streaming responses
      operationId: openai-format-chat-completions
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionRequest'
            examples:
              single-turn:
                summary: Single Turn
                description: Basic single-turn Q&A
                value:
                  model: gpt-5.4
                  messages:
                    - role: user
                      content: Write a quicksort algorithm in Python
              multi-turn:
                summary: Multi-turn
                description: Multi-turn conversation with context
                value:
                  model: gpt-5.4
                  messages:
                    - role: system
                      content: You are a senior backend engineer
                    - role: user
                      content: >-
                        My API response time increased from 200ms to 2s. What
                        could be the cause?
                    - role: assistant
                      content: >-
                        A significant increase in response time usually has
                        several common causes:

                        1. Slow database queries (missing indexes, data growth)

                        2. External service call timeouts

                        3. Memory leaks causing frequent GC

                        4. Increased network latency


                        Can you provide more details? Is it all endpoints or
                        specific ones?
                    - role: user
                      content: Only the user list query endpoint is slow
              streaming:
                summary: Streaming
                description: Enable streaming for real-time content generation
                value:
                  model: gpt-5.4
                  messages:
                    - role: user
                      content: Explain the TCP three-way handshake in detail
                  stream: true
              with-image:
                summary: With Image
                description: Send an image for model analysis (vision)
                value:
                  model: gpt-5.4
                  messages:
                    - role: user
                      content:
                        - type: text
                          text: >-
                            What issues do you see in this architecture diagram?
                            Point out potential performance bottlenecks
                        - type: image_url
                          image_url:
                            url: >-
                              https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg
              tool-calling-weather:
                summary: Tool Use - Weather
                description: >-
                  Let the model call a weather tool to get real-time weather
                  info
                value:
                  model: gpt-5.4
                  messages:
                    - role: user
                      content: >-
                        What's the weather like in Tokyo today? Is it good for
                        outdoor running?
                  tools:
                    - type: function
                      function:
                        name: get_weather
                        description: Get current weather for a specified city
                        parameters:
                          type: object
                          properties:
                            city:
                              type: string
                              description: City name
                            unit:
                              type: string
                              enum:
                                - celsius
                                - fahrenheit
                              description: Temperature unit
                          required:
                            - city
              tool-calling-search:
                summary: Tool Use - Web Search
                description: Let the model call a search tool to find latest information
                value:
                  model: gpt-5.4
                  messages:
                    - role: user
                      content: Search for the latest news about GPT-5 release
                  tools:
                    - type: function
                      function:
                        name: web_search
                        description: Search the internet for information
                        parameters:
                          type: object
                          properties:
                            query:
                              type: string
                              description: Search keywords
                            num_results:
                              type: integer
                              description: Number of results to return
                              default: 5
                          required:
                            - query
              tool-calling-database:
                summary: Tool Use - Data Query
                description: Let the model call a data query tool to retrieve business data
                value:
                  model: gpt-5.4
                  messages:
                    - role: user
                      content: Find the top 5 products by sales last month
                  tools:
                    - type: function
                      function:
                        name: query_database
                        description: Query the business database for data
                        parameters:
                          type: object
                          properties:
                            query:
                              type: string
                              description: SQL query
                            database:
                              type: string
                              enum:
                                - sales
                                - inventory
                                - users
                              description: Target database
                          required:
                            - query
                            - database
      responses:
        '200':
          $ref: '#/components/responses/ChatCompletionSuccess'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          $ref: '#/components/responses/PaymentRequired'
        '403':
          $ref: '#/components/responses/Forbidden'
        '429':
          $ref: '#/components/responses/TooManyRequests'
        '500':
          $ref: '#/components/responses/InternalServerError'
components:
  schemas:
    ChatCompletionRequest:
      type: object
      required:
        - model
        - messages
      properties:
        model:
          type: string
          description: Model name, e.g. gpt-5.4, deepseek-chat, etc.
          example: gpt-5.4
        messages:
          type: array
          description: List of messages in the conversation
          items:
            type: object
            required:
              - role
              - content
            properties:
              role:
                type: string
                description: Role of the message sender
                enum:
                  - system
                  - user
                  - assistant
                  - tool
              content:
                type: string
                description: Content of the message (string or array of content parts)
        stream:
          type: boolean
          description: Whether to stream the response
          default: false
        temperature:
          type: number
          description: Sampling temperature (0-2)
          minimum: 0
          maximum: 2
        max_tokens:
          type: integer
          description: Maximum number of tokens to generate
        top_p:
          type: number
          description: Nucleus sampling parameter (0-1)
          minimum: 0
          maximum: 1
        frequency_penalty:
          type: number
          description: >-
            Penalize new tokens based on their frequency in the text so far (-2
            to 2)
          minimum: -2
          maximum: 2
        presence_penalty:
          type: number
          description: >-
            Penalize new tokens based on whether they appear in the text so far
            (-2 to 2)
          minimum: -2
          maximum: 2
        tools:
          type: array
          description: A list of tools the model may call
          items:
            type: object
            properties:
              type:
                type: string
                enum:
                  - function
              function:
                type: object
                properties:
                  name:
                    type: string
                    description: The name of the function to call
                  description:
                    type: string
                    description: A description of what the function does
                  parameters:
                    type: object
                    description: >-
                      The parameters the function accepts, described as a JSON
                      Schema object
                required:
                  - name
        tool_choice:
          description: Controls which tool is called by the model
          oneOf:
            - type: string
              enum:
                - none
                - auto
                - required
            - type: object
              properties:
                type:
                  type: string
                  enum:
                    - function
                function:
                  type: object
                  properties:
                    name:
                      type: string
                  required:
                    - name
        response_format:
          type: object
          description: An object specifying the format that the model must output
          properties:
            type:
              type: string
              description: The type of response format
              enum:
                - text
                - json_object
                - json_schema
        stop:
          description: Up to 4 sequences where the API will stop generating further tokens
          oneOf:
            - type: string
            - type: array
              items:
                type: string
        'n':
          type: integer
          description: How many chat completion choices to generate for each input message
    ChatCompletionResponse:
      type: object
      properties:
        id:
          type: string
          description: Unique completion ID
          example: chatcmpl-abc123
        object:
          type: string
          description: Object type
          enum:
            - chat.completion
        created:
          type: integer
          description: Creation timestamp
          example: 1757165031
        model:
          type: string
          description: Model used
        choices:
          type: array
          items:
            type: object
            properties:
              index:
                type: integer
                description: Choice index
                example: 0
              message:
                type: object
                properties:
                  role:
                    type: string
                    example: assistant
                  content:
                    type: string
                    example: Hello! How can I help you today?
              finish_reason:
                type: string
                description: Reason the generation stopped
                enum:
                  - stop
                  - length
                  - content_filter
                  - tool_calls
                example: stop
        usage:
          type: object
          properties:
            prompt_tokens:
              type: integer
              description: Number of tokens in the prompt
              example: 20
            completion_tokens:
              type: integer
              description: Number of tokens in the completion
              example: 50
            total_tokens:
              type: integer
              description: Total number of tokens used
              example: 70
    ErrorResponse400:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: Invalid request parameters
            type:
              type: string
              example: invalid_request_error
    ErrorResponse401:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: Invalid API key
            type:
              type: string
              example: authentication_error
    ErrorResponse403:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: Access denied
            type:
              type: string
              example: permission_error
    ErrorResponse429:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: Rate limit exceeded
            type:
              type: string
              example: rate_limit_error
    ErrorResponse500:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: Internal server error
            type:
              type: string
              example: server_error
  responses:
    ChatCompletionSuccess:
      description: Chat completion response
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ChatCompletionResponse'
    BadRequest:
      description: Bad Request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse400'
    Unauthorized:
      description: Unauthorized
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse401'
    PaymentRequired:
      description: Insufficient balance
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse400'
    Forbidden:
      description: Forbidden
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse403'
    TooManyRequests:
      description: Too Many Requests
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse429'
    InternalServerError:
      description: Internal Server Error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse500'
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: |
        ## All APIs require Bearer Token authentication ##

        Add to request header:

        `Authorization: Bearer YOUR_API_KEY`

````