grok_api 0.2.0

Rust client library for the Grok AI API (xAI)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
# Changelog


All notable changes to the `grok_api` crate will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.9] - 2026-07-29


> **Note:** Versions `0.1.71``0.1.77` were incremental patch steps.
> `0.1.8` is the correct semver minor bump that supersedes them all.
> All changes from those versions are included here.

### Added (since 0.1.7)

- `Model::Grok4_5` — current flagship; 500 K context, configurable reasoning effort.
- `Model::GrokBuild0_1` — agentic coding model; 256 K context.
- `Model::Grok4_3` — previous flagship; 1 M context.
- `Model::GrokVoiceThinkFast2_0`, `GrokVoiceThinkFast1_0`, `GrokVoiceLatest` — real-time voice models.
- `Model::Grok5` — placeholder for upcoming Grok 5.
- **`grok_api::voice` module** — full `VoiceSession` WebSocket client:
  - `VoiceSessionBuilder` with all `session.update` parameters.
  - 12 public `async` methods: `append_audio`, `send_text`, `request_response`, `send_function_result`, `reconnect`, `force_message`, etc.
  - Starlink-aware exponential backoff reconnection.
  - `AudioCodec`, `AudioFormat`, `TurnDetection`, `ReasoningEffort`, `VoiceEvent`, `VoiceUsage` public types.
  - Guard: `build()` rejects non-voice models.
- `Model::supports_reasoning_effort()` — true for `Grok4_3`, `Grok4_5`, `Grok5`.
- `Model::is_voice_model()` — true for voice variants.
- `Model::all_including_deprecated()` — exhaustive list including deprecated variants.
- `Model::all()` now returns only active (non-deprecated) models.
- `ChatRequest::reasoning_effort` field + `ChatRequestBuilder::reasoning_effort()` setter.
- `.zed/task_list.json` — task tracker for Grok 4.6, 4.7, and Voice improvements.

### Changed (since 0.1.7)

- `DEFAULT_MODEL` in `client.rs` updated to `"grok-4.5"`.
- `Model::is_language_model()` returns `false` for voice models.
- `Model::supports_logprobs()` updated for all new-gen models.
- Deprecated variants updated with refined migration notes.
- **`Cargo.toml` version** `0.1.7``0.1.9` (0.1.8 was already taken on crates.io).

---

## [0.1.77] - 2026-07-29


### Added

- **`src/voice.rs`** — complete `voice` module for the xAI real-time
  Speech-to-Speech WebSocket API (`wss://api.x.ai/v1/realtime`).

  | Public type | Purpose |
  |---|---|
  | `VoiceSession` | Active WebSocket session; all I/O is async |
  | `VoiceSessionBuilder` | Fluent builder — `VoiceSession::builder(api_key).…build().await` |
  | `VoiceEvent` | Parsed server-sent events (12 variants) |
  | `AudioFormat` | Codec + sample-rate descriptor (`pcm`, `pcmu`, `pcma`, `opus`) |
  | `AudioCodec` | Codec enum backing `AudioFormat` |
  | `TurnDetection` | Turn-detection config with builder methods |
  | `TurnDetectionKind` | `ServerVad` or `Manual` |
  | `ReasoningEffort` | `High` or `None` |
  | `VoiceUsage` | Token-usage stats from `VoiceEvent::Done` |

  **Key capabilities:**
  - Full `session.update` serialisation: voice, instructions, turn detection,
    audio formats, transport modes, language hints, keyterms, output speed,
    reasoning effort.
  - All bidirectional operations: `append_audio`, `commit_audio`,
    `clear_audio`, `request_response`, `send_text`, `send_function_result`,
    `interrupt`, `force_message`, `update_session`.
  - Starlink-aware `reconnect()` with exponential backoff + jitter
    (`RetryConfig`), session-resumption via `conversation_id` query param.
  - 12 `VoiceEvent` variants cover every server message type including
    `AudioDelta`, `TranscriptDone`, `FunctionCall`, `Done`, `Error`, and
    `Other` for forward-compatibility.
  - All `warn!`/`info!`/`debug!` logging via `tracing`.

