# Deferred Chat Completions

## OpenAPI Specification

```yaml
openapi: 3.0.1
info:
  title: ''
  description: ''
  version: 1.0.0
paths:
  /v1/chat/completions)REQUEST_ID=$(echo:
    post:
      summary: Deferred Chat Completions
      deprecated: false
      description: >-
        Deferred Chat Completions allow you to create a chat completion, get a
        `response_id`, and retrieve the response at a later time. The result
        would be available to be requested exactly once within 24 hours, after
        which it would be discarded.



        ![f592d1e9a4acf2622e56fb892a3b4be3_deferred-chat-flow.png](https://api.apidog.com/api/v1/projects/875787/resources/353383/image-preview)

        After sending the request to the xAI API, the chat completion result
        will be available at
        `https://api.x.ai/v1/chat/deferred-completion/{request_id}`. The
        response body will contain `{'request_id':
        'f15c114e-f47d-40ca-8d5c-8c23d656eeb6'}`, and the `request_id` value can
        be inserted into the `deferred-completion` endpoint path. Then, we send
        this GET request to retrieve the deferred completion result.


        Example code is provided below:


        ```bash

        RESPONSE=$(curl -s https://api.x.ai/v1/chat/completions \
          -H "Content-Type: application/json" \
          -H "Authorization: Bearer $XAI_API_KEY" \
          -d '{
                "messages": [
                    {"role": "system", "content": "You are Zaphod Beeblebrox."},
                    {"role": "user", "content": "126/3=?"}
                ],
                "model": "grok-3-latest",
                "deferred": true
              }')

        REQUEST_ID=$(echo "$RESPONSE" | jq -r '.request_id')

        echo "Request ID: $REQUEST_ID"


        sleep 10


        curl -s https://api.x.ai/v1/chat/deferred-completion/$REQUEST_ID \
          -H "Authorization: Bearer $XAI_API_KEY"
          ```

        The response body will be the same as what you would expect with
        non-deferred chat completions:


        ```json

        {
            "id": "c0161816-8b53-4c28-bd2b-3877c6edb800",
            "object": "chat.completion",
            "created": 3141592653,
            "model": "grok-3-beta",
            "choices": [
                {
                    "index": 0,
                    "message": {
                        "role": "assistant",
                        "content": "Hey, don't ask me about math, I'm Zaphod Beeblebrox, not a calculator! But if you really need to know, it's 42, isn't it? Everything's 42!",
                        "refusal": null
                    },
                    "finish_reason": "stop"
                }
            ],
            "usage": {
                "prompt_tokens": 27,
                "completion_tokens": 48,
                "reasoning_tokens": 0,
                "total_tokens": 75,
                "prompt_tokens_details": {
                    "text_tokens": 27,
                    "audio_tokens": 0,
                    "image_tokens": 0,
                    "cached_tokens": 0
                }
            },
            "system_fingerprint": "fp_fe9e7ef66e"
        }

        ```


        For more details, refer to [Chat
        completions](https://docs.x.ai/docs/api-reference#chat-completions) and
        [Get deferred chat
        completions](https://docs.x.ai/docs/api-reference#get-deferred-chat-completions)
        in our REST API Reference.
      tags:
        - Guides
      parameters:
        - name: Content-Type
          in: header
          description: ''
          required: true
          example: application/json
          schema:
            type: string
        - name: Authorization
          in: header
          description: ''
          required: true
          example: Bearer {{XAI_API_KEY}}
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                messages:
                  type: array
                  items:
                    type: object
                    properties:
                      role:
                        type: string
                      content:
                        type: string
                    required:
                      - role
                      - content
                model:
                  type: string
                deferred:
                  type: boolean
              required:
                - messages
                - model
                - deferred
            example:
              messages:
                - role: system
                  content: You are Zaphod Beeblebrox.
                - role: user
                  content: 126/3=?
              model: grok-3-latest
              deferred: true
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties: {}
          headers: {}
          x-apidog-name: Success
      security: []
      x-apidog-folder: Guides
      x-apidog-status: released
      x-run-in-apidog: https://app.apidog.com/web/project/875787/apis/api-15799322-run
components:
  schemas: {}
  securitySchemes: {}
servers:
  - url: https://api.x.ai/v1/
    description: Prod Env
security: []

```
