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

# Chat Completions

> Creates a model response for Gemini models using OpenAI-compatible format.



## OpenAPI

````yaml api-reference/endpoints/openapi/gemini-chat/openapi.yaml POST /v1/chat/completions
openapi: 3.1.0
info:
  title: Gemini Chat Compatible Endpoint
  description: >-
    Google Gemini models via OpenAI-compatible chat completions endpoint on
    Anyfast
  version: 1.0.0
servers:
  - url: https://www.anyfast.ai
security:
  - bearerAuth: []
paths:
  /v1/chat/completions:
    post:
      summary: Chat Completion
      description: >-
        Creates a model response for Gemini models using OpenAI-compatible
        format.
      operationId: createChatCompletionGemini
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - model
                - messages
              properties:
                model:
                  type: string
                  enum:
                    - gemini-3.1-pro-preview
                    - gemini-3.1-flash-image
                    - gemini-3.1-flash-lite-preview
                    - gemini-3-pro-preview
                    - gemini-3-pro-image
                    - gemini-3-flash-preview
                    - gemini-2.5-pro
                    - gemini-2.5-flash
                    - gemini-2.5-flash-lite
                    - gemini-2.0-flash
                  description: Gemini model ID to use for completion.
                  example: gemini-2.5-pro
                messages:
                  type: array
                  minItems: 1
                  description: A list of messages comprising the conversation so far.
                  items:
                    type: object
                    required:
                      - role
                      - content
                    properties:
                      role:
                        type: string
                        enum:
                          - system
                          - user
                          - assistant
                      content:
                        oneOf:
                          - type: string
                          - type: array
                            items:
                              type: object
                  example:
                    - role: user
                      content: Hello!
                max_tokens:
                  type: integer
                  minimum: 1
                  description: >-
                    The maximum number of tokens to generate in the chat
                    completion.
                temperature:
                  type: number
                  minimum: 0
                  maximum: 2
                  default: 1
                  description: Sampling temperature between 0 and 2.
                  example: 1
                top_p:
                  type: number
                  minimum: 0
                  maximum: 1
                  description: Nucleus sampling threshold.
                frequency_penalty:
                  type: number
                  minimum: -2
                  maximum: 2
                  default: 0
                  description: >-
                    Penalizes new tokens based on their existing frequency in
                    the text so far.
                presence_penalty:
                  type: number
                  minimum: -2
                  maximum: 2
                  default: 0
                  description: >-
                    Penalizes new tokens based on whether they appear in the
                    text so far.
                stream:
                  type: boolean
                  default: false
                  description: >-
                    If true, partial message deltas will be sent as server-sent
                    events.
                stop:
                  oneOf:
                    - type: string
                    - type: array
                      items:
                        type: string
                  description: Sequences where the API will stop generating further tokens.
                'n':
                  type: integer
                  minimum: 1
                  default: 1
                  description: >-
                    How many chat completion choices to generate for each input
                    message.
                response_format:
                  type: object
                  properties:
                    type:
                      type: string
                      enum:
                        - text
                        - json_object
                  description: >-
                    An object specifying the format that the model must output.
                    Setting to {"type": "json_object"} enables JSON mode.
      responses:
        '200':
          description: Completion generated successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletion'
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: Rate limit exceeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    ChatCompletion:
      type: object
      required:
        - id
        - object
        - created
        - model
        - choices
      properties:
        id:
          type: string
          example: chatcmpl-abc123
        object:
          type: string
          example: chat.completion
        created:
          type: integer
          description: Unix timestamp of when the completion was created.
        model:
          type: string
          example: gemini-2.5-pro
        choices:
          type: array
          items:
            type: object
            properties:
              index:
                type: integer
              message:
                type: object
                properties:
                  role:
                    type: string
                    example: assistant
                  content:
                    type: string
                    example: Hello! How can I help you today?
              finish_reason:
                type: string
                enum:
                  - stop
                  - length
                  - content_filter
                  - null
        usage:
          type: object
          properties:
            prompt_tokens:
              type: integer
            completion_tokens:
              type: integer
            total_tokens:
              type: integer
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
            message:
              type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````