- **New Cargo dependencies:**
  - `tokio-tungstenite = { version = "0.26", features = ["rustls-tls-native-roots"] }`
  - `futures-util = "0.3"`

- **`src/lib.rs`**`pub mod voice` declared; all nine public voice types
  re-exported from the crate root.

- **13 new unit tests** in `voice::tests`; 3 new doc-tests. All 33 unit tests
  and 9 doc-tests pass (`cargo test`).

- **`Cargo.toml` version** bumped `0.1.76``0.1.77`.

---

## [0.1.74] - 2026-07-09


### Added

- **`Model::Grok4_5`** (`grok-4.5`) -- SpaceXAI's frontier model released July 8, 2026,
  optimised for coding, agentic tasks, and knowledge work.
  - **Context window**: 500,000 tokens
  - **Reasoning**: configurable (`low` / `medium` / `high`, default `high`) via `reasoning_effort`
  - **Modalities**: text + image input -> text output
  - **Function calling & structured outputs**: supported
  - **Pricing**: $2.00 / 1M input tokens, $6.00 / 1M output tokens ($0.50 / 1M cached)
  - `parse()` recognises the primary string `"grok-4.5"` plus rolling aliases
    `"grok-4.5-latest"` and `"grok-build-latest"`.
  - Capability flags:
    - `is_reasoning_model()` -> `false` (configurable effort, not a pure reasoning model)
    - `supports_reasoning_effort()` -> `true`
    - `supports_logprobs()` -> `false`
  - Appears first in `Model::all()` as the recommended default for coding workloads.
- **`Cargo.toml` version** bumped `0.1.73` -> `0.1.74`.

---

## [0.1.76] - 2026-07-29


### Added

- **Voice model variants** — three new `Model` variants for the xAI Speech-to-Speech
  (real-time voice) API, released July 2026.

  | Variant | API string | Notes |
  |---|---|---|
  | `GrokVoiceThinkFast2_0` | `grok-voice-think-fast-2.0` | Current flagship voice model |
  | `GrokVoiceThinkFast1_0` | `grok-voice-think-fast-1.0` | Previous-gen voice model |
  | `GrokVoiceLatest` | `grok-voice-latest` | Rolling alias; updates to 2.0 on 2026-08-05 |

  Voice models connect via WebSocket (`wss://api.x.ai/v1/realtime?model=...`) and are
  **not** usable with `GrokClient` or the chat completions API. Use `Model::as_str()` to
  get the model name for the `?model=` query parameter.

- **`Model::is_voice_model()`** — returns `true` for all three voice variants.
- **`Model::is_language_model()`** updated to return `false` for voice models (in addition
  to image and video models).
- **`Model::context_window()`** returns `None` for voice models (no token context window).
- Voice models included in `Model::all()` and `Model::all_including_deprecated()`.
- **`.zed/task_list.json`** created with tracked tasks for upcoming Grok 4.6, 4.7, and
  a Voice API `VoiceSessionBuilder` improvement task.
- **`Cargo.toml` version** bumped `0.1.75``0.1.76`.

---

## [0.1.75] - 2026-07-20


### Changed

- `DEFAULT_MODEL` in `client.rs` updated `"grok-4.3"``"grok-4.5"`.
- `test_connection()` updated to use `"grok-4.5"`.
- All examples updated: `grok-4.3``grok-4.5` as the recommended model string.
- README: added Grok 4.5 section at the top of the models table; `grok-4.3`
  re-positioned as "Previous Flagship" (still active, better for > 500 K context needs).
- **`Cargo.toml` version** bumped `0.1.74``0.1.75`.

---

## [0.1.73] - 2026-05-31


### Added

