Skip to content

Commit 8268267

Browse files
committed
Adding grok-4-1-fast-non-reasoning as default
1 parent b19479e commit 8268267

File tree

5 files changed

+45
-41
lines changed

5 files changed

+45
-41
lines changed

docs/models/grok.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pip/uv-add "pydantic-ai-slim[grok]"
1010

1111
## Configuration
1212

13-
To use Grok from [xAI](https://x.ai/api) through their API, go to [console.x.ai]https://console.x.ai) and follow your nose until you find the place to create an API key.
13+
To use Grok from [xAI](https://x.ai/api) through their API, go your [console.x.ai](https://console.x.ai/team/default/api-keys) and follow your nose until you find the place to create an API key.
1414

1515
## Environment variable
1616

@@ -25,7 +25,7 @@ You can then use `GrokModel` by name:
2525
```python
2626
from pydantic_ai import Agent
2727

28-
agent = Agent('grok:grok-4-fast-non-reasoning')
28+
agent = Agent('grok:grok-4-1-fast-non-reasoning')
2929
...
3030
```
3131

@@ -35,7 +35,7 @@ Or initialise the model directly with just the model name:
3535
from pydantic_ai import Agent
3636
from pydantic_ai.models.grok import GrokModel
3737

38-
model = GrokModel('grok-4-fast-non-reasoning')
38+
model = GrokModel('grok-4-1-fast-non-reasoning')
3939
agent = Agent(model)
4040
...
4141
```
@@ -46,7 +46,7 @@ You can provide your own `api_key` inline like so:
4646
from pydantic_ai import Agent
4747
from pydantic_ai.models.grok import GrokModel
4848

49-
model = GrokModel('grok-4-fast-non-reasoning', api_key='your-api-key')
49+
model = GrokModel('grok-4-1-fast-non-reasoning', api_key='your-api-key')
5050
agent = Agent(model)
5151
...
5252
```
@@ -60,7 +60,7 @@ async_client = AsyncClient(api_key='your-api-key')
6060
from pydantic_ai import Agent
6161
from pydantic_ai.models.grok import GrokModel
6262

63-
model = GrokModel('grok-4-fast-non-reasoning', client=async_client)
63+
model = GrokModel('grok-4-1-fast-non-reasoning', client=async_client)
6464
agent = Agent(model)
6565
...
6666
```

pydantic_ai_slim/pydantic_ai/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@
175175
'grok:grok-3-mini-fast',
176176
'grok:grok-4',
177177
'grok:grok-4-0709',
178+
'grok:grok-4-1-fast-non-reasoning',
179+
'grok:grok-4-1-fast-reasoning',
178180
'grok:grok-4-fast-non-reasoning',
179181
'grok:grok-4-fast-reasoning',
180182
'grok:grok-code-fast-1',

pydantic_ai_slim/pydantic_ai/models/grok.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def __init__(
6363
"""Initialize the Grok model.
6464
6565
Args:
66-
model_name: The name of the Grok model to use (e.g., "grok-3", "grok-4-fast-non-reasoning")
66+
model_name: The name of the Grok model to use (e.g., "grok-4-1-fast-non-reasoning")
6767
api_key: The xAI API key. If not provided, uses XAI_API_KEY environment variable.
6868
client: Optional AsyncClient instance for testing. If provided, api_key is ignored.
6969
settings: Optional model settings.

pydantic_ai_slim/pydantic_ai/providers/grok.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
GrokModelName = Literal[
2626
'grok-4',
2727
'grok-4-0709',
28+
'grok-4-1-fast-reasoning',
29+
'grok-4-1-fast-non-reasoning',
2830
'grok-4-fast-reasoning',
2931
'grok-4-fast-non-reasoning',
3032
'grok-code-fast-1',

tests/models/test_grok.py

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,16 @@
6464

6565

6666
def test_grok_init():
67-
m = GrokModel('grok-4-fast-non-reasoning', api_key='foobar')
67+
m = GrokModel('grok-4-1-fast-non-reasoning', api_key='foobar')
6868
# Check model properties without accessing private attributes
69-
assert m.model_name == 'grok-4-fast-non-reasoning'
69+
assert m.model_name == 'grok-4-1-fast-non-reasoning'
7070
assert m.system == 'xai'
7171

7272

7373
async def test_grok_request_simple_success(allow_model_requests: None):
7474
response = create_response(content='world')
7575
mock_client = MockGrok.create_mock(response)
76-
m = GrokModel('grok-4-fast-non-reasoning', client=mock_client)
76+
m = GrokModel('grok-4-1-fast-non-reasoning', client=mock_client)
7777
agent = Agent(m)
7878

7979
result = await agent.run('hello')
@@ -94,7 +94,7 @@ async def test_grok_request_simple_success(allow_model_requests: None):
9494
),
9595
ModelResponse(
9696
parts=[TextPart(content='world')],
97-
model_name='grok-4-fast-non-reasoning',
97+
model_name='grok-4-1-fast-non-reasoning',
9898
timestamp=IsDatetime(),
9999
provider_name='xai',
100100
provider_response_id='grok-123',
@@ -107,7 +107,7 @@ async def test_grok_request_simple_success(allow_model_requests: None):
107107
),
108108
ModelResponse(
109109
parts=[TextPart(content='world')],
110-
model_name='grok-4-fast-non-reasoning',
110+
model_name='grok-4-1-fast-non-reasoning',
111111
timestamp=IsDatetime(),
112112
provider_name='xai',
113113
provider_response_id='grok-123',
@@ -124,7 +124,7 @@ async def test_grok_request_simple_usage(allow_model_requests: None):
124124
usage=SimpleNamespace(prompt_tokens=2, completion_tokens=1),
125125
)
126126
mock_client = MockGrok.create_mock(response)
127-
m = GrokModel('grok-4-fast-non-reasoning', client=mock_client)
127+
m = GrokModel('grok-4-1-fast-non-reasoning', client=mock_client)
128128
agent = Agent(m)
129129

130130
result = await agent.run('Hello')
@@ -142,7 +142,7 @@ async def test_grok_image_input(allow_model_requests: None):
142142
"""Test that Grok model handles image inputs (text is extracted from content)."""
143143
response = create_response(content='done')
144144
mock_client = MockGrok.create_mock(response)
145-
model = GrokModel('grok-4-fast-non-reasoning', client=mock_client)
145+
model = GrokModel('grok-4-1-fast-non-reasoning', client=mock_client)
146146
agent = Agent(model)
147147

148148
image_url = ImageUrl('https://example.com/image.png')
@@ -160,7 +160,7 @@ async def test_grok_request_structured_response(allow_model_requests: None):
160160
)
161161
response = create_response(tool_calls=[tool_call])
162162
mock_client = MockGrok.create_mock(response)
163-
m = GrokModel('grok-4-fast-non-reasoning', client=mock_client)
163+
m = GrokModel('grok-4-1-fast-non-reasoning', client=mock_client)
164164
agent = Agent(m, output_type=list[int])
165165

166166
result = await agent.run('Hello')
@@ -179,7 +179,7 @@ async def test_grok_request_structured_response(allow_model_requests: None):
179179
tool_call_id='123',
180180
)
181181
],
182-
model_name='grok-4-fast-non-reasoning',
182+
model_name='grok-4-1-fast-non-reasoning',
183183
timestamp=IsDatetime(),
184184
provider_name='xai',
185185
provider_response_id='grok-123',
@@ -214,7 +214,7 @@ async def test_grok_request_tool_call(allow_model_requests: None):
214214
create_response(content='final response'),
215215
]
216216
mock_client = MockGrok.create_mock(responses)
217-
m = GrokModel('grok-4-fast-non-reasoning', client=mock_client)
217+
m = GrokModel('grok-4-1-fast-non-reasoning', client=mock_client)
218218
agent = Agent(m, system_prompt='this is the system prompt')
219219

220220
@agent.tool_plain
@@ -247,7 +247,7 @@ async def get_location(loc_name: str) -> str:
247247
input_tokens=2,
248248
output_tokens=1,
249249
),
250-
model_name='grok-4-fast-non-reasoning',
250+
model_name='grok-4-1-fast-non-reasoning',
251251
timestamp=IsDatetime(),
252252
provider_name='xai',
253253
provider_response_id='grok-123',
@@ -277,7 +277,7 @@ async def get_location(loc_name: str) -> str:
277277
input_tokens=3,
278278
output_tokens=2,
279279
),
280-
model_name='grok-4-fast-non-reasoning',
280+
model_name='grok-4-1-fast-non-reasoning',
281281
timestamp=IsDatetime(),
282282
provider_name='xai',
283283
provider_response_id='grok-123',
@@ -297,7 +297,7 @@ async def get_location(loc_name: str) -> str:
297297
),
298298
ModelResponse(
299299
parts=[TextPart(content='final response')],
300-
model_name='grok-4-fast-non-reasoning',
300+
model_name='grok-4-1-fast-non-reasoning',
301301
timestamp=IsDatetime(),
302302
provider_name='xai',
303303
provider_response_id='grok-123',
@@ -369,7 +369,7 @@ def grok_reasoning_text_chunk(
369369
async def test_grok_stream_text(allow_model_requests: None):
370370
stream = [grok_text_chunk('hello '), grok_text_chunk('world')]
371371
mock_client = MockGrok.create_mock_stream(stream)
372-
m = GrokModel('grok-4-fast-non-reasoning', client=mock_client)
372+
m = GrokModel('grok-4-1-fast-non-reasoning', client=mock_client)
373373
agent = Agent(m)
374374

375375
async with agent.run_stream('') as result:
@@ -387,7 +387,7 @@ async def test_grok_stream_text_finish_reason(allow_model_requests: None):
387387
grok_text_chunk('.', 'stop'),
388388
]
389389
mock_client = MockGrok.create_mock_stream(stream)
390-
m = GrokModel('grok-4-fast-non-reasoning', client=mock_client)
390+
m = GrokModel('grok-4-1-fast-non-reasoning', client=mock_client)
391391
agent = Agent(m)
392392

393393
async with agent.run_stream('') as result:
@@ -402,7 +402,7 @@ async def test_grok_stream_text_finish_reason(allow_model_requests: None):
402402
ModelResponse(
403403
parts=[TextPart(content='hello world.')],
404404
usage=RequestUsage(input_tokens=2, output_tokens=1),
405-
model_name='grok-4-fast-non-reasoning',
405+
model_name='grok-4-1-fast-non-reasoning',
406406
timestamp=IsDatetime(),
407407
provider_name='xai',
408408
provider_response_id='grok-123',
@@ -479,7 +479,7 @@ async def test_grok_stream_structured(allow_model_requests: None):
479479
grok_tool_chunk(None, '}', finish_reason='stop', accumulated_args='{"first": "One", "second": "Two"}'),
480480
]
481481
mock_client = MockGrok.create_mock_stream(stream)
482-
m = GrokModel('grok-4-fast-non-reasoning', client=mock_client)
482+
m = GrokModel('grok-4-1-fast-non-reasoning', client=mock_client)
483483
agent = Agent(m, output_type=MyTypedDict)
484484

485485
async with agent.run_stream('') as result:
@@ -500,7 +500,7 @@ async def test_grok_stream_structured_finish_reason(allow_model_requests: None):
500500
grok_tool_chunk(None, None, finish_reason='stop', accumulated_args='{"first": "One", "second": "Two"}'),
501501
]
502502
mock_client = MockGrok.create_mock_stream(stream)
503-
m = GrokModel('grok-4-fast-non-reasoning', client=mock_client)
503+
m = GrokModel('grok-4-1-fast-non-reasoning', client=mock_client)
504504
agent = Agent(m, output_type=MyTypedDict)
505505

506506
async with agent.run_stream('') as result:
@@ -518,7 +518,7 @@ async def test_grok_stream_native_output(allow_model_requests: None):
518518
grok_text_chunk('}'),
519519
]
520520
mock_client = MockGrok.create_mock_stream(stream)
521-
m = GrokModel('grok-4-fast-non-reasoning', client=mock_client)
521+
m = GrokModel('grok-4-1-fast-non-reasoning', client=mock_client)
522522
agent = Agent(m, output_type=NativeOutput(MyTypedDict))
523523

524524
async with agent.run_stream('') as result:
@@ -537,7 +537,7 @@ async def test_grok_stream_tool_call_with_empty_text(allow_model_requests: None)
537537
grok_tool_chunk(None, '}', finish_reason='stop', accumulated_args='{"first": "One", "second": "Two"}'),
538538
]
539539
mock_client = MockGrok.create_mock_stream(stream)
540-
m = GrokModel('grok-4-fast-non-reasoning', client=mock_client)
540+
m = GrokModel('grok-4-1-fast-non-reasoning', client=mock_client)
541541
agent = Agent(m, output_type=[str, MyTypedDict])
542542

543543
async with agent.run_stream('') as result:
@@ -554,7 +554,7 @@ async def test_grok_no_delta(allow_model_requests: None):
554554
grok_text_chunk('world'),
555555
]
556556
mock_client = MockGrok.create_mock_stream(stream)
557-
m = GrokModel('grok-4-fast-non-reasoning', client=mock_client)
557+
m = GrokModel('grok-4-1-fast-non-reasoning', client=mock_client)
558558
agent = Agent(m)
559559

560560
async with agent.run_stream('') as result:
@@ -571,7 +571,7 @@ async def test_grok_none_delta(allow_model_requests: None):
571571
grok_text_chunk('world'),
572572
]
573573
mock_client = MockGrok.create_mock_stream(stream)
574-
m = GrokModel('grok-4-fast-non-reasoning', client=mock_client)
574+
m = GrokModel('grok-4-1-fast-non-reasoning', client=mock_client)
575575
agent = Agent(m)
576576

577577
async with agent.run_stream('') as result:
@@ -597,7 +597,7 @@ async def test_grok_parallel_tool_calls(allow_model_requests: None, parallel_too
597597
)
598598
response = create_response(content='', tool_calls=[tool_call], finish_reason='tool_calls')
599599
mock_client = MockGrok.create_mock(response)
600-
m = GrokModel('grok-4-fast-non-reasoning', client=mock_client)
600+
m = GrokModel('grok-4-1-fast-non-reasoning', client=mock_client)
601601
agent = Agent(m, output_type=list[int], model_settings=ModelSettings(parallel_tool_calls=parallel_tool_calls))
602602

603603
await agent.run('Hello')
@@ -607,7 +607,7 @@ async def test_grok_parallel_tool_calls(allow_model_requests: None, parallel_too
607607
async def test_grok_penalty_parameters(allow_model_requests: None) -> None:
608608
response = create_response(content='test response')
609609
mock_client = MockGrok.create_mock(response)
610-
m = GrokModel('grok-4-fast-non-reasoning', client=mock_client)
610+
m = GrokModel('grok-4-1-fast-non-reasoning', client=mock_client)
611611

612612
settings = ModelSettings(
613613
temperature=0.7,
@@ -631,7 +631,7 @@ async def test_grok_penalty_parameters(allow_model_requests: None) -> None:
631631
async def test_grok_image_url_input(allow_model_requests: None):
632632
response = create_response(content='world')
633633
mock_client = MockGrok.create_mock(response)
634-
m = GrokModel('grok-4-fast-non-reasoning', client=mock_client)
634+
m = GrokModel('grok-4-1-fast-non-reasoning', client=mock_client)
635635
agent = Agent(m)
636636

637637
result = await agent.run(
@@ -647,7 +647,7 @@ async def test_grok_image_url_input(allow_model_requests: None):
647647

648648
@pytest.mark.skipif(os.getenv('XAI_API_KEY') is None, reason='Requires XAI_API_KEY (gRPC, no cassettes)')
649649
async def test_grok_image_url_tool_response(allow_model_requests: None, xai_api_key: str):
650-
m = GrokModel('grok-4-fast-non-reasoning', api_key=xai_api_key)
650+
m = GrokModel('grok-4-1-fast-non-reasoning', api_key=xai_api_key)
651651
agent = Agent(m)
652652

653653
@agent.tool_plain
@@ -684,7 +684,7 @@ async def get_image() -> ImageUrl:
684684
async def test_grok_image_as_binary_content_tool_response(
685685
allow_model_requests: None, image_content: BinaryContent, xai_api_key: str
686686
):
687-
m = GrokModel('grok-4-fast-non-reasoning', api_key=xai_api_key)
687+
m = GrokModel('grok-4-1-fast-non-reasoning', api_key=xai_api_key)
688688
agent = Agent(m)
689689

690690
@agent.tool_plain
@@ -724,7 +724,7 @@ async def test_grok_image_as_binary_content_input(
724724
allow_model_requests: None, image_content: BinaryContent, xai_api_key: str
725725
):
726726
"""Test passing binary image content directly as input (not from a tool)."""
727-
m = GrokModel('grok-4-fast-non-reasoning', api_key=xai_api_key)
727+
m = GrokModel('grok-4-1-fast-non-reasoning', api_key=xai_api_key)
728728
agent = Agent(m)
729729

730730
result = await agent.run(['What fruit is in the image?', image_content])
@@ -923,7 +923,7 @@ async def test_grok_model_retries(allow_model_requests: None):
923923
success_response = create_response(content='Success after retry')
924924

925925
mock_client = MockGrok.create_mock(success_response)
926-
m = GrokModel('grok-4-fast-non-reasoning', client=mock_client)
926+
m = GrokModel('grok-4-1-fast-non-reasoning', client=mock_client)
927927
agent = Agent(m)
928928
result = await agent.run('hello')
929929
assert result.output == 'Success after retry'
@@ -933,7 +933,7 @@ async def test_grok_model_settings(allow_model_requests: None):
933933
"""Test Grok model with various settings."""
934934
response = create_response(content='response with settings')
935935
mock_client = MockGrok.create_mock(response)
936-
m = GrokModel('grok-4-fast-non-reasoning', client=mock_client)
936+
m = GrokModel('grok-4-1-fast-non-reasoning', client=mock_client)
937937
agent = Agent(
938938
m,
939939
model_settings=ModelSettings(
@@ -965,7 +965,7 @@ async def test_grok_model_multiple_tool_calls(allow_model_requests: None):
965965
]
966966

967967
mock_client = MockGrok.create_mock(responses)
968-
m = GrokModel('grok-4-fast-non-reasoning', client=mock_client)
968+
m = GrokModel('grok-4-1-fast-non-reasoning', client=mock_client)
969969
agent = Agent(m)
970970

971971
@agent.tool_plain
@@ -995,7 +995,7 @@ async def test_grok_stream_with_tool_calls(allow_model_requests: None):
995995
]
996996

997997
mock_client = MockGrok.create_mock_stream([stream1, stream2])
998-
m = GrokModel('grok-4-fast-non-reasoning', client=mock_client)
998+
m = GrokModel('grok-4-1-fast-non-reasoning', client=mock_client)
999999
agent = Agent(m)
10001000

10011001
@agent.tool_plain
@@ -1017,14 +1017,14 @@ async def get_info(query: str) -> str:
10171017
async def test_grok_model_invalid_api_key():
10181018
"""Test Grok model with invalid API key."""
10191019
with pytest.raises(ValueError, match='XAI API key is required'):
1020-
GrokModel('grok-4-fast-non-reasoning', api_key='')
1020+
GrokModel('grok-4-1-fast-non-reasoning', api_key='')
10211021

10221022

10231023
async def test_grok_model_properties():
10241024
"""Test Grok model properties."""
1025-
m = GrokModel('grok-4-fast-non-reasoning', api_key='test-key')
1025+
m = GrokModel('grok-4-1-fast-non-reasoning', api_key='test-key')
10261026

1027-
assert m.model_name == 'grok-4-fast-non-reasoning'
1027+
assert m.model_name == 'grok-4-1-fast-non-reasoning'
10281028
assert m.system == 'xai'
10291029

10301030

0 commit comments

Comments
 (0)