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

# Create a chat completion

> Menjalankan inferensi model dalam format OpenAI Chat Completions. Seluruh parameter JSON (termasuk tools, structured outputs, reasoning, dan vision) diteruskan secara transparan ke engine inferensi.

Generates a completion for the supplied conversation.

Set `stream: true` to receive Server-Sent Events. Every response carries a UUID v4 `x-request-id` header for lookup in [Logs](https://console.cerasai.cloud/logs).

Retry `429` and `5xx` responses with exponential backoff and jitter. Prefer `retry-after` when provided. Do not retry `400`, `401`, `402`, or `404`.

A `429` means one of your three per-minute budgets (requests, input tokens, or output tokens) is temporarily exhausted. See [Rate limits](https://docs.cerasai.com/rate-limits.md) for details.


## OpenAPI

````yaml POST /v1/chat/completions
openapi: 3.1.0
info:
  title: CerasAI Inference API
  version: 1.0.0
  description: >-
    API inferensi AI berlatensi rendah yang kompatibel penuh dengan protokol
    OpenAI Chat Completions dan Anthropic Messages.
servers:
  - url: https://api.cerasai.cloud
    description: Production Inference Gateway
security:
  - BearerAuth: []
paths:
  /v1/chat/completions:
    post:
      summary: Buat Chat Completion (OpenAI-compatible)
      description: >-
        Menjalankan inferensi model dalam format OpenAI Chat Completions.
        Seluruh parameter JSON (termasuk tools, structured outputs, reasoning,
        dan vision) diteruskan secara transparan ke engine inferensi.
      operationId: createChatCompletion
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionRequest'
      responses:
        '200':
          description: >-
            Respons inferensi berhasil (JSON atau text/event-stream saat
            stream=true).
          headers:
            x-request-id:
              description: UUID v4 unik untuk melacak permintaan di halaman Logs.
              schema:
                type: string
                format: uuid
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletionResponse'
        '400':
          description: Permintaan tidak valid.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: API key tidak valid atau kedaluwarsa.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '402':
          description: Saldo kredit habis atau batas pengeluaran bulanan tercapai.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '429':
          description: Batas laju RPM/ITPM/OTPM terlampaui.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    ChatCompletionRequest:
      type: object
      required:
        - model
        - messages
      properties:
        model:
          type: string
          example: zai-org/GLM-5.3-Flash
          description: Model ID persis dari endpoint GET /v1/models.
        messages:
          type: array
          items:
            $ref: '#/components/schemas/ChatMessage'
        stream:
          type: boolean
          default: false
          description: Aktifkan Server-Sent Events (SSE) streaming.
        temperature:
          type: number
          minimum: 0
          maximum: 2
          example: 0.7
        top_p:
          type: number
          minimum: 0
          maximum: 1
          example: 1
        max_tokens:
          type: integer
          minimum: 1
          example: 2048
        tools:
          type: array
          items:
            type: object
            additionalProperties: true
          description: Definisi function/tool calling diteruskan apa adanya ke model.
        tool_choice:
          oneOf:
            - type: string
            - type: object
              additionalProperties: true
        response_format:
          type: object
          additionalProperties: true
        stop:
          oneOf:
            - type: string
            - type: array
              items:
                type: string
        seed:
          type: integer
      additionalProperties: true
    ChatCompletionResponse:
      type: object
      properties:
        id:
          type: string
        object:
          type: string
          example: chat.completion
        created:
          type: integer
        model:
          type: string
          example: zai-org/GLM-5.3-Flash
        choices:
          type: array
          items:
            type: object
            properties:
              index:
                type: integer
              message:
                $ref: '#/components/schemas/ChatMessage'
              finish_reason:
                type: string
                nullable: true
        usage:
          $ref: '#/components/schemas/Usage'
    ErrorResponse:
      type: object
      properties:
        error:
          type: object
          properties:
            message:
              type: string
            type:
              type: string
            code:
              type: string
    ChatMessage:
      type: object
      required:
        - role
        - content
      properties:
        role:
          type: string
          enum:
            - system
            - user
            - assistant
            - tool
        content:
          oneOf:
            - type: string
            - type: array
              items:
                type: object
                additionalProperties: true
        tool_calls:
          type: array
          items:
            type: object
            additionalProperties: true
        tool_call_id:
          type: string
      additionalProperties: true
    Usage:
      type: object
      properties:
        prompt_tokens:
          type: integer
        completion_tokens:
          type: integer
        total_tokens:
          type: integer
        prompt_tokens_details:
          type: object
          properties:
            cached_tokens:
              type: integer
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: >-
        Kunci API workspace CerasAI (format OpenAI: `Authorization: Bearer
        $CERASAI_API_KEY`).

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.