- **`Model::Grok5`** — placeholder variant for the upcoming Grok 5 model family.
  - **Not yet released by xAI.** All capability values are speculative and clearly
    marked with `UPDATE WHEN CONFIRMED` comments in the source.
  - Assumed API string: `"grok-5"` (recognised by `parse()`).
  - Placeholder capabilities (conservative guesses):
    - `context_window()``Some(1_000_000)` (conservative floor)
    - `is_reasoning_model()``false` (assumed flexible like Grok 4.3)
    - `supports_reasoning_effort()``true` (assumed continues Grok 4.3 pattern)
    - `supports_logprobs()``false` (assumed new-gen behaviour)
    - `is_language_model()``true`
  - `all()` intentionally **excludes** `Grok5` (has a commented-out line to
    uncomment once xAI officially releases it).
  - `all_including_deprecated()` **includes** `Grok5` for completeness.
  - **Do not use `Model::Grok5` in production** — the API will return an error
    until xAI activates the model.
- **`Cargo.toml` version** bumped `0.1.72``0.1.73`.

### Migration checklist for when Grok 5 actually ships

1. Confirm the real API string and update `as_str()` if it differs from `"grok-5"`.
2. Verify every `// UPDATE WHEN CONFIRMED` comment in `src/models.rs`.
3. Check xAI release notes for new request/response fields.
4. Add `#[deprecated]` to any models being retired.
5. Uncomment `Model::Grok5` in `all()`.
6. Remove the `⚠️ placeholder` warning block from the doc comment.
7. Bump version and publish.

---

## [0.1.72] - 2026-05-31


### Added

- **`Model::GrokBuild0_1`** (`grok-build-0.1`) — xAI's new fast agentic coding model
  (early access, released May 2026). Successor to the retired `grok-code-fast-1`.
  - Context window: **256,000 tokens**.
  - Modalities: text + image input → text output.
  - Built-in reasoning (not user-configurable via `reasoning_effort`).
  - Priced at $1.00 / 1 M input · $2.00 / 1 M output tokens.
  - `parse()` also recognises the legacy aliases `"grok-code-fast"` and
    `"grok-code-fast-1-0825"` and maps them to this variant.
  - **Recommended default for all coding and agentic development workloads.**
- Updated `Model::GrokCodeFast1` deprecation note to point to `GrokBuild0_1`
  (previously pointed to `Grok4_3`) since `grok-build-0.1` is the direct successor.
- **`Cargo.toml` version** bumped `0.1.71``0.1.72`.

### Current active model list (May 2026)

| Variant | API string | Notes |
|---|---|---|
| `Grok4_3` | `grok-4.3` | Flagship; 1M ctx; configurable reasoning effort |
| `GrokBuild0_1` | `grok-build-0.1` | Agentic coding; 256K ctx; built-in reasoning |
| `Grok4_20_0309Reasoning` | `grok-4.20-0309-reasoning` | Pure reasoning; 2M ctx |
| `Grok4_20NonReasoning` | `grok-4.20-non-reasoning` | Fast standard; 2M ctx |
| `Grok4_20_0309NonReasoning` | `grok-4.20-0309-non-reasoning` | Dated 4.20 standard; 2M ctx |
| `Grok4_20MultiAgent0309` | `grok-4.20-multi-agent-0309` | Agentic; 2M ctx |
| `Grok3Mini` | `grok-3-mini` | Legacy efficient; 131K ctx |
| `GrokImagineImage` | `grok-imagine-image` | Standard image gen |
| `GrokImagineVideo` | `grok-imagine-video` | Video gen |

---

## [0.1.71] - 2026-05-15


### Added

- **`Model::Grok4_3`** (`grok-4.3`) — xAI's new flagship model (announced May 2026).
  - Context window: **1,000,000 tokens**.
  - Configurable reasoning via `reasoning_effort` = `"low"` / `"medium"` / `"high"`.
  - Priced at $1.25 / 1 M input · $2.50 / 1 M output.
  - Replaces all retiring Grok 4.1 Fast, Grok 4-0709, Grok Code Fast 1, and Grok 3 workloads.
  - **Recommended default** for all new and migrated workloads.
- **`Model::Grok4_20NonReasoning`** (`grok-4.20-non-reasoning`) — stable (dateless) alias
  for the Grok 4.20 fast non-reasoning model; 2 M token context.
  Recommended replacement for the retiring `grok-4-1-fast-non-reasoning`.
