34 timeout=3600,34 timeout=3600,
35)35)
36 36
37chat = client.chat.create(model="grok-4.3")37chat = client.chat.create(model="grok-4.5")
38chat.append(system("You are Grok, an AI agent built to answer helpful questions."))38chat.append(system("You are Grok, an AI agent built to answer helpful questions."))
39chat.append(user("How big is the universe?"))39chat.append(user("How big is the universe?"))
40response = chat.sample()40response = chat.sample()
58)58)
59 59
60response = client.responses.create(60response = client.responses.create(
61 model="grok-4.3",61 model="grok-4.5",
62 input=[62 input=[
63 {"role": "system", "content": "You are Grok, an AI agent built to answer helpful questions."},63 {"role": "system", "content": "You are Grok, an AI agent built to answer helpful questions."},
64 {"role": "user", "content": "How big is the universe?"},64 {"role": "user", "content": "How big is the universe?"},
82});82});
83 83
84const response = await client.responses.create({84const response = await client.responses.create({
85 model: "grok-4.3",85 model: "grok-4.5",
86 input: [86 input: [
87 {87 {
88 role: "system",88 role: "system",
106import { generateText } from 'ai';106import { generateText } from 'ai';
107 107
108const { text, response } = await generateText({108const { text, response } = await generateText({
109 model: xai.responses('grok-4.3'),109 model: xai.responses('grok-4.5'),
110 system: "You are Grok, an AI agent built to answer helpful questions.",110 system: "You are Grok, an AI agent built to answer helpful questions.",
111 prompt: "How big is the universe?",111 prompt: "How big is the universe?",
112});112});
123 -H "Authorization: Bearer $XAI_API_KEY" \123 -H "Authorization: Bearer $XAI_API_KEY" \
124 -m 3600 \124 -m 3600 \
125 -d '{125 -d '{
126 "model": "grok-4.3",126 "model": "grok-4.5",
127 "input": [127 "input": [
128 {128 {
129 "role": "system",129 "role": "system",
152 timeout=3600,152 timeout=3600,
153)153)
154 154
155chat = client.chat.create(model="grok-4.3", store_messages=False)155chat = client.chat.create(model="grok-4.5", store_messages=False)
156chat.append(system("You are Grok, an AI agent built to answer helpful questions."))156chat.append(system("You are Grok, an AI agent built to answer helpful questions."))
157chat.append(user("How big is the universe?"))157chat.append(user("How big is the universe?"))
158response = chat.sample()158response = chat.sample()
172)172)
173 173
174response = client.responses.create(174response = client.responses.create(
175 model="grok-4.3",175 model="grok-4.5",
176 input=[176 input=[
177 {"role": "system", "content": "You are Grok, an AI agent built to answer helpful questions."},177 {"role": "system", "content": "You are Grok, an AI agent built to answer helpful questions."},
178 {"role": "user", "content": "How big is the universe?"},178 {"role": "user", "content": "How big is the universe?"},
193});193});
194 194
195const response = await client.responses.create({195const response = await client.responses.create({
196 model: "grok-4.3",196 model: "grok-4.5",
197 input: [197 input: [
198 {198 {
199 role: "system",199 role: "system",
216 -H "Authorization: Bearer $XAI_API_KEY" \216 -H "Authorization: Bearer $XAI_API_KEY" \
217 -m 3600 \217 -m 3600 \
218 -d '{218 -d '{
219 "model": "grok-4.3",219 "model": "grok-4.5",
220 "input": [220 "input": [
221 {221 {
222 "role": "system",222 "role": "system",
242Modify the steps to create a chat client (xAI SDK) or change the request body as following:242Modify the steps to create a chat client (xAI SDK) or change the request body as following:
243 243
244```python customLanguage="pythonXAI"244```python customLanguage="pythonXAI"
245chat = client.chat.create(model="grok-4.3",245chat = client.chat.create(model="grok-4.5",
246 use_encrypted_content=True)246 use_encrypted_content=True)
247```247```
248 248
249```python customLanguage="pythonOpenAISDK"249```python customLanguage="pythonOpenAISDK"
250response = client.responses.create(250response = client.responses.create(
251 model="grok-4.3",251 model="grok-4.5",
252 input=[252 input=[
253 {"role": "system", "content": "You are Grok, an AI agent built to answer helpful questions."},253 {"role": "system", "content": "You are Grok, an AI agent built to answer helpful questions."},
254 {"role": "user", "content": "How big is the universe?"},254 {"role": "user", "content": "How big is the universe?"},
259 259
260```javascript customLanguage="javascriptWithoutSDK"260```javascript customLanguage="javascriptWithoutSDK"
261const response = await client.responses.create({261const response = await client.responses.create({
262 model: "grok-4.3",262 model: "grok-4.5",
263 input: [263 input: [
264 {"role": "system", "content": "You are Grok, an AI agent built to answer helpful questions."},264 {"role": "system", "content": "You are Grok, an AI agent built to answer helpful questions."},
265 {"role": "user", "content": "How big is the universe?"},265 {"role": "user", "content": "How big is the universe?"},
276// Encrypted reasoning content is included automatically by the AI SDK276// Encrypted reasoning content is included automatically by the AI SDK
277// as long as `store: false` is not set. No extra configuration is needed.277// as long as `store: false` is not set. No extra configuration is needed.
278const { text, reasoning } = await generateText({278const { text, reasoning } = await generateText({
279 model: xai.responses('grok-4.3'),279 model: xai.responses('grok-4.5'),
280 system: "You are Grok, an AI agent built to answer helpful questions.",280 system: "You are Grok, an AI agent built to answer helpful questions.",
281 prompt: "How big is the universe?",281 prompt: "How big is the universe?",
282});282});
291 -H "Authorization: Bearer $XAI_API_KEY" \291 -H "Authorization: Bearer $XAI_API_KEY" \
292 -m 3600 \292 -m 3600 \
293 -d '{293 -d '{
294 "model": "grok-4.3",294 "model": "grok-4.5",
295 "input": [295 "input": [
296 {296 {
297 "role": "system",297 "role": "system",
325 timeout=3600,325 timeout=3600,
326)326)
327 327
328chat = client.chat.create(model="grok-4.3", store_messages=True)328chat = client.chat.create(model="grok-4.5", store_messages=True)
329chat.append(system("You are Grok, an AI agent built to answer helpful questions."))329chat.append(system("You are Grok, an AI agent built to answer helpful questions."))
330chat.append(user("How big is the universe?"))330chat.append(user("How big is the universe?"))
331response = chat.sample()331response = chat.sample()
339# New steps339# New steps
340 340
341chat = client.chat.create(341chat = client.chat.create(
342 model="grok-4.3",342 model="grok-4.5",
343 previous_response_id=response.id,343 previous_response_id=response.id,
344 store_messages=True,344 store_messages=True,
345)345)
366)366)
367 367
368response = client.responses.create(368response = client.responses.create(
369 model="grok-4.3",369 model="grok-4.5",
370 input=[370 input=[
371 {"role": "system", "content": "You are Grok, an AI agent built to answer helpful questions."},371 {"role": "system", "content": "You are Grok, an AI agent built to answer helpful questions."},
372 {"role": "user", "content": "How big is the universe?"},372 {"role": "user", "content": "How big is the universe?"},
382# New steps382# New steps
383 383
384second_response = client.responses.create(384second_response = client.responses.create(
385 model="grok-4.3",385 model="grok-4.5",
386 previous_response_id=response.id,386 previous_response_id=response.id,
387 input=[387 input=[
388 {"role": "user", "content": "How do stars form?"},388 {"role": "user", "content": "How do stars form?"},
407});407});
408 408
409const response = await client.responses.create({409const response = await client.responses.create({
410 model: "grok-4.3",410 model: "grok-4.5",
411 input: [411 input: [
412 {412 {
413 role: "system",413 role: "system",
426console.log(response.id);426console.log(response.id);
427 427
428const secondResponse = await client.responses.create({428const secondResponse = await client.responses.create({
429 model: "grok-4.3",429 model: "grok-4.5",
430 previous_response_id: response.id,430 previous_response_id: response.id,
431 input: [431 input: [
432 {"role": "user", "content": "How do stars form?"},432 {"role": "user", "content": "How do stars form?"},
445 445
446// First request446// First request
447const result = await generateText({447const result = await generateText({
448 model: xai.responses('grok-4.3'),448 model: xai.responses('grok-4.5'),
449 system: "You are Grok, an AI agent built to answer helpful questions.",449 system: "You are Grok, an AI agent built to answer helpful questions.",
450 prompt: "How big is the universe?",450 prompt: "How big is the universe?",
451});451});
457 457
458// Continue the conversation using previousResponseId458// Continue the conversation using previousResponseId
459const { text: secondResponse } = await generateText({459const { text: secondResponse } = await generateText({
460 model: xai.responses('grok-4.3'),460 model: xai.responses('grok-4.5'),
461 prompt: "How do stars form?",461 prompt: "How do stars form?",
462 providerOptions: {462 providerOptions: {
463 xai: {463 xai: {
475 -H "Authorization: Bearer $XAI_API_KEY" \475 -H "Authorization: Bearer $XAI_API_KEY" \
476 -m 3600 \476 -m 3600 \
477 -d '{477 -d '{
478 "model": "grok-4.3",478 "model": "grok-4.5",
479 "previous_response_id": "The previous response ID",479 "previous_response_id": "The previous response ID",
480 "input": [480 "input": [
481 {481 {
505 timeout=3600,505 timeout=3600,
506)506)
507 507
508chat = client.chat.create(model="grok-4.3", store_messages=True, use_encrypted_content=True)508chat = client.chat.create(model="grok-4.5", store_messages=True, use_encrypted_content=True)
509chat.append(system("You are Grok, an AI agent built to answer helpful questions."))509chat.append(system("You are Grok, an AI agent built to answer helpful questions."))
510chat.append(user("How big is the universe?"))510chat.append(user("How big is the universe?"))
511response = chat.sample()511response = chat.sample()
543)543)
544 544
545response = client.responses.create(545response = client.responses.create(
546 model="grok-4.3",546 model="grok-4.5",
547 input=[547 input=[
548 {"role": "system", "content": "You are Grok, an AI agent built to answer helpful questions."},548 {"role": "system", "content": "You are Grok, an AI agent built to answer helpful questions."},
549 {"role": "user", "content": "How big is the universe?"},549 {"role": "user", "content": "How big is the universe?"},
560# New steps560# New steps
561 561
562second_response = client.responses.create(562second_response = client.responses.create(
563 model="grok-4.3",563 model="grok-4.5",
564 input=[564 input=[
565 *response.output, # Use response.output instead of the stored response565 *response.output, # Use response.output instead of the stored response
566 {"role": "user", "content": "How do stars form?"},566 {"role": "user", "content": "How do stars form?"},
585});585});
586 586
587const response = await client.responses.create({587const response = await client.responses.create({
588 model: "grok-4.3",588 model: "grok-4.5",
589 input: [589 input: [
590 {590 {
591 role: "system",591 role: "system",
605console.log(response.id);605console.log(response.id);
606 606
607const secondResponse = await client.responses.create({607const secondResponse = await client.responses.create({
608 model: "grok-4.3",608 model: "grok-4.5",
609 input: [609 input: [
610 ...response.output, // Use response.output instead of the stored response610 ...response.output, // Use response.output instead of the stored response
611 {"role": "user", "content": "How do stars form?"},611 {"role": "user", "content": "How do stars form?"},
625// First request. Encrypted reasoning content is included automatically625// First request. Encrypted reasoning content is included automatically
626// by the AI SDK as long as `store: false` is not set.626// by the AI SDK as long as `store: false` is not set.
627const result = await generateText({627const result = await generateText({
628 model: xai.responses('grok-4.3'),628 model: xai.responses('grok-4.5'),
629 system: "You are Grok, an AI agent built to answer helpful questions.",629 system: "You are Grok, an AI agent built to answer helpful questions.",
630 prompt: "How big is the universe?",630 prompt: "How big is the universe?",
631});631});
635// Continue the conversation using previousResponseId635// Continue the conversation using previousResponseId
636// The encrypted content is automatically included when using previousResponseId636// The encrypted content is automatically included when using previousResponseId
637const { text: secondResponse } = await generateText({637const { text: secondResponse } = await generateText({
638 model: xai.responses('grok-4.3'),638 model: xai.responses('grok-4.5'),
639 prompt: "How do stars form?",639 prompt: "How do stars form?",
640 providerOptions: {640 providerOptions: {
641 xai: {641 xai: {
653 -H "Authorization: Bearer $XAI_API_KEY" \653 -H "Authorization: Bearer $XAI_API_KEY" \
654 -m 3600 \654 -m 3600 \
655 -d '{655 -d '{
656 "model": "grok-4.3",656 "model": "grok-4.5",
657 "input": [657 "input": [
658 {658 {
659 "role": "system",659 "role": "system",