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

# xAI

> Call xAI Grok 4.7 and Grok 4.6 through the OpenAI-compatible Chat Completions endpoint.

xAI Grok models cover long-running agents, coding, engineering, and knowledge work. The playground on this page uses [Chat Completions](https://docs.poyo.ai/api-manual/chat-series/chat-completions.md), which every Grok model supports.

## Models

* **grok-4.7** — Grok 4.7. Chat Completions only.
* **grok-4.6** — Grok 4.6, for long-running agents, coding, and interactive or visual projects. Supports Chat Completions and Responses.

## Examples

* **Basic chat completion** — single user message.
* **System prompt** — `system` message with `max_tokens`.
* **Streaming output** — `stream: true`, returned as SSE.

To call `grok-4.6` with the Responses format, send the same model id to [Responses](https://docs.poyo.ai/api-manual/chat-series/responses.md).

## Notes

* `grok-4.7` only accepts `/v1/chat/completions`.
* See [LLM Models](https://docs.poyo.ai/api-manual/chat-series/overview.md) for every model and the formats it supports.


## OpenAPI

````yaml api-manual/chat-series/xai.json POST /v1/chat/completions
openapi: 3.0.0
info:
  title: xAI API
  description: >-
    Call xAI Grok models through the OpenAI-compatible Chat Completions
    endpoint.
  version: 1.0.0
servers:
  - url: https://api.poyo.ai
    description: Production server
security:
  - BearerAuth: []
paths:
  /v1/chat/completions:
    post:
      tags:
        - LLM
      summary: xAI
      description: Chat completions with xAI Grok models.
      operationId: createXaiChatCompletion
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionRequest'
            examples:
              basic:
                summary: Basic chat completion
                value:
                  model: grok-4.7
                  messages:
                    - role: user
                      content: Explain vector databases in one sentence.
              system_prompt:
                summary: System prompt
                value:
                  model: grok-4.7
                  messages:
                    - role: system
                      content: >-
                        You are a senior Python reviewer. Reply with a numbered
                        list.
                    - role: user
                      content: 'Review: def add(a, b): return a+b'
                  max_tokens: 512
              stream:
                summary: Streaming output
                value:
                  model: grok-4.6
                  messages:
                    - role: user
                      content: Generate 5 short titles about AI agents.
                  stream: true
      responses:
        '200':
          description: Completion created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletion'
              examples:
                success:
                  summary: Successful response
                  value:
                    id: chatcmpl-9876543210
                    object: chat.completion
                    created: 1677652288
                    model: grok-4.7
                    choices:
                      - index: 0
                        message:
                          role: assistant
                          content: >-
                            A vector database stores embeddings and finds the
                            most similar ones quickly.
                        finish_reason: stop
                    usage:
                      prompt_tokens: 12
                      completion_tokens: 18
                      total_tokens: 30
        '400':
          description: >-
            Invalid request parameters, or the model does not support this API
            format
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PoyoValidationError'
        '401':
          description: Missing or invalid API key
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PoyoAuthError'
        '404':
          description: Unknown model id
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UpstreamFormatError'
              example:
                error:
                  message: 'Model not found: no-such-model'
                  type: invalid_request_error
                  code: model_not_found
components:
  schemas:
    ChatCompletionRequest:
      type: object
      required:
        - model
        - messages
      properties:
        model:
          type: string
          enum:
            - grok-4.7
            - grok-4.6
          default: grok-4.7
          description: xAI Grok model id.
        messages:
          type: array
          description: >-
            List of conversation messages. Each message contains a `role` and
            `content`. Use `system` to define model behavior, `user` for user
            input, and `assistant` for previous model responses in multi-turn
            conversations.
          items:
            $ref: '#/components/schemas/ChatMessage'
        temperature:
          type: number
          minimum: 0
          maximum: 2
          description: >-
            Controls output randomness, range 0-2. Lower values such as 0.2 make
            output more deterministic. Higher values such as 1.8 make output
            more random. Default: 1.0.
          example: 1
        max_tokens:
          type: integer
          minimum: 1
          description: >-
            Maximum number of tokens to generate. Different models have
            different maximum limits.
          example: 256
        stream:
          type: boolean
          description: >-
            Whether to use streaming output. `true` returns a streaming response
            in SSE format. `false` returns the complete response at once.
            Default: false.
          example: false
        top_p:
          type: number
          minimum: 0
          maximum: 1
          description: >-
            Nucleus sampling parameter, range 0-1. Controls diversity of
            generated text. We recommend using either `top_p` or `temperature`,
            not both. Default: 1.0.
          example: 1
        frequency_penalty:
          type: number
          minimum: -2
          maximum: 2
          description: >-
            Frequency penalty, range -2.0 to 2.0. Positive values reduce the
            likelihood of repeating the same words. Default: 0.
          example: 0
        presence_penalty:
          type: number
          minimum: -2
          maximum: 2
          description: >-
            Presence penalty, range -2.0 to 2.0. Positive values increase the
            likelihood of talking about new topics. Default: 0.
          example: 0
        stop:
          description: >-
            Stop sequences. Up to 4 sequences where generation will stop when
            encountered.
          oneOf:
            - type: string
              example: |-


                Human:
            - type: array
              items:
                type: string
        'n':
          type: integer
          minimum: 1
          description: >-
            Number of completions to generate. Default: 1. Must be a plain
            number such as `1`; do not use quotes.
          example: 1
    ChatCompletion:
      type: object
      properties:
        id:
          type: string
          description: Unique identifier for the response.
          example: chatcmpl-9876543210
        object:
          type: string
          description: Object type.
          example: chat.completion
        created:
          type: integer
          description: Creation timestamp.
          example: 1677652288
        model:
          type: string
          description: The actual model name used.
          example: grok-4.7
        choices:
          type: array
          items:
            $ref: '#/components/schemas/ChatCompletionChoice'
        usage:
          $ref: '#/components/schemas/Usage'
    PoyoValidationError:
      type: object
      properties:
        code:
          type: integer
          example: 400
        error:
          type: object
          properties:
            message:
              type: string
              example: 'Invalid request parameters: messages: Field required'
            type:
              type: string
              example: validation_error
            details:
              type: object
              description: Field-level validation errors when available.
    PoyoAuthError:
      type: object
      properties:
        code:
          type: integer
          example: 401
        error:
          type: object
          properties:
            message:
              type: string
              example: Invalid API key
            type:
              type: string
              example: authentication_error
    UpstreamFormatError:
      type: object
      description: >-
        Error returned when the model or request is rejected for this API
        format.
      properties:
        error:
          type: object
          properties:
            message:
              type: string
              example: 'Model not found: no-such-model'
            type:
              type: string
              example: invalid_request_error
            code:
              type: string
              example: model_not_found
    ChatMessage:
      type: object
      required:
        - role
        - content
      properties:
        role:
          type: string
          enum:
            - system
            - user
            - assistant
          description: >-
            Message role. `user` is user input, `assistant` is previous model
            output for multi-turn conversations, and `system` is the system
            prompt.
          default: user
        content:
          type: string
          description: Message content, question, or instruction.
          example: Explain vector databases in one sentence.
    ChatCompletionChoice:
      type: object
      properties:
        index:
          type: integer
          example: 0
        message:
          $ref: '#/components/schemas/ChatMessage'
        finish_reason:
          type: string
          description: Reason for completion.
          enum:
            - stop
            - length
            - content_filter
            - function_call
          example: stop
    Usage:
      type: object
      properties:
        prompt_tokens:
          type: integer
          description: Number of tokens in the input messages.
          example: 12
        completion_tokens:
          type: integer
          description: Number of tokens in the generated content.
          example: 18
        total_tokens:
          type: integer
          description: Total number of tokens.
          example: 30
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: >-
        All API endpoints require Bearer Token authentication.


        Get your API Key:


        Visit the [API Key Management Page](https://poyo.ai/dashboard/api-key)
        to get your API Key


        Add it to the request header:


        ```

        Authorization: Bearer YOUR_API_KEY

        ```

````

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