- **`Model::supports_reasoning_effort()`** — returns `true` for models that accept the
  `reasoning_effort` request field (`"low"` / `"medium"` / `"high"`). Currently only
  `Model::Grok4_3` returns `true`.
- **`Model::all_including_deprecated()`** — exhaustive list of all variants, including
  deprecated ones. Useful for migration tooling and full API-string lookup tables.
  (`Model::all()` now returns only active, non-deprecated models.)
- **`ChatRequest::reasoning_effort`** (`Option<String>`) — new field on the request struct.
  Serialised only when `Some`; pass `"low"`, `"medium"`, or `"high"` for `grok-4.3`.
- **`ChatRequestBuilder::reasoning_effort()`** — fluent setter on the request builder,
  allowing callers to control thinking depth per-request:
  ```rust
  client
      .chat_with_history(&messages)
      .model("grok-4.3")
      .reasoning_effort("high")   // ← new
      .send()
      .await?
  ```
- **`DEFAULT_MODEL`** updated to `"grok-4.3"``GrokClient::chat()` and
  `test_connection()` now default to the new flagship instead of the retiring
  `grok-4-1-fast-reasoning`.

### Deprecated (retire 2026-05-15 12:00 PT)

- **`Model::Grok4_1FastReasoning`** (`grok-4-1-fast-reasoning`) — use `Model::Grok4_3`.
- **`Model::Grok4_1FastNonReasoning`** (`grok-4-1-fast-non-reasoning`) — use `Model::Grok4_20NonReasoning`.
- **`Model::Grok4_0709`** (`grok-4-0709`) — use `Model::Grok4_3`.
- **`Model::Grok3`** (`grok-3`) — use `Model::Grok4_3`.
- **`Model::GrokCodeFast1`** (`grok-code-fast-1`) — use `Model::Grok4_3`.
- **`Model::GrokImagineImagePro`** (`grok-imagine-image-pro`) — use `Model::GrokImagineImage`.

  All deprecated variants continue to compile (emitting a `#[deprecated]` warning) and
  continue to work against the xAI API until the retirement date.

### Changed

- `Model::all()` — now returns only **active** (non-deprecated) models, ordered newest →
  oldest. Previously it included all variants. Use `Model::all_including_deprecated()` for
  the old behaviour.
- `Model::supports_logprobs()` — now returns `false` for `Grok4_3` and `Grok4_20NonReasoning`
  (conservative default for the new model generation).
- `Model::context_window()` — returns `Some(1_000_000)` for `Grok4_3`;
  returns `Some(2_000_000)` for `Grok4_20NonReasoning`.
- **`Cargo.toml` version** bumped `0.1.6``0.1.71`.
- All examples updated: `grok-4-1-fast-reasoning``grok-4.3`,
  `grok-code-fast-1``grok-4.3`, `grok-4.20-0309-non-reasoning``grok-4.20-non-reasoning`.

### Current active model list (May 2026)

| Variant | API string | Notes |
|---|---|---|
| `Grok4_3` | `grok-4.3` | New flagship; 1M ctx; configurable reasoning effort |
| `Grok4_20_0309Reasoning` | `grok-4.20-0309-reasoning` | Pure reasoning; 2M ctx |
| `Grok4_20NonReasoning` | `grok-4.20-non-reasoning` | Fast standard; 2M ctx |
| `Grok4_20_0309NonReasoning` | `grok-4.20-0309-non-reasoning` | Dated 4.20 standard; 2M ctx |
| `Grok4_20MultiAgent0309` | `grok-4.20-multi-agent-0309` | Agentic; 2M ctx |
| `Grok3Mini` | `grok-3-mini` | Legacy efficient; 131K ctx |
| `GrokImagineImage` | `grok-imagine-image` | Standard image gen |
| `GrokImagineVideo` | `grok-imagine-video` | Video gen |

### Migration Guide: 0.1.6 → 0.1.71


