# Messages API for Grok

Generate text with Grok through the OpenAI-compatible Responses API. This reference covers requests, parameters, response objects, token usage, and conversation history.

To display the answer while it is being generated, see the [Streaming API](https://grok-api.dev/en/docs/streaming).

## Request example

```bash
curl https://api.llm-gate.tech/v1/responses \
  -H "Authorization: Bearer $GROK_API_DEV_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "grok-4.5",
    "input": "Explain binary search in two sentences."
  }'
```

## Request parameters

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| model | string | Yes | Model ID. |
| input | string or array | Yes | A prompt or an ordered list of messages. |
| instructions | string | No | High-level instructions for the response. |
| max_output_tokens | integer | No | Maximum number of generated tokens. |
| temperature | number | No | Sampling randomness. |
| stream | boolean | No | Returns incremental SSE events when true. |
| store | boolean | No | Controls whether the response can be referenced by ID. |
| previous_response_id | string | No | Previous response ID used to continue a conversation. |

## Message roles

| role | description |
| --- | --- |
| system | Application rules and context. |
| user | The current user request. |
| assistant | A previous model response in locally managed history. |

## Response format

| status | meaning |
| --- | --- |
| completed | The response is ready. |
| in_progress | Generation is still running. |
| incomplete | The response stopped before completion. |

`usage.input_tokens` is the processed context, `usage.output_tokens` is generated output, and `usage.total_tokens` is their sum. Input and output are billed separately.

## Stateful and stateless conversations

In stateless mode, your application stores the message history and sends the required context with every request. In stateful mode, pass `previous_response_id` to continue from an earlier response.
