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

# Grok Completions

<Note>
  请求参数及响应参数与官方一致，
  具体参考<a href="https://docs.x.ai/developers/rest-api-reference/inference/chat#chat-completions" target="_blank">Grok官方文档</a>。
</Note>


## OpenAPI

````yaml openapi/cn/llm.json POST /v1/chat/completions
openapi: 3.1.0
info:
  title: LLM API DOCS
  version: 1.0.0
  description: TTAPI LLM API 接口服务。
servers:
  - url: https://api.ttapi.io
security: []
paths:
  /v1/chat/completions:
    post:
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CompletionsRequest'
      responses:
        '200':
          description: 成功响应
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    example: chatcmpl-9ugiTupGJUmeRNqyqUvYO34GOUzyv
                  object:
                    type: string
                    example: chat.completion
                  created:
                    type: integer
                    example: 1723297597
                  model:
                    type: string
                    example: gpt-3.5-turbo-0125
                  choices:
                    type: array
                    items:
                      type: object
                      properties:
                        index:
                          type: integer
                          example: 0
                        message:
                          type: object
                          properties:
                            content:
                              type: string
                              example: 你好！有什么可以帮助你的吗？
                            role:
                              type: string
                              example: assistant
                            refusal:
                              type:
                                - string
                                - 'null'
                              example: null
                        finish_reason:
                          type: string
                          example: stop
                  usage:
                    type: object
                    properties:
                      prompt_tokens:
                        type: integer
                        example: 11
                      completion_tokens:
                        type: integer
                        example: 17
                      total_tokens:
                        type: integer
                        example: 28
            text/event-stream:
              schema:
                type: string
                description: 'SSE 流式输出，每行以 data: 开头，最后一行是 data: [DONE]'
              examples:
                stream-example:
                  summary: SSE 流式输出 (stream=true)
                  value: >-
                    data:
                    {"id":"chatcmpl-83jctesyk8nEkPytXDNLz1oV5dIQK","object":"chat.completion.chunk","created":1695901063,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}


                    data:
                    {"id":"chatcmpl-83jctesyk8nEkPytXDNLz1oV5dIQK","object":"chat.completion.chunk","created":1695901063,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}


                    data:
                    {"id":"chatcmpl-83jctesyk8nEkPytXDNLz1oV5dIQK","object":"chat.completion.chunk","created":1695901063,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"content":"!"},"finish_reason":null}]}


                    data:
                    {"id":"chatcmpl-83jctesyk8nEkPytXDNLz1oV5dIQK","object":"chat.completion.chunk","created":1695901063,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"content":"
                    How"},"finish_reason":null}]}


                    data:
                    {"id":"chatcmpl-83jctesyk8nEkPytXDNLz1oV5dIQK","object":"chat.completion.chunk","created":1695901063,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"content":"
                    can"},"finish_reason":null}]}


                    data:
                    {"id":"chatcmpl-83jctesyk8nEkPytXDNLz1oV5dIQK","object":"chat.completion.chunk","created":1695901063,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"content":"
                    I"},"finish_reason":null}]}


                    data:
                    {"id":"chatcmpl-83jctesyk8nEkPytXDNLz1oV5dIQK","object":"chat.completion.chunk","created":1695901063,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"content":"
                    assist"},"finish_reason":null}]}


                    data:
                    {"id":"chatcmpl-83jctesyk8nEkPytXDNLz1oV5dIQK","object":"chat.completion.chunk","created":1695901063,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"content":"
                    you"},"finish_reason":null}]}


                    data:
                    {"id":"chatcmpl-83jctesyk8nEkPytXDNLz1oV5dIQK","object":"chat.completion.chunk","created":1695901063,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"content":"
                    today"},"finish_reason":null}]}


                    data:
                    {"id":"chatcmpl-83jctesyk8nEkPytXDNLz1oV5dIQK","object":"chat.completion.chunk","created":1695901063,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{"content":"?"},"finish_reason":null}]}


                    data:
                    {"id":"chatcmpl-83jctesyk8nEkPytXDNLz1oV5dIQK","object":"chat.completion.chunk","created":1695901063,"model":"gpt-3.5-turbo-0613","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}


                    data: [DONE]
        '400':
          $ref: '#/components/responses/400Response'
        '401':
          $ref: '#/components/responses/401Response'
      security:
        - Authorization: []
components:
  schemas:
    CompletionsRequest:
      type: object
      properties:
        messages:
          type: array
          items:
            type: object
            properties:
              role:
                type: string
              content:
                type: string
          example:
            - role: user
              content: Hello!
        model:
          type: string
          description: 使用模型，详见[支持模型](/grids/cn/start/pricing/llm)
        stream:
          type: boolean
          default: 'false'
          description: 是否使用服务器发送的事件逐步传输响应
      required:
        - messages
        - model
  responses:
    400Response:
      description: 参数错误
      content:
        application/json:
          schema:
            type: object
            properties:
              status:
                type: string
                example: FAILED
              message:
                type: string
                example: '"prompt" cannot be empty.'
              data:
                type: object
            required:
              - status
              - message
    401Response:
      description: 授权失败
      content:
        application/json:
          schema:
            type: object
            properties:
              status:
                type: string
                example: FAILED
              message:
                type: string
                example: Wrong TT-API-KEY or email is not activated.
            required:
              - status
              - message
  securitySchemes:
    Authorization:
      type: apiKey
      in: header
      name: Authorization
      description: >-
        请前往 <a href='https://dashboard.ttapi.io' target='_blank'>TTAPI 控制台</a>
        获取 API 密钥。

````