| Deprecated variant | Retired API string | Use instead |
|---|---|---|
| `Model::Grok4_1FastReasoning` | `grok-4-1-fast-reasoning` | `Model::Grok4_3` |
| `Model::Grok4_1FastNonReasoning` | `grok-4-1-fast-non-reasoning` | `Model::Grok4_20NonReasoning` |
| `Model::Grok4_0709` | `grok-4-0709` | `Model::Grok4_3` |
| `Model::Grok3` | `grok-3` | `Model::Grok4_3` |
| `Model::GrokCodeFast1` | `grok-code-fast-1` | `Model::Grok4_3` |
| `Model::GrokImagineImagePro` | `grok-imagine-image-pro` | `Model::GrokImagineImage` |

```rust
// Before (0.1.6)
let model = Model::Grok4_1FastReasoning;     // now deprecated
// After (0.1.7)
let model = Model::Grok4_3;                  // new recommended default

// Before (0.1.6)
let model = Model::Grok4_1FastNonReasoning;  // now deprecated
// After (0.1.7)
let model = Model::Grok4_20NonReasoning;     // stable 4.20 fast non-reasoning

// Using the new reasoning_effort capability
if model.supports_reasoning_effort() {
    // Set reasoning_effort in your request: "low" | "medium" | "high"
}
```

---

## [0.1.6] - 2025-07-14


### Removed

- **`Model::Grok4FastReasoning`** (`grok-4-fast-reasoning`) — no longer listed as an active
  model in the xAI API. Superseded by `Grok4_1FastReasoning` and the Grok 4.20 family.
- **`Model::Grok4FastNonReasoning`** (`grok-4-fast-non-reasoning`) — same as above.
- **`Model::Grok2Vision1212`** (`grok-2-vision-1212`) — Grok 2 generation retired from the
  active model list.
- **`Model::Grok2Image1212`** (`grok-2-image-1212`) — same as above.

### Changed

- `Model::is_reasoning_model()` — removed `Grok4FastReasoning` from the reasoning set.
- `Model::context_window()` — removed the retired models; `GrokCodeFast1` context window
  updated from 32 K to 131 K tokens to better reflect current behaviour.
- `Model::is_image_model()` — removed `Grok2Image1212` from the image-model set.
- **`Cargo.toml` version** bumped from `0.1.5``0.1.6`.

### Current active model list (April 2026)

| Variant | API string | Notes |
|---|---|---|
| `Grok4_20_0309Reasoning` | `grok-4.20-0309-reasoning` | Flagship reasoning, 2M ctx |
| `Grok4_20_0309NonReasoning` | `grok-4.20-0309-non-reasoning` | Flagship fast, 2M ctx |
| `Grok4_20MultiAgent0309` | `grok-4.20-multi-agent-0309` | Agentic pipelines, 2M ctx |
| `Grok4_1FastReasoning` | `grok-4-1-fast-reasoning` | Best default for CLI/tools |
| `Grok4_1FastNonReasoning` | `grok-4-1-fast-non-reasoning` | Fast standard, 2M ctx |
| `Grok4_0709` | `grok-4-0709` | Previous flagship, still active |
| `Grok3` | `grok-3` | Legacy |
| `Grok3Mini` | `grok-3-mini` | Legacy, efficient |
| `GrokCodeFast1` | `grok-code-fast-1` | Code-optimised |
| `GrokImagineImagePro` | `grok-imagine-image-pro` | High-quality image gen |
| `GrokImagineImage` | `grok-imagine-image` | Standard image gen |
| `GrokImagineVideo` | `grok-imagine-video` | Video generation |

### Migration Guide: 0.1.5 → 0.1.6


If you were using any of the removed variants, switch to the recommended replacements:

| Removed | Replace with |
|---|---|
| `Model::Grok4FastReasoning` | `Model::Grok4_1FastReasoning` |
| `Model::Grok4FastNonReasoning` | `Model::Grok4_1FastNonReasoning` |
| `Model::Grok2Vision1212` | `Model::Grok4_20_0309NonReasoning` (vision via tool) |
| `Model::Grok2Image1212` | `Model::GrokImagineImagePro` |

---

## [0.1.5] - 2025-07-14


### Changed

- **Rust edition upgraded from `2021``2024`** — the library now targets the latest Rust
  edition (stabilized in Rust 1.85). All source files and examples were migrated using
  `cargo fix --edition`.
