create_chat_completion
Generate chat completions using the Grok API by specifying models, messages, and parameters like temperature, tools, and response format to create tailored conversational outputs.
Instructions
Create a chat completion with the Grok API
Input Schema
| Name | Required | Description | Default | 
|---|---|---|---|
| frequency_penalty | No | Penalty for new tokens based on frequency in text (-2 to 2) | |
| logit_bias | No | Map of token IDs to bias scores (-100 to 100) that influence generation | |
| max_tokens | No | Maximum number of tokens to generate | |
| messages | Yes | Messages to generate chat completions for | |
| model | Yes | ID of the model to use | |
| n | No | Number of chat completion choices to generate | |
| presence_penalty | No | Penalty for new tokens based on presence in text (-2 to 2) | |
| response_format | No | Specify 'json_object' to receive JSON response or 'text' for raw text | |
| search_parameters | No | Parameters for live search capabilities | |
| seed | No | If specified, results will be more deterministic when the same seed is used | |
| stop | No | Sequences where the API will stop generating further tokens | |
| stream | No | If set, partial message deltas will be sent | |
| temperature | No | Sampling temperature (0-2) | |
| tool_choice | No | Controls which (if any) tool is called by the model | |
| tools | No | List of tools the model may call | |
| top_p | No | Nucleus sampling parameter (0-1) | |
| user | No | A unique user identifier | 
Input Schema (JSON Schema)
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "additionalProperties": false,
  "properties": {
    "frequency_penalty": {
      "description": "Penalty for new tokens based on frequency in text (-2 to 2)",
      "maximum": 2,
      "minimum": -2,
      "type": "number"
    },
    "logit_bias": {
      "additionalProperties": {
        "type": "number"
      },
      "description": "Map of token IDs to bias scores (-100 to 100) that influence generation",
      "type": "object"
    },
    "max_tokens": {
      "description": "Maximum number of tokens to generate",
      "exclusiveMinimum": 0,
      "type": "integer"
    },
    "messages": {
      "description": "Messages to generate chat completions for",
      "items": {
        "additionalProperties": false,
        "properties": {
          "content": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "items": {
                  "anyOf": [
                    {
                      "additionalProperties": false,
                      "properties": {
                        "text": {
                          "type": "string"
                        },
                        "type": {
                          "const": "text",
                          "type": "string"
                        }
                      },
                      "required": [
                        "type",
                        "text"
                      ],
                      "type": "object"
                    },
                    {
                      "additionalProperties": false,
                      "properties": {
                        "image_url": {
                          "additionalProperties": false,
                          "properties": {
                            "detail": {
                              "enum": [
                                "low",
                                "high",
                                "auto"
                              ],
                              "type": "string"
                            },
                            "url": {
                              "type": "string"
                            }
                          },
                          "required": [
                            "url"
                          ],
                          "type": "object"
                        },
                        "type": {
                          "const": "image",
                          "type": "string"
                        }
                      },
                      "required": [
                        "type",
                        "image_url"
                      ],
                      "type": "object"
                    }
                  ]
                },
                "type": "array"
              }
            ]
          },
          "name": {
            "type": "string"
          },
          "role": {
            "enum": [
              "system",
              "user",
              "assistant",
              "tool"
            ],
            "type": "string"
          }
        },
        "required": [
          "role",
          "content"
        ],
        "type": "object"
      },
      "type": "array"
    },
    "model": {
      "description": "ID of the model to use",
      "type": "string"
    },
    "n": {
      "description": "Number of chat completion choices to generate",
      "exclusiveMinimum": 0,
      "type": "integer"
    },
    "presence_penalty": {
      "description": "Penalty for new tokens based on presence in text (-2 to 2)",
      "maximum": 2,
      "minimum": -2,
      "type": "number"
    },
    "response_format": {
      "additionalProperties": false,
      "description": "Specify 'json_object' to receive JSON response or 'text' for raw text",
      "properties": {
        "type": {
          "enum": [
            "text",
            "json_object"
          ],
          "type": "string"
        }
      },
      "required": [
        "type"
      ],
      "type": "object"
    },
    "search_parameters": {
      "additionalProperties": false,
      "description": "Parameters for live search capabilities",
      "properties": {
        "from_date": {
          "description": "ISO 8601 format, e.g. YYYY-MM-DD",
          "type": "string"
        },
        "max_search_results": {
          "default": 20,
          "exclusiveMinimum": 0,
          "type": "integer"
        },
        "mode": {
          "default": "auto",
          "enum": [
            "off",
            "auto",
            "on"
          ],
          "type": "string"
        },
        "return_citations": {
          "type": "boolean"
        },
        "sources": {
          "items": {
            "anyOf": [
              {
                "additionalProperties": false,
                "properties": {
                  "country": {
                    "description": "ISO alpha-2 country code",
                    "maxLength": 2,
                    "minLength": 2,
                    "type": "string"
                  },
                  "excluded_websites": {
                    "items": {
                      "type": "string"
                    },
                    "maxItems": 5,
                    "type": "array"
                  },
                  "safe_search": {
                    "type": "boolean"
                  },
                  "type": {
                    "const": "web",
                    "type": "string"
                  }
                },
                "required": [
                  "type"
                ],
                "type": "object"
              },
              {
                "additionalProperties": false,
                "properties": {
                  "type": {
                    "const": "x",
                    "type": "string"
                  },
                  "x_handles": {
                    "items": {
                      "type": "string"
                    },
                    "type": "array"
                  }
                },
                "required": [
                  "type"
                ],
                "type": "object"
              },
              {
                "additionalProperties": false,
                "properties": {
                  "country": {
                    "description": "ISO alpha-2 country code",
                    "maxLength": 2,
                    "minLength": 2,
                    "type": "string"
                  },
                  "excluded_websites": {
                    "items": {
                      "type": "string"
                    },
                    "maxItems": 5,
                    "type": "array"
                  },
                  "safe_search": {
                    "type": "boolean"
                  },
                  "type": {
                    "const": "news",
                    "type": "string"
                  }
                },
                "required": [
                  "type"
                ],
                "type": "object"
              },
              {
                "additionalProperties": false,
                "properties": {
                  "links": {
                    "items": {
                      "type": "string"
                    },
                    "type": "array"
                  },
                  "type": {
                    "const": "rss",
                    "type": "string"
                  }
                },
                "required": [
                  "type",
                  "links"
                ],
                "type": "object"
              }
            ]
          },
          "type": "array"
        },
        "to_date": {
          "description": "ISO 8601 format, e.g. YYYY-MM-DD",
          "type": "string"
        }
      },
      "type": "object"
    },
    "seed": {
      "description": "If specified, results will be more deterministic when the same seed is used",
      "type": "integer"
    },
    "stop": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "items": {
            "type": "string"
          },
          "type": "array"
        }
      ],
      "description": "Sequences where the API will stop generating further tokens"
    },
    "stream": {
      "description": "If set, partial message deltas will be sent",
      "type": "boolean"
    },
    "temperature": {
      "description": "Sampling temperature (0-2)",
      "maximum": 2,
      "minimum": 0,
      "type": "number"
    },
    "tool_choice": {
      "anyOf": [
        {
          "const": "auto",
          "type": "string"
        },
        {
          "const": "none",
          "type": "string"
        },
        {
          "additionalProperties": false,
          "properties": {
            "function": {
              "additionalProperties": false,
              "properties": {
                "name": {
                  "description": "Force the model to call the specified function",
                  "type": "string"
                }
              },
              "required": [
                "name"
              ],
              "type": "object"
            },
            "type": {
              "const": "function",
              "type": "string"
            }
          },
          "required": [
            "type",
            "function"
          ],
          "type": "object"
        }
      ],
      "description": "Controls which (if any) tool is called by the model"
    },
    "tools": {
      "description": "List of tools the model may call",
      "items": {
        "additionalProperties": false,
        "properties": {
          "function": {
            "additionalProperties": false,
            "properties": {
              "description": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "parameters": {
                "additionalProperties": false,
                "properties": {
                  "properties": {
                    "additionalProperties": {},
                    "type": "object"
                  },
                  "required": {
                    "items": {
                      "type": "string"
                    },
                    "type": "array"
                  },
                  "type": {
                    "const": "object",
                    "type": "string"
                  }
                },
                "required": [
                  "type"
                ],
                "type": "object"
              }
            },
            "required": [
              "name"
            ],
            "type": "object"
          },
          "type": {
            "type": "string"
          }
        },
        "required": [
          "type",
          "function"
        ],
        "type": "object"
      },
      "type": "array"
    },
    "top_p": {
      "description": "Nucleus sampling parameter (0-1)",
      "maximum": 1,
      "minimum": 0,
      "type": "number"
    },
    "user": {
      "description": "A unique user identifier",
      "type": "string"
    }
  },
  "required": [
    "model",
    "messages"
  ],
  "type": "object"
}