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

# 创建聊天补全

> Creates a chat completion using an OpenAI-compatible request body.

使用 OpenAI 兼容请求体发起多轮对话、文本生成、代码生成或推理任务。


## OpenAPI

````yaml api-reference/openapi.json POST /chat/completions
openapi: 3.1.0
info:
  title: AIOAGI OpenAI-compatible API
  description: >-
    OpenAI-compatible API surface for AIOAGI model access. Endpoint
    availability, model names, and billing rules depend on your account and the
    current control panel configuration.
  version: 1.0.0
servers:
  - url: https://api.aiearth.dev/v1
    description: General API endpoint
  - url: https://api.aiearth.vip/v1
    description: CDN accelerated API endpoint
  - url: https://api-s1.aiearth.dev/v1
    description: Specialized endpoint for account and realtime capabilities
  - url: https://api-s1.aiearth.vip/v1
    description: CDN accelerated specialized endpoint
security:
  - bearerAuth: []
paths:
  /chat/completions:
    post:
      summary: Create chat completion
      description: Creates a chat completion using an OpenAI-compatible request body.
      operationId: createChatCompletion
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionRequest'
            examples:
              basic:
                summary: Basic chat request
                value:
                  model: gpt-4o-mini
                  messages:
                    - role: system
                      content: You are a concise assistant.
                    - role: user
                      content: 用一句话介绍 AIOAGI。
                  temperature: 0.7
      responses:
        '200':
          description: Chat completion response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletionResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
components:
  schemas:
    ChatCompletionRequest:
      type: object
      properties:
        model:
          type: string
          description: Model name available in your AIOAGI account.
        messages:
          type: array
          items:
            $ref: '#/components/schemas/ChatMessage'
        temperature:
          type: number
          minimum: 0
          maximum: 2
          default: 1
        max_tokens:
          type: integer
          minimum: 1
        stream:
          type: boolean
          default: false
      required:
        - model
        - messages
    ChatCompletionResponse:
      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:
                $ref: '#/components/schemas/ChatMessage'
              finish_reason:
                type: string
        usage:
          $ref: '#/components/schemas/Usage'
    ChatMessage:
      type: object
      properties:
        role:
          type: string
          enum:
            - system
            - user
            - assistant
            - tool
        content:
          oneOf:
            - type: string
            - type: array
              items:
                type: object
      required:
        - role
        - content
    Usage:
      type: object
      properties:
        prompt_tokens:
          type: integer
        completion_tokens:
          type: integer
        total_tokens:
          type: integer
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            type:
              type: string
            code:
              type: string
  responses:
    BadRequest:
      description: Invalid request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Unauthorized:
      description: Missing or invalid API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API key

````