# Grok API with cURL

Use cURL to test a Grok API Dev key, reproduce an HTTP error without an SDK, and inspect a streaming response. Every example calls the OpenAI-compatible Responses API.

## Prepare the API key

```bash
curl --version
```

```bash
export GROK_API_DEV_KEY="sk-lg-YOUR_API_KEY"
```

## Send a Responses API request

```bash
curl --fail-with-body 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 HTTP in two sentences"
  }'
```

## Read the JSON response

```json
{
  "id": "resp_01abc",
  "status": "completed",
  "output": [
    {
      "type": "message",
      "role": "assistant",
      "content": [
        { "type": "output_text", "text": "HTTP is..." }
      ]
    }
  ],
  "usage": {
    "input_tokens": 12,
    "output_tokens": 34,
    "total_tokens": 46
  }
}
```

## Stream SSE events with cURL

```bash
curl -N --fail-with-body 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": "Write a short example",
    "stream": true
  }'
```

## Inspect HTTP errors

Start debugging with one short input and the smallest valid JSON body. Add -i when you need response headers together with the body.

```bash
curl -i --fail-with-body 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": "Test request"
  }'
```

- 401: verify the Bearer header and GROK_API_DEV_KEY.
- 404: verify /v1/responses and the grok-4.5 model ID.
- 429: check Retry-After when present and reduce request frequency.
- DNS or TLS failure: no HTTP status exists, so check the network and hostname first.

[Full API error reference](https://grok-api.dev/en/docs/errors)

## Related pages

- [Messages API](https://grok-api.dev/en/docs/messages)
- [Streaming API](https://grok-api.dev/en/docs/streaming)
- [Python](https://grok-api.dev/en/docs/python)
- [TypeScript](https://grok-api.dev/en/docs/typescript)
