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

# Chat Completion

> Create a chat completion using the specified model. Supports multi-turn conversation, streaming, and a variety of generation parameters.



## OpenAPI

````yaml post /v1/chat/completions
openapi: 3.1.0
info:
  title: General Chat API
  version: 1.0.0
  description: >-
    Unified chat API interface supporting multiple text-generation models.
    Compatible with OpenAI Chat Completions API format.
servers:
  - url: https://apiif.com
    description: Primary API server
security:
  - bearerAuth: []
paths:
  /v1/chat/completions:
    post:
      summary: Chat Completion
      description: >-
        Create a chat completion using the specified model. Supports multi-turn
        conversation, streaming, and a variety of generation parameters.
      operationId: createChatCompletion
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                model:
                  type: string
                  description: Model name (e.g. gpt-4o, gpt-5, claude-opus-4-1-20250805).
                messages:
                  type: array
                  description: List of conversation messages.
                  items:
                    type: object
                    properties:
                      role:
                        type: string
                        enum:
                          - user
                          - assistant
                          - system
                        default: user
                      content:
                        type: string
                    required:
                      - role
                      - content
                temperature:
                  type: number
                  description: 'Controls output randomness (0-2). Default: 1.0'
                max_tokens:
                  type: integer
                  description: Maximum number of tokens to generate.
                stream:
                  type: boolean
                  description: 'Whether to use streaming output (SSE). Default: false'
                top_p:
                  type: number
                  description: 'Nucleus sampling parameter (0-1). Default: 1.0'
                frequency_penalty:
                  type: number
                  description: 'Frequency penalty (-2.0 to 2.0). Default: 0'
                presence_penalty:
                  type: number
                  description: 'Presence penalty (-2.0 to 2.0). Default: 0'
                stop:
                  oneOf:
                    - type: string
                    - type: array
                      items:
                        type: string
                  description: Stop sequences (up to 4).
                'n':
                  type: integer
                  description: 'Number of completions to generate. Default: 1'
              required:
                - model
                - messages
            examples:
              basic:
                summary: Basic conversation
                value:
                  model: gpt-4o
                  messages:
                    - role: user
                      content: Hello
      responses:
        '200':
          description: Successful response with a chat completion.
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: integer
                  data:
                    type: object
                    properties:
                      id:
                        type: string
                      object:
                        type: string
                        example: chat.completion
                      created:
                        type: integer
                      model:
                        type: string
                      choices:
                        type: array
                        items:
                          type: object
                          properties:
                            index:
                              type: integer
                            message:
                              type: object
                              properties:
                                role:
                                  type: string
                                  example: assistant
                                content:
                                  type: string
                            finish_reason:
                              type: string
                      usage:
                        type: object
                        properties:
                          prompt_tokens:
                            type: integer
                          completion_tokens:
                            type: integer
                          total_tokens:
                            type: integer
              examples:
                success:
                  value:
                    code: 200
                    data:
                      id: chatcmpl-9876543210
                      object: chat.completion
                      created: 1677652288
                      model: gpt-4o
                      choices:
                        - index: 0
                          message:
                            role: assistant
                            content: >-
                              The history of artificial intelligence (AI) dates
                              back to the 1950s...
                          finish_reason: stop
                      usage:
                        prompt_tokens: 28
                        completion_tokens: 320
                        total_tokens: 348
        '400':
          description: Invalid request parameters
          content:
            application/json:
              examples:
                bad_request:
                  value:
                    error:
                      code: 400
                      message: Invalid request parameters
                      type: invalid_request_error
        '401':
          description: Authentication failed
          content:
            application/json:
              examples:
                unauthorized:
                  value:
                    error:
                      code: 401
                      message: Authentication failed, please check your API key
                      type: authentication_error
        '402':
          description: Payment required / insufficient balance
          content:
            application/json:
              examples:
                payment_required:
                  value:
                    error:
                      code: 402
                      message: Insufficient account balance, please recharge
                      type: payment_required
        '403':
          description: Access forbidden
          content:
            application/json:
              examples:
                forbidden:
                  value:
                    error:
                      code: 403
                      message: >-
                        Access forbidden, you don't have permission to access
                        this resource
                      type: permission_error
        '429':
          description: Rate limit exceeded
          content:
            application/json:
              examples:
                rate_limited:
                  value:
                    error:
                      code: 429
                      message: Too many requests, please try again later
                      type: rate_limit_error
        '500':
          description: Internal server error
          content:
            application/json:
              examples:
                server_error:
                  value:
                    error:
                      code: 500
                      message: Internal server error, please try again later
                      type: server_error
        '502':
          description: Bad gateway
          content:
            application/json:
              examples:
                bad_gateway:
                  value:
                    error:
                      code: 502
                      message: Bad gateway, service temporarily unavailable
                      type: bad_gateway
      security:
        - bearerAuth: []
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: 'All endpoints require `Authorization: Bearer YOUR_API_KEY`.'

````