- **`rust-version` (MSRV) raised from `1.70``1.85`** — required to compile the 2024
  edition. Rust 1.85 has been stable since February 2025.
- **`retry.rs` — fixed `tail_expr_drop_order` lint** (Rust 2024 edition): the temporary
  future created by `operation().await` in the retry loop is now bound to a `let` binding
  before the `match`, which is the canonical fix for the changed temporary drop-order
  semantics introduced in the 2024 edition.

### Migration Guide: 0.1.4 → 0.1.5


No API changes. If you are building this library from source you will need **Rust ≥ 1.85**
(stable). Update your toolchain with:

```
rustup update stable
```

---

## [0.1.4] - 2025-07-14


### Added

- **Grok 4.20 Models** — xAI's newest flagship model family with industry-leading speed,
  agentic tool calling, lowest hallucination rate, and a **2,000,000 token** context window:
  - `Model::Grok4_20_0309Reasoning``"grok-4.20-0309-reasoning"`
  - `Model::Grok4_20_0309NonReasoning``"grok-4.20-0309-non-reasoning"`
  - `Model::Grok4_20MultiAgent0309``"grok-4.20-multi-agent-0309"` (optimised for agentic pipelines)
- **`Model::GrokImagineImagePro`**`"grok-imagine-image-pro"` high-quality image generation model
- **Model capability methods** on `Model` enum:
  - `is_reasoning_model()` — returns `true` for reasoning-only models
  - `supports_frequency_presence_penalty()` — returns `false` for models that reject those fields
  - `supports_logprobs()` — returns `false` for Grok 4.20 models (field is ignored by API)
  - `context_window()` — returns `Some(token_count)` for text models, `None` for gen models
  - `is_language_model()` — distinguishes text models from image/video generation models
  - `is_image_model()` — returns `true` for image generation models
  - `is_video_model()` — returns `true` for video generation models
- **`Usage::cached_prompt_tokens`** (`Option<u32>`) — number of prompt tokens served from
  cache; only present when prompt caching was used (reduces billing cost)
- **`Usage::reasoning_tokens`** (`Option<u32>`) — internal reasoning tokens used by reasoning
  models; only present in responses from reasoning models

### Changed

- **Fixed Grok 4.20 model API strings** — previous enum variants incorrectly included `"beta"`
  in both the variant name and the API identifier string. The official xAI API never used those
  names. Old variants and their corrected replacements:
  | Old (incorrect)                   | New (correct)                   |
  |-----------------------------------|---------------------------------|
  | `Grok4_20MultiAgentBeta0309`      | `Grok4_20MultiAgent0309`        |
  | `Grok4_20Beta0309Reasoning`       | `Grok4_20_0309Reasoning`        |
  | `Grok4_20Beta0309NonReasoning`    | `Grok4_20_0309NonReasoning`     |
- **`Model::all()`** now returns models ordered newest → oldest with section grouping
- **`ChatRequest::frequency_penalty` and `presence_penalty` doc comments** updated with a clear
  warning that reasoning models (Grok 4 and above reasoning variants) will return an API error
  if these fields are sent
- **`Cargo.toml` version** bumped from `0.1.3``0.1.4`

### Migration Guide: 0.1.3 → 0.1.4


**Breaking change — Grok 4.20 enum variant renames:**

If you were using the old (incorrectly named) beta variants, update your code:

```rust
// Before (0.1.3 — incorrect API string)
let model = Model::Grok4_20Beta0309Reasoning;
// → sent "grok-4.20-beta-0309-reasoning" to the API (wrong)

// After (0.1.4 — correct API string)
let model = Model::Grok4_20_0309Reasoning;
// → sends "grok-4.20-0309-reasoning" to the API (correct)
```

**Guard reasoning-model requests against unsupported fields:**

```rust
let mut req = ChatRequest { model: Model::Grok4_20_0309Reasoning.as_str().to_string(), ..Default::default() };

// Safe pattern — only set penalty fields for models that support them
if !Model::Grok4_20_0309Reasoning.is_reasoning_model() {
    req.frequency_penalty = Some(0.5);
    req.presence_penalty  = Some(0.3);
}
```

