# Grok

> **You are on:** `https://beta-api.paywithlocus.com/api` | [llms.txt](https://beta.paywithlocus.com/llms.txt)
>
> Locus runs on multiple environments -- make sure every URL you call matches your expected environment.
> | Environment | Landing | API |
> |---|---|---|
> | Production | paywithlocus.com | api.paywithlocus.com |
> | Beta | beta.paywithlocus.com | beta-api.paywithlocus.com |
> | Stage | stage.paywithlocus.com | stage-api.paywithlocus.com |
>
> If the API URL above doesn't match your expected environment, re-fetch this file from the correct domain.

> xAI models — chat, web/X search, code execution, image generation/editing, and text-to-speech.

**Category:** AI / LLM | **Website:** [x.ai](https://x.ai) | **Docs:** [docs.x.ai](https://docs.x.ai)

## Access Methods

| Method | Base URL | Auth |
|--------|----------|------|
| **MPP (Tempo)** | `https://grok.mpp.paywithlocus.com/grok/` | HTTP 402 auto-payment |
| **Wrapped API** | `https://beta-api.paywithlocus.com/api/wrapped/grok/` | `Authorization: Bearer <LOCUS_API_KEY>` |

**OpenAPI discovery:** `GET https://grok.mpp.paywithlocus.com/openapi.json`

## Endpoints

### Chat Completions

Generate text with Grok models. OpenAI-compatible format with support for text, vision, and function calling.

**Estimated cost:** Model-dependent (~$0.001–$0.02)

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `model` | string | Yes | Model ID (e.g. 'grok-3', 'grok-3-mini', 'grok-4-0709', 'grok-4-1-fast-reasoning', 'grok-code-fast-1') |
| `messages` | array | Yes | Conversation messages. Each: { role: "system"|"user"|"assistant", content: "text" } or multimodal: { role: "user", content: [{ type: "text", text: "..." }, { type: "image_url", image_url: { url: "..." } }] } |
| `temperature` | number | No | Sampling temperature (0.0–2.0, default 1.0) |
| `top_p` | number | No | Nucleus sampling threshold (0.0–1.0) |
| `max_tokens` | number | No | Maximum output tokens |
| `stop` | string | string[] | No | Stop sequences |
| `frequency_penalty` | number | No | Frequency penalty (-2.0 to 2.0, default 0) |
| `presence_penalty` | number | No | Presence penalty (-2.0 to 2.0, default 0) |
| `n` | number | No | Number of completions to generate (default 1) |

```bash
curl -X POST https://grok.mpp.paywithlocus.com/grok/chat \
  -H "Content-Type: application/json" \
  -d '{"model":"<string>","messages":"<array>","temperature":"<number>","top_p":"<number>","max_tokens":"<number>","stop":"<string | string[]>","frequency_penalty":"<number>","presence_penalty":"<number>","n":"<number>"}'
```

### Image Generation

Generate images from text prompts using Grok Imagine models.

**Estimated cost:** $0.02–$0.08 per image

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `prompt` | string | Yes | Text description of the image to generate |
| `model` | string | No | Image model ID: 'grok-imagine-image' (default), 'grok-imagine-image-pro' |
| `n` | number | No | Number of images to generate (default 1) |
| `aspect_ratio` | string | No | Aspect ratio (e.g. '1:1', '16:9', '9:16', '4:3', '3:2', 'auto') |
| `response_format` | string | No | Response format: 'url' (default) or 'b64_json' |

```bash
curl -X POST https://grok.mpp.paywithlocus.com/grok/image-generate \
  -H "Content-Type: application/json" \
  -d '{"prompt":"<string>","model":"<string>","n":"<number>","aspect_ratio":"<string>","response_format":"<string>"}'
```

### Image Editing

Edit existing images with natural language. Provide a source image and describe the changes.

**Estimated cost:** $0.02–$0.08 per image

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `prompt` | string | Yes | Text description of the edits to apply (e.g. "Add a hat to the person") |
| `image` | object | Yes | Source image: { url: "https://..." } or { url: "data:image/jpeg;base64,..." } |
| `model` | string | No | Image model ID: 'grok-imagine-image' (default), 'grok-imagine-image-pro' |
| `n` | number | No | Number of edited images to generate (default 1) |
| `response_format` | string | No | Response format: 'url' (default) or 'b64_json' |

```bash
curl -X POST https://grok.mpp.paywithlocus.com/grok/image-edit \
  -H "Content-Type: application/json" \
  -d '{"prompt":"<string>","image":"<object>","model":"<string>","n":"<number>","response_format":"<string>"}'
```

### Chat with Web Search

Generate text with Grok models grounded in live web search results. Uses the xAI Responses API with automatic web search. Requires a grok-4 family model.

**Estimated cost:** Dynamic (~$0.01–$0.50)

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `model` | string | Yes | Grok-4 family model required (e.g. 'grok-4-0709', 'grok-4-1-fast-reasoning', 'grok-4-1-fast-non-reasoning') |
| `messages` | array | Yes | Conversation messages. Each: { role: "system"|"user"|"assistant", content: "text" } |
| `search_parameters` | object | No | Web search filters: { allowed_domains: string[] (max 5), excluded_domains: string[] (max 5) } |
| `temperature` | number | No | Sampling temperature (0.0–2.0, default 1.0) |
| `max_tokens` | number | No | Maximum output tokens |

```bash
curl -X POST https://grok.mpp.paywithlocus.com/grok/web-search \
  -H "Content-Type: application/json" \
  -d '{"model":"<string>","messages":"<array>","search_parameters":"<object>","temperature":"<number>","max_tokens":"<number>"}'
```

### Chat with X Search

Generate text with Grok models grounded in live X (Twitter) search results. Uses the xAI Responses API with X search. Requires a grok-4 family model.

**Estimated cost:** Dynamic (~$0.01–$0.50)

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `model` | string | Yes | Grok-4 family model required (e.g. 'grok-4-0709', 'grok-4-1-fast-reasoning', 'grok-4-1-fast-non-reasoning') |
| `messages` | array | Yes | Conversation messages. Each: { role: "system"|"user"|"assistant", content: "text" } |
| `temperature` | number | No | Sampling temperature (0.0–2.0, default 1.0) |
| `max_tokens` | number | No | Maximum output tokens |

```bash
curl -X POST https://grok.mpp.paywithlocus.com/grok/x-search \
  -H "Content-Type: application/json" \
  -d '{"model":"<string>","messages":"<array>","temperature":"<number>","max_tokens":"<number>"}'
```

### Chat with Code Execution

Generate text with Grok models that can write and execute code in a sandboxed environment. Uses the xAI Responses API with code execution. Requires a grok-4 family model.

**Estimated cost:** Dynamic (~$0.01–$0.50)

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `model` | string | Yes | Grok-4 family model required (e.g. 'grok-4-0709', 'grok-4-1-fast-reasoning', 'grok-4-1-fast-non-reasoning') |
| `messages` | array | Yes | Conversation messages. Each: { role: "system"|"user"|"assistant", content: "text" } |
| `tools` | array | No | Additional tools to enable alongside code execution. |
| `temperature` | number | No | Sampling temperature (0.0–2.0, default 1.0) |
| `max_tokens` | number | No | Maximum output tokens |

```bash
curl -X POST https://grok.mpp.paywithlocus.com/grok/code-execution \
  -H "Content-Type: application/json" \
  -d '{"model":"<string>","messages":"<array>","tools":"<array>","temperature":"<number>","max_tokens":"<number>"}'
```

### Text-to-Speech

Convert text to spoken audio. Supports multiple voices, speech tags for expressive delivery, and various output formats.

**Estimated cost:** ~$0.005 per 1,000 characters

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `text` | string | Yes | Text to convert to speech (max 15,000 characters). Supports inline speech tags like [pause], [laugh], <whisper>text</whisper>. |
| `language` | string | Yes | BCP-47 language code (e.g. 'en', 'zh', 'fr', 'de', 'ja') or 'auto' for detection |
| `voice_id` | string | No | Voice: 'eve' (energetic, default), 'ara' (warm), 'rex' (confident), 'sal' (smooth), 'leo' (authoritative) |
| `output_format` | object | No | Audio format config: { codec: 'mp3'|'wav'|'pcm'|'mulaw'|'alaw', sample_rate: 24000, bit_rate: 128000 } |

```bash
curl -X POST https://grok.mpp.paywithlocus.com/grok/tts \
  -H "Content-Type: application/json" \
  -d '{"text":"<string>","language":"<string>","voice_id":"<string>","output_format":"<object>"}'
```