---

## [0.1.2] - 2025-01-15


### Added

- **Tool/Function Calling Support**: Full implementation of tool calling features
  - Added `tool_call_id` field to `ChatMessage` struct for tool result messages
  - Added `ChatMessage::tool()` constructor for easy tool result creation
  - Added `MessageContent::text()` helper method returning `&str`
  - Implemented `Display` trait for `MessageContent` for direct printing
  - Added `ChatResponse::has_tool_calls()` method to check for tool calls
  - Added 7 comprehensive tests for tool support features
  
- **Documentation**
  - Created `TOOL_SUPPORT.md` (443 lines) - Complete tool usage guide
  - Created `IMPLEMENTATION_CHECKLIST.md` (315 lines) - Task verification
  - Created `TASKS_COMPLETED.md` (302 lines) - Completion report
  - Created `QUICK_REFERENCE.md` (258 lines) - Quick start guide
  - Created `DELIVERY_SUMMARY.md` (410 lines) - Delivery documentation
  
- **Examples**
  - Created `examples/tools_example.rs` - Complete working tool calling example

### Changed

- Updated `rand` dependency from `0.10.0` to `0.9` for stability
- Renamed `Model::from_str()` to `Model::parse()` to avoid trait confusion
- Improved type annotations in `client.rs` for better inference

### Fixed

- Fixed clippy warning: Changed `map_or` to `is_some_and` in `has_tool_calls()`
- Fixed clippy warning: Changed `unwrap_or_else` to `unwrap_or` for simple values
- Fixed rand API usage to use non-deprecated methods (`rng()` and `random_range()`)

### Security

- All dependencies audited and verified clean
- No known security vulnerabilities

## [0.1.1] - 2025-01-14


### Added

- Initial public release
- Core Grok API client implementation
- Chat completion support
- Streaming support
- Model enumeration
- Retry logic with exponential backoff
- Starlink network optimization
- Error handling with custom error types
- Comprehensive examples (simple_chat, conversation, streaming, video_chat)

### Features

- Support for all Grok models (Grok 3, Grok 4, Grok Code Fast, etc.)
- Multimodal support (text, images, videos)
- Configurable retry behavior
- Environment-based configuration
- Full async/await support with Tokio

## [0.1.0] - 2025-01-13


### Added

- Initial development version
- Basic project structure
- Core API types and models
- HTTP client setup with reqwest
- Serialization with serde

---

## Release Notes


### Version 0.1.2 Highlights


This release adds **complete tool/function calling support** to enable AI models to request and use external functions. Key improvements:

**For Developers:**
- Easy tool result creation with `ChatMessage::tool(result, id)`
- Simple content extraction with `MessageContent::text()`
- Direct printing support with `Display` trait
- Comprehensive documentation and examples

**For Integration:**
- Prevents infinite loops in tool calling scenarios
- Maintains proper conversation context
- Type-safe tool handling
- Full test coverage (28/28 tests passing)

**Quality Assurance:**
- Zero compiler warnings
- Clippy clean
- All tests passing
- 100% backward compatible

### Migration Guide: 0.1.1 → 0.1.2


**No breaking changes** - All existing code continues to work.

**To use new tool support:**

```rust
// Before (manual message construction)
ChatMessage {
    role: "tool".to_string(),
    content: Some(MessageContent::Text(result)),
    tool_calls: None,
    tool_call_id: Some(id),
}

// After (using helper)
ChatMessage::tool(result, id)
```

**To extract text content:**

```rust
// Before
if let Some(MessageContent::Text(text)) = &content {
    println!("{}", text);
}

// After
println!("{}", content);  // Display trait
let text = content.text(); // Helper method
```

---

## Links


- [Repository]https://github.com/microtech/grok-api
- [Documentation]https://docs.rs/grok_api
- [Issues]https://github.com/microtech/grok-api/issues
- [Buy me a coffee]https://buymeacoffee.com/micro.tech

## Authors


- John McConnell (john.microtech@gmail.com)

## License


This project is licensed under MIT OR Apache-2.0