SpyBara
Go Premium

Documentation 2026-07-06 22:58 UTC to 2026-07-08 18:58 UTC

37 files changed +436 −292. View all changes and history on the product overview
2026
Thu 9 13:03 Wed 8 18:58 Mon 6 22:58 Sat 4 20:00 Thu 2 16:59 Wed 1 19:00
Details

29 timeout=3600, # Override default timeout with longer timeout for reasoning models29 timeout=3600, # Override default timeout with longer timeout for reasoning models

30 )30 )

31 31 

32 model = "grok-4.3"32 model = "grok-4.5"

33 requests = [33 requests = [

34 "Tell me a joke",34 "Tell me a joke",

35 "Write a funny haiku",35 "Write a funny haiku",


78 # The 'async with sem' ensures only a limited number of requests run at once78 # The 'async with sem' ensures only a limited number of requests run at once

79 async with sem:79 async with sem:

80 return await client.chat.completions.create(80 return await client.chat.completions.create(

81 model="grok-4.3",81 model="grok-4.5",

82 messages=[{"role": "user", "content": request}]82 messages=[{"role": "user", "content": request}]

83 )83 )

84 84 

Details

111 111 

112# Chat completion with tools112# Chat completion with tools

113chat = client.chat.create(113chat = client.chat.create(

114 model="grok-4.3",114 model="grok-4.5",

115 batch_request_id="chat_001",115 batch_request_id="chat_001",

116 tools=[web_search(), x_search()],116 tools=[web_search(), x_search()],

117)117)


165 165 

166# Remote MCP166# Remote MCP

167mcp_chat = client.chat.create(167mcp_chat = client.chat.create(

168 model="grok-4.3",168 model="grok-4.5",

169 batch_request_id="mcp_001",169 batch_request_id="mcp_001",

170 tools=[mcp(server_url="https://mcp.deepwiki.com/mcp")],170 tools=[mcp(server_url="https://mcp.deepwiki.com/mcp")],

171)171)


191 {"role": "system", "content": "Classify the sentiment as positive, negative, or neutral."},191 {"role": "system", "content": "Classify the sentiment as positive, negative, or neutral."},

192 {"role": "user", "content": "The product exceeded my expectations!"}192 {"role": "user", "content": "The product exceeded my expectations!"}

193 ],193 ],

194 "model": "grok-4.3"194 "model": "grok-4.5"

195 }195 }

196 }196 }

197 },197 },


203 {"role": "system", "content": "Classify the sentiment as positive, negative, or neutral."},203 {"role": "system", "content": "Classify the sentiment as positive, negative, or neutral."},

204 {"role": "user", "content": "Shipping took way too long."}204 {"role": "user", "content": "Shipping took way too long."}

205 ],205 ],

206 "model": "grok-4.3"206 "model": "grok-4.5"

207 }207 }

208 }208 }

209 }209 }


219 batch_request_id: "chat_001",219 batch_request_id: "chat_001",

220 batch_request: {220 batch_request: {

221 responses: {221 responses: {

222 model: "grok-4.3",222 model: "grok-4.5",

223 tools: [{ type: "web_search" }, { type: "x_search" }],223 tools: [{ type: "web_search" }, { type: "x_search" }],

224 input: [224 input: [

225 { role: "system", content: "Analyze market sentiment from recent news and posts." },225 { role: "system", content: "Analyze market sentiment from recent news and posts." },


293 batch_request_id: "mcp_001",293 batch_request_id: "mcp_001",

294 batch_request: {294 batch_request: {

295 responses: {295 responses: {

296 model: "grok-4.3",296 model: "grok-4.5",

297 tools: [{ type: "mcp", server_label: "deepwiki", server_url: "https://mcp.deepwiki.com/mcp" }],297 tools: [{ type: "mcp", server_label: "deepwiki", server_url: "https://mcp.deepwiki.com/mcp" }],

298 input: [{ role: "user", content: "What does the xai-sdk-python repo do?" }],298 input: [{ role: "user", content: "What does the xai-sdk-python repo do?" }],

299 },299 },


710batch_requests = []710batch_requests = []

711for item in feedback_data:711for item in feedback_data:

712 chat = client.chat.create(712 chat = client.chat.create(

713 model="grok-4.3",713 model="grok-4.5",

714 batch_request_id=item["id"],714 batch_request_id=item["id"],

715 )715 )

716 chat.append(system(716 chat.append(system(


793 batch_request_id: item.id,793 batch_request_id: item.id,

794 batch_request: {794 batch_request: {

795 chat_get_completion: {795 chat_get_completion: {

796 model: "grok-4.3",796 model: "grok-4.5",

797 messages: [797 messages: [

798 {798 {

799 role: "system",799 role: "system",

Details

35 -H "Content-Type: application/json" \35 -H "Content-Type: application/json" \

36 -H "Authorization: Bearer $XAI_API_KEY" \36 -H "Authorization: Bearer $XAI_API_KEY" \

37 -d '{37 -d '{

38 "model": "grok-4.3",38 "model": "grok-4.5",

39 "input": [39 "input": [

40 {"role": "system", "content": "You are a concise and knowledgeable science tutor."},40 {"role": "system", "content": "You are a concise and knowledgeable science tutor."},

41 {"role": "user", "content": "What is the Higgs boson and why is it important?"},41 {"role": "user", "content": "What is the Higgs boson and why is it important?"},


50 -H "Content-Type: application/json" \50 -H "Content-Type: application/json" \

51 -H "Authorization: Bearer $XAI_API_KEY" \51 -H "Authorization: Bearer $XAI_API_KEY" \

52 -d '{52 -d '{

53 "model": "grok-4.3",53 "model": "grok-4.5",

54 "input": [54 "input": [

55 {55 {

56 "type": "compaction",56 "type": "compaction",


72# Build up a chat normally — system prompt plus a few user/assistant turns.72# Build up a chat normally — system prompt plus a few user/assistant turns.

73# use_encrypted_content=True is recommended for reasoning models so the model's73# use_encrypted_content=True is recommended for reasoning models so the model's

74# reasoning content from prior turns is preserved through the compaction.74# reasoning content from prior turns is preserved through the compaction.

75chat = client.chat.create(model="grok-4.3", use_encrypted_content=True)75chat = client.chat.create(model="grok-4.5", use_encrypted_content=True)

76chat.append(system("You are a concise and knowledgeable science tutor."))76chat.append(system("You are a concise and knowledgeable science tutor."))

77 77 

78chat.append(user("What is the Higgs boson and why is it important?"))78chat.append(user("What is the Higgs boson and why is it important?"))


86# Step 1 — compact the conversation. Pass the chat's accumulated messages86# Step 1 — compact the conversation. Pass the chat's accumulated messages

87# straight into compact_context.87# straight into compact_context.

88compact = client.chat.compact_context(88compact = client.chat.compact_context(

89 model="grok-4.3",89 model="grok-4.5",

90 messages=chat.messages,90 messages=chat.messages,

91)91)

92print(f"Compaction ID: {compact.id}")92print(f"Compaction ID: {compact.id}")


113 113 

114# Step 1 — compact the long conversation114# Step 1 — compact the long conversation

115compacted = client.responses.compact(115compacted = client.responses.compact(

116 model="grok-4.3",116 model="grok-4.5",

117 input=[117 input=[

118 {"role": "system", "content": "You are a concise and knowledgeable science tutor."},118 {"role": "system", "content": "You are a concise and knowledgeable science tutor."},

119 {"role": "user", "content": "What is the Higgs boson and why is it important?"},119 {"role": "user", "content": "What is the Higgs boson and why is it important?"},


129 129 

130# Step 2 — continue the conversation. Spread compacted.output into the next input.130# Step 2 — continue the conversation. Spread compacted.output into the next input.

131followup = client.responses.create(131followup = client.responses.create(

132 model="grok-4.3",132 model="grok-4.5",

133 input=[133 input=[

134 *compacted.output, # use the compaction item verbatim — do not modify134 *compacted.output, # use the compaction item verbatim — do not modify

135 {"role": "user", "content": "Based on our earlier conversation, what gives particles their mass?"},135 {"role": "user", "content": "Based on our earlier conversation, what gives particles their mass?"},


149 149 

150// Step 1 — compact the long conversation150// Step 1 — compact the long conversation

151const compacted = await client.responses.compact({151const compacted = await client.responses.compact({

152 model: "grok-4.3",152 model: "grok-4.5",

153 input: [153 input: [

154 { role: "system", content: "You are a concise and knowledgeable science tutor." },154 { role: "system", content: "You are a concise and knowledgeable science tutor." },

155 { role: "user", content: "What is the Higgs boson and why is it important?" },155 { role: "user", content: "What is the Higgs boson and why is it important?" },


165 165 

166// Step 2 — continue the conversation. Spread compacted.output into the next input.166// Step 2 — continue the conversation. Spread compacted.output into the next input.

167const followup = await client.responses.create({167const followup = await client.responses.create({

168 model: "grok-4.3",168 model: "grok-4.5",

169 input: [169 input: [

170 ...compacted.output, // use the compaction item verbatim — do not modify170 ...compacted.output, // use the compaction item verbatim — do not modify

171 { role: "user", content: "Based on our earlier conversation, what gives particles their mass?" },171 { role: "user", content: "Based on our earlier conversation, what gives particles their mass?" },


186 "id": "cmp_01HZ9P0V8M2YQK3F7C4G6N5R2A",186 "id": "cmp_01HZ9P0V8M2YQK3F7C4G6N5R2A",

187 "object": "response.compaction",187 "object": "response.compaction",

188 "created_at": 1748895600,188 "created_at": 1748895600,

189 "model": "grok-4.3",189 "model": "grok-4.5",

190 "output": [190 "output": [

191 {191 {

192 "type": "compaction",192 "type": "compaction",


233 233 

234# use_encrypted_content=True preserves the model's reasoning content across234# use_encrypted_content=True preserves the model's reasoning content across

235# turns, recommended when using reasoning models.235# turns, recommended when using reasoning models.

236chat = client.chat.create(model="grok-4.3", use_encrypted_content=True)236chat = client.chat.create(model="grok-4.5", use_encrypted_content=True)

237chat.append(system("You are a helpful assistant. Keep answers brief."))237chat.append(system("You are a helpful assistant. Keep answers brief."))

238 238 

239compact_every = 5239compact_every = 5

Details

36client = Client(api_key=os.getenv('XAI_API_KEY'))36client = Client(api_key=os.getenv('XAI_API_KEY'))

37 37 

38chat = client.chat.create(38chat = client.chat.create(

39 model="grok-4.3",39 model="grok-4.5",

40 messages=[system("You are Zaphod Beeblebrox.")]40 messages=[system("You are Zaphod Beeblebrox.")]

41)41)

42chat.append(user("126/3=?"))42chat.append(user("126/3=?"))


69 {"role": "system", "content": "You are Zaphod Beeblebrox."},69 {"role": "system", "content": "You are Zaphod Beeblebrox."},

70 {"role": "user", "content": "126/3=?"}70 {"role": "user", "content": "126/3=?"}

71 ],71 ],

72 "model": "grok-4.3",72 "model": "grok-4.5",

73 "deferred": True73 "deferred": True

74}74}

75 75 


109 { role: 'system', content: 'You are Zaphod Beeblebrox.' },109 { role: 'system', content: 'You are Zaphod Beeblebrox.' },

110 { role: 'user', content: '126/3=?' }110 { role: 'user', content: '126/3=?' }

111 ],111 ],

112 model: 'grok-4.3',112 model: 'grok-4.5',

113 deferred: true113 deferred: true

114};114};

115 115 


149 {"role": "system", "content": "You are Zaphod Beeblebrox."},149 {"role": "system", "content": "You are Zaphod Beeblebrox."},

150 {"role": "user", "content": "126/3=?"}150 {"role": "user", "content": "126/3=?"}

151 ],151 ],

152 "model": "grok-4.3",152 "model": "grok-4.5",

153 "deferred": true153 "deferred": true

154}')154}')

155 155 


169 "id": "3f4ddfca-b997-3bd4-80d4-8112278a1508",169 "id": "3f4ddfca-b997-3bd4-80d4-8112278a1508",

170 "object": "chat.completion",170 "object": "chat.completion",

171 "created": 1752077400,171 "created": 1752077400,

172 "model": "grok-4.3",172 "model": "grok-4.5",

173 "choices": [173 "choices": [

174 {174 {

175 "index": 0,175 "index": 0,

Details

47 "content": "Hello, world!"47 "content": "Hello, world!"

48 }48 }

49 ],49 ],

50 "model": "grok-4.3",50 "model": "grok-4.5",

51 "stream": false51 "stream": false

52 }'52 }'

53```53```


69)69)

70 70 

71completion = client.chat.completions.create(71completion = client.chat.completions.create(

72 model="grok-4.3",72 model="grok-4.5",

73 messages=[73 messages=[

74 {"role": "user", "content": "Hello, world!"}74 {"role": "user", "content": "Hello, world!"}

75 ]75 ]


92});92});

93 93 

94const completion = await client.chat.completions.create({94const completion = await client.chat.completions.create({

95 model: 'grok-4.3',95 model: 'grok-4.5',

96 messages: [96 messages: [

97 { role: 'user', content: 'Hello, world!' }97 { role: 'user', content: 'Hello, world!' }

98 ],98 ],

Details

28 -H "Authorization: Bearer $XAI_API_KEY" \28 -H "Authorization: Bearer $XAI_API_KEY" \

29 -H "Content-Type: application/json" \29 -H "Content-Type: application/json" \

30 -d '{30 -d '{

31 "model": "grok-4.3",31 "model": "grok-4.5",

32 "input": "Explain the Riemann hypothesis in one paragraph.",32 "input": "Explain the Riemann hypothesis in one paragraph.",

33 "service_tier": "priority"33 "service_tier": "priority"

34 }'34 }'


43client = Client(api_key=os.getenv("XAI_API_KEY"))43client = Client(api_key=os.getenv("XAI_API_KEY"))

44 44 

45chat = client.chat.create(45chat = client.chat.create(

46 model="grok-4.3",46 model="grok-4.5",

47 service_tier="priority",47 service_tier="priority",

48)48)

49chat.append(user("Explain the Riemann hypothesis in one paragraph."))49chat.append(user("Explain the Riemann hypothesis in one paragraph."))


64)64)

65 65 

66response = client.responses.create(66response = client.responses.create(

67 model="grok-4.3",67 model="grok-4.5",

68 input="Explain the Riemann hypothesis in one paragraph.",68 input="Explain the Riemann hypothesis in one paragraph.",

69 service_tier="priority",69 service_tier="priority",

70)70)


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: "Explain the Riemann hypothesis in one paragraph.",86 input: "Explain the Riemann hypothesis in one paragraph.",

87 service_tier: "priority",87 service_tier: "priority",

88});88});


96```json customLanguage="json"96```json customLanguage="json"

97{97{

98 "id": "resp_abc123",98 "id": "resp_abc123",

99 "model": "grok-4.3",99 "model": "grok-4.5",

100 "service_tier": "priority",100 "service_tier": "priority",

101 "usage": {101 "usage": {

102 "input_tokens": 42,102 "input_tokens": 42,

Details

12 -H "Authorization: Bearer $XAI_API_KEY" \12 -H "Authorization: Bearer $XAI_API_KEY" \

13 -H "x-grok-conv-id: conv_abc123" \13 -H "x-grok-conv-id: conv_abc123" \

14 -d '{14 -d '{

15 "model": "grok-4.3",15 "model": "grok-4.5",

16 "messages": [16 "messages": [

17 {"role": "system", "content": "You are Grok, a helpful and truthful AI assistant built by xAI."},17 {"role": "system", "content": "You are Grok, a helpful and truthful AI assistant built by xAI."},

18 {"role": "user", "content": "What is prompt caching?"}18 {"role": "user", "content": "What is prompt caching?"}


29)29)

30 30 

31response = client.chat.completions.create(31response = client.chat.completions.create(

32 model="grok-4.3",32 model="grok-4.5",

33 messages=[33 messages=[

34 {"role": "system", "content": "You are Grok, a helpful and truthful AI assistant built by xAI."},34 {"role": "system", "content": "You are Grok, a helpful and truthful AI assistant built by xAI."},

35 {"role": "user", "content": "What is prompt caching?"},35 {"role": "user", "content": "What is prompt caching?"},


53 53 

54const response = await client.chat.completions.create(54const response = await client.chat.completions.create(

55 {55 {

56 model: 'grok-4.3',56 model: 'grok-4.5',

57 messages: [57 messages: [

58 {58 {

59 role: 'system',59 role: 'system',


85 -H "Content-Type: application/json" \85 -H "Content-Type: application/json" \

86 -H "Authorization: Bearer $XAI_API_KEY" \86 -H "Authorization: Bearer $XAI_API_KEY" \

87 -d '{87 -d '{

88 "model": "grok-4.3",88 "model": "grok-4.5",

89 "input": "What is prompt caching?",89 "input": "What is prompt caching?",

90 "prompt_cache_key": "b79ad29b-b3f9-463c-bca6-041d5058d366"90 "prompt_cache_key": "b79ad29b-b3f9-463c-bca6-041d5058d366"

91 }'91 }'


100)100)

101 101 

102response = client.responses.create(102response = client.responses.create(

103 model="grok-4.3",103 model="grok-4.5",

104 input="What is prompt caching?",104 input="What is prompt caching?",

105 extra_body={105 extra_body={

106 "prompt_cache_key": "b79ad29b-b3f9-463c-bca6-041d5058d366",106 "prompt_cache_key": "b79ad29b-b3f9-463c-bca6-041d5058d366",


120});120});

121 121 

122const response = await client.responses.create({122const response = await client.responses.create({

123 model: 'grok-4.3',123 model: 'grok-4.5',

124 input: 'What is prompt caching?',124 input: 'What is prompt caching?',

125 // @ts-expect-error -- xAI-specific field125 // @ts-expect-error -- xAI-specific field

126 prompt_cache_key: 'b79ad29b-b3f9-463c-bca6-041d5058d366',126 prompt_cache_key: 'b79ad29b-b3f9-463c-bca6-041d5058d366',


137import { generateText } from 'ai';137import { generateText } from 'ai';

138 138 

139const { text, usage } = await generateText({139const { text, usage } = await generateText({

140 model: xai.responses('grok-4.3'),140 model: xai.responses('grok-4.5'),

141 prompt: 'What is prompt caching?',141 prompt: 'What is prompt caching?',

142 providerOptions: {142 providerOptions: {

143 xai: {143 xai: {


163 metadata=(("x-grok-conv-id", "conv_abc123"),),163 metadata=(("x-grok-conv-id", "conv_abc123"),),

164)164)

165 165 

166chat = client.chat.create(model="grok-4.3")166chat = client.chat.create(model="grok-4.5")

167chat.append(system("You are Grok, a helpful and truthful AI assistant built by xAI."))167chat.append(system("You are Grok, a helpful and truthful AI assistant built by xAI."))

168chat.append(user("What is prompt caching?"))168chat.append(user("What is prompt caching?"))

169 169 

Details

24 -H "Authorization: Bearer $XAI_API_KEY" \24 -H "Authorization: Bearer $XAI_API_KEY" \

25 -H "x-grok-conv-id: conv_abc123" \25 -H "x-grok-conv-id: conv_abc123" \

26 -d '{26 -d '{

27 "model": "grok-4.3",27 "model": "grok-4.5",

28 "messages": [28 "messages": [

29 {"role": "system", "content": "You are Grok, a helpful and truthful AI assistant built by xAI."},29 {"role": "system", "content": "You are Grok, a helpful and truthful AI assistant built by xAI."},

30 {"role": "user", "content": "What is prompt caching?"},30 {"role": "user", "content": "What is prompt caching?"},


38 -H "Authorization: Bearer $XAI_API_KEY" \38 -H "Authorization: Bearer $XAI_API_KEY" \

39 -H "x-grok-conv-id: conv_abc123" \39 -H "x-grok-conv-id: conv_abc123" \

40 -d '{40 -d '{

41 "model": "grok-4.3",41 "model": "grok-4.5",

42 "messages": [42 "messages": [

43 {"role": "system", "content": "You are Grok, a helpful and truthful AI assistant built by xAI."},43 {"role": "system", "content": "You are Grok, a helpful and truthful AI assistant built by xAI."},

44 {"role": "user", "content": "What is prompt caching?"},44 {"role": "user", "content": "What is prompt caching?"},


64 64 

65# Turn 1: Initial request (establishes the cache)65# Turn 1: Initial request (establishes the cache)

66response = client.chat.completions.create(66response = client.chat.completions.create(

67 model="grok-4.3",67 model="grok-4.5",

68 messages=messages,68 messages=messages,

69 extra_headers={"x-grok-conv-id": conversation_id},69 extra_headers={"x-grok-conv-id": conversation_id},

70)70)


76 76 

77# Turn 2: Cache HIT — prefix is unchanged, only new messages appended77# Turn 2: Cache HIT — prefix is unchanged, only new messages appended

78response = client.chat.completions.create(78response = client.chat.completions.create(

79 model="grok-4.3",79 model="grok-4.5",

80 messages=messages,80 messages=messages,

81 extra_headers={"x-grok-conv-id": conversation_id},81 extra_headers={"x-grok-conv-id": conversation_id},

82)82)


103 103 

104// Turn 1: Initial request (establishes the cache)104// Turn 1: Initial request (establishes the cache)

105const turn1 = await client.chat.completions.create(105const turn1 = await client.chat.completions.create(

106 { model: 'grok-4.3', messages },106 { model: 'grok-4.5', messages },

107 { headers: { 'x-grok-conv-id': conversationId } },107 { headers: { 'x-grok-conv-id': conversationId } },

108);108);

109console.log(109console.log(


117 117 

118// Turn 2: Cache HIT — prefix unchanged, new message appended118// Turn 2: Cache HIT — prefix unchanged, new message appended

119const turn2 = await client.chat.completions.create(119const turn2 = await client.chat.completions.create(

120 { model: 'grok-4.3', messages },120 { model: 'grok-4.5', messages },

121 { headers: { 'x-grok-conv-id': conversationId } },121 { headers: { 'x-grok-conv-id': conversationId } },

122);122);

123console.log(123console.log(


136 -H "Authorization: Bearer $XAI_API_KEY" \136 -H "Authorization: Bearer $XAI_API_KEY" \

137 -H "x-grok-conv-id: conv_abc123" \137 -H "x-grok-conv-id: conv_abc123" \

138 -d '{138 -d '{

139 "model": "grok-4.3",139 "model": "grok-4.5",

140 "messages": [140 "messages": [

141 {"role": "system", "content": "You are Grok, a helpful and truthful AI assistant built by xAI."},141 {"role": "system", "content": "You are Grok, a helpful and truthful AI assistant built by xAI."},

142 {"role": "user", "content": "What is prompt caching?"},142 {"role": "user", "content": "What is prompt caching?"},


160 -H "Authorization: Bearer $XAI_API_KEY" \160 -H "Authorization: Bearer $XAI_API_KEY" \

161 -H "x-grok-conv-id: conv_abc123" \161 -H "x-grok-conv-id: conv_abc123" \

162 -d '{162 -d '{

163 "model": "grok-4.3",163 "model": "grok-4.5",

164 "messages": [164 "messages": [

165 {"role": "system", "content": "You are Grok, a helpful and truthful AI assistant built by xAI."},165 {"role": "system", "content": "You are Grok, a helpful and truthful AI assistant built by xAI."},

166 {"role": "user", "content": "What is prompt caching?"},166 {"role": "user", "content": "What is prompt caching?"},


183 -H "Authorization: Bearer $XAI_API_KEY" \183 -H "Authorization: Bearer $XAI_API_KEY" \

184 -H "x-grok-conv-id: conv_abc123" \184 -H "x-grok-conv-id: conv_abc123" \

185 -d '{185 -d '{

186 "model": "grok-4.3",186 "model": "grok-4.5",

187 "messages": [187 "messages": [

188 {"role": "user", "content": "What is prompt caching?"},188 {"role": "user", "content": "What is prompt caching?"},

189 {"role": "system", "content": "You are Grok, a helpful and truthful AI assistant built by xAI."},189 {"role": "system", "content": "You are Grok, a helpful and truthful AI assistant built by xAI."},

Details

44 json.dumps(44 json.dumps(

45 {45 {

46 "type": "response.create",46 "type": "response.create",

47 "model": "grok-4.3",47 "model": "grok-4.5",

48 "store": False,48 "store": False,

49 "input": [49 "input": [

50 {50 {


72 ws.send(72 ws.send(

73 JSON.stringify({73 JSON.stringify({

74 type: "response.create",74 type: "response.create",

75 model: "grok-4.3",75 model: "grok-4.5",

76 store: false,76 store: false,

77 input: [77 input: [

78 {78 {


112 json.dumps(112 json.dumps(

113 {113 {

114 "type": "response.create",114 "type": "response.create",

115 "model": "grok-4.3",115 "model": "grok-4.5",

116 "store": False,116 "store": False,

117 "previous_response_id": "resp_123",117 "previous_response_id": "resp_123",

118 "input": [118 "input": [


137ws.send(137ws.send(

138 JSON.stringify({138 JSON.stringify({

139 type: "response.create",139 type: "response.create",

140 model: "grok-4.3",140 model: "grok-4.5",

141 store: false,141 store: false,

142 previous_response_id: "resp_123",142 previous_response_id: "resp_123",

143 input: [143 input: [

community.md +2 −2

Details

20 20 

21os.environ['XAI_API_KEY'] = ""21os.environ['XAI_API_KEY'] = ""

22response = completion(22response = completion(

23 model="xai/grok-4.3",23 model="xai/grok-4.5",

24 messages=[24 messages=[

25 {25 {

26 "role": "user",26 "role": "user",


50import { generateText } from 'ai';50import { generateText } from 'ai';

51 51 

52const { text } = await generateText({52const { text } = await generateText({

53 model: xai.responses('grok-4.3'),53 model: xai.responses('grok-4.5'),

54 prompt: 'Write a vegetarian lasagna recipe for 4 people.',54 prompt: 'Write a vegetarian lasagna recipe for 4 people.',

55});55});

56```56```

Details

45 45 

46Use the model ID shown in Model Garden. Vertex model names may use a publisher prefix, for example:46Use the model ID shown in Model Garden. Vertex model names may use a publisher prefix, for example:

47 47 

48* `xai/grok-4.3`48* `xai/grok-4.5`

49 49 

50Model availability generally matches the xAI API, subject to Google Cloud regional availability and quotas.50Model availability generally matches the xAI API, subject to Google Cloud regional availability and quotas.

51 51 


71client = OpenAI() # Uses ADC / env vars automatically71client = OpenAI() # Uses ADC / env vars automatically

72 72 

73response = client.responses.create(73response = client.responses.create(

74 model="xai/grok-4.3",74 model="xai/grok-4.5",

75 input="Explain the advantages of using Grok for agentic workflows with parallel tool calling.",75 input="Explain the advantages of using Grok for agentic workflows with parallel tool calling.",

76 max_output_tokens=800,76 max_output_tokens=800,

77)77)


87client = OpenAI()87client = OpenAI()

88 88 

89response = client.chat.completions.create(89response = client.chat.completions.create(

90 model="xai/grok-4.3",90 model="xai/grok-4.5",

91 messages=[91 messages=[

92 {92 {

93 "role": "user",93 "role": "user",

cost-tracking.md +11 −11

Details

32client = Client(api_key=os.getenv("XAI_API_KEY"))32client = Client(api_key=os.getenv("XAI_API_KEY"))

33 33 

34chat = client.chat.create(34chat = client.chat.create(

35 model="grok-4.3",35 model="grok-4.5",

36 messages=[user("Say hello")],36 messages=[user("Say hello")],

37)37)

38response = chat.sample()38response = chat.sample()


62 -H "Authorization: Bearer $XAI_API_KEY" \62 -H "Authorization: Bearer $XAI_API_KEY" \

63 -H "Content-Type: application/json" \63 -H "Content-Type: application/json" \

64 -d '{64 -d '{

65 "model": "grok-4.3",65 "model": "grok-4.5",

66 "input": "Say hello"66 "input": "Say hello"

67 }' | jq '.usage.cost_in_usd_ticks'67 }' | jq '.usage.cost_in_usd_ticks'

68```68```


77)77)

78 78 

79completion = client.chat.completions.create(79completion = client.chat.completions.create(

80 model="grok-4.3",80 model="grok-4.5",

81 messages=[{"role": "user", "content": "Say hello"}],81 messages=[{"role": "user", "content": "Say hello"}],

82)82)

83 83 


96});96});

97 97 

98const completion = await client.chat.completions.create({98const completion = await client.chat.completions.create({

99 model: "grok-4.3",99 model: "grok-4.5",

100 messages: [{ role: "user", content: "Say hello" }],100 messages: [{ role: "user", content: "Say hello" }],

101});101});

102 102 


123client = Client(api_key=os.getenv("XAI_API_KEY"))123client = Client(api_key=os.getenv("XAI_API_KEY"))

124 124 

125chat = client.chat.create(125chat = client.chat.create(

126 model="grok-4.3",126 model="grok-4.5",

127 messages=[user("Tell me a joke")],127 messages=[user("Tell me a joke")],

128)128)

129 129 


145)145)

146 146 

147stream = client.chat.completions.create(147stream = client.chat.completions.create(

148 model="grok-4.3",148 model="grok-4.5",

149 messages=[{"role": "user", "content": "Tell me a joke"}],149 messages=[{"role": "user", "content": "Tell me a joke"}],

150 stream=True,150 stream=True,

151 stream_options={"include_usage": True},151 stream_options={"include_usage": True},


171client = Client(api_key=os.getenv("XAI_API_KEY"))171client = Client(api_key=os.getenv("XAI_API_KEY"))

172 172 

173chat = client.chat.create(173chat = client.chat.create(

174 model="grok-4.3",174 model="grok-4.5",

175 messages=[system("You are a helpful assistant.")],175 messages=[system("You are a helpful assistant.")],

176)176)

177 177 


211 211 

212 messages.append({"role": "user", "content": prompt})212 messages.append({"role": "user", "content": prompt})

213 completion = client.chat.completions.create(213 completion = client.chat.completions.create(

214 model="grok-4.3",214 model="grok-4.5",

215 messages=messages,215 messages=messages,

216 )216 )

217 217 


240client = Client(api_key=os.getenv("XAI_API_KEY"))240client = Client(api_key=os.getenv("XAI_API_KEY"))

241 241 

242chat = client.chat.create(242chat = client.chat.create(

243 model="grok-4.3",243 model="grok-4.5",

244 tools=[web_search(), x_search()],244 tools=[web_search(), x_search()],

245)245)

246chat.append(user("What are people saying about xAI's latest announcement?"))246chat.append(user("What are people saying about xAI's latest announcement?"))


264)264)

265 265 

266response = client.responses.create(266response = client.responses.create(

267 model="grok-4.3",267 model="grok-4.5",

268 input="What are people saying about xAI's latest announcement?",268 input="What are people saying about xAI's latest announcement?",

269 tools=[269 tools=[

270 {"type": "web_search"},270 {"type": "web_search"},


284 -H "Authorization: Bearer $XAI_API_KEY" \284 -H "Authorization: Bearer $XAI_API_KEY" \

285 -H "Content-Type: application/json" \285 -H "Content-Type: application/json" \

286 -d '{286 -d '{

287 "model": "grok-4.3",287 "model": "grok-4.5",

288 "tools": [{"type": "web_search"}, {"type": "x_search"}],288 "tools": [{"type": "web_search"}, {"type": "x_search"}],

289 "input": "What are people saying about xAI'\''s latest announcement?"289 "input": "What are people saying about xAI'\''s latest announcement?"

290 }' | jq '{tools_used: .usage.num_server_side_tools_used, cost_in_usd_ticks: .usage.cost_in_usd_ticks}'290 }' | jq '{tools_used: .usage.num_server_side_tools_used, cost_in_usd_ticks: .usage.cost_in_usd_ticks}'

files.md +3 −3

Details

78)78)

79 79 

80# 2. Chat with files80# 2. Chat with files

81chat = client.chat.create(model="grok-4.3")81chat = client.chat.create(model="grok-4.5")

82chat.append(user(82chat.append(user(

83 "Summarize both documents",83 "Summarize both documents",

84 file(url=file_url),84 file(url=file_url),


117 Authorization: \`Bearer \${process.env.XAI_API_KEY}\`,117 Authorization: \`Bearer \${process.env.XAI_API_KEY}\`,

118 },118 },

119 body: JSON.stringify({119 body: JSON.stringify({

120 model: "grok-4.3",120 model: "grok-4.5",

121 input: [121 input: [

122 {122 {

123 role: "user",123 role: "user",


162 162 

163* **File size**: Maximum 48 MB per file163* **File size**: Maximum 48 MB per file

164* **No batch requests**: File attachments with document search are agentic requests and do not support batch mode (`n > 1`)164* **No batch requests**: File attachments with document search are agentic requests and do not support batch mode (`n > 1`)

165* **Agentic models only**: Requires models that support agentic tool calling (e.g., `grok-4.20`, `grok-4.3`)165* **Agentic models only**: Requires models that support agentic tool calling (e.g., `grok-4.20`, `grok-4.5`)

166* **Supported file formats**:166* **Supported file formats**:

167 * Plain text files (.txt)167 * Plain text files (.txt)

168 * Markdown files (.md)168 * Markdown files (.md)

grok-4-5.md +107 −0 created

Details

1#### Get Started

2 

3# grok-4.5

4 

5Grok 4.5 is SpaceXAI's frontier model built for coding, agentic tasks, and knowledge work. It was trained in SpaceXAI's data centers in Memphis with new datasets spanning science, engineering, and math.

6 

7> Grok 4.5 isn't available in the API console for EU users yet. Availability is expected later this month.

8 

9## Using the API

10 

11If you already have an [API key](https://console.x.ai/team/default/api-keys), set the model name to `grok-4.5`:

12 

13```python customLanguage="pythonXAI"

14import os

15from xai_sdk import Client

16from xai_sdk.chat import user

17 

18client = Client(api_key=os.getenv("XAI_API_KEY"))

19 

20chat = client.chat.create(model="grok-4.5")

21chat.append(user("Find and fix the bug, then explain it: function median(a){a.sort();return a[a.length/2]}"))

22 

23response = chat.sample()

24print(response.content)

25```

26 

27```javascript customLanguage="javascriptAISDK"

28import { xai } from '@ai-sdk/xai';

29import { generateText } from 'ai';

30 

31const { text } = await generateText({

32 model: xai.responses('grok-4.5'),

33 prompt:

34 'Find and fix the bug, then explain it: function median(a){a.sort();return a[a.length/2]}',

35});

36 

37console.log(text);

38```

39 

40```javascript customLanguage="javascriptOpenAISDK"

41import OpenAI from 'openai';

42 

43const client = new OpenAI({

44 apiKey: process.env.XAI_API_KEY,

45 baseURL: 'https://api.x.ai/v1',

46});

47 

48const response = await client.responses.create({

49 model: 'grok-4.5',

50 input: [

51 {

52 role: 'user',

53 content:

54 'Find and fix the bug, then explain it: function median(a){a.sort();return a[a.length/2]}',

55 },

56 ],

57});

58 

59console.log(response.output_text);

60```

61 

62```bash customLanguage="bash"

63curl https://api.x.ai/v1/responses \

64 -H "Content-Type: application/json" \

65 -H "Authorization: Bearer $XAI_API_KEY" \

66 -d '{

67 "model": "grok-4.5",

68 "input": "Find and fix the bug, then explain it: function median(a){a.sort();return a[a.length/2]}"

69 }'

70```

71 

72New to the xAI API? Follow the [Quickstart](/developers/quickstart) to create an account and make your first request.

73 

74## At a glance

75 

76| Property | Value |

77|----------|-------|

78| Model name | `grok-4.5` |

79| Input price | $2.00 / 1M tokens |

80| Output price | $6.00 / 1M tokens |

81| Reasoning | Low, medium, or high (default high) |

82| APIs | [Responses API](/developers/rest-api-reference/inference/chat#create-new-response), [Chat Completions](/developers/rest-api-reference/inference/chat#chat-completions) |

83| Tools | [Function calling](/developers/tools/function-calling), [web search](/developers/tools/web-search), [X search](/developers/tools/x-search), [code execution](/developers/tools/code-execution) |

84 

85Full context window, rate limits, and live pricing for your team are on the [model detail page](/developers/models/grok-4.5) and [Pricing](/developers/pricing).

86 

87For benchmark results and cost-versus-score comparisons, see the [announcement](https://x.ai/news/grok-4-5).

88 

89## Important details

90 

91* **We highly recommend setting a [`prompt_cache_key`](/developers/advanced-api-usage/prompt-caching/maximizing-cache-hits)** (Responses API; `x-grok-conv-id` header on Chat Completions). It routes a conversation's requests to the same server, making cache hits reliable; without it you often pay full input price on a cache-cold server. See [What Breaks Caching](/developers/advanced-api-usage/prompt-caching/multi-turn) for common mistakes.

92* **Long agent loops** additionally benefit from [context compaction](/developers/advanced-api-usage/context-compaction); for tool-heavy workloads see [function calling](/developers/tools/function-calling).

93 

94## Where it runs

95 

96* **xAI API**: get a key from the [console](https://console.x.ai/)

97* **Grok Build**: the default model of the [coding agent](/build/overview), on the API and CLI

98* **Cursor**: available on all plans

99* **Office add-ins**: default model in the Word, PowerPoint, and Excel add-ins

100* **Model gateways**: OpenRouter, Vercel, Cloudflare, Snowflake, and Databricks Mosaic

101 

102## Learn more

103 

104* [Reasoning](/developers/model-capabilities/text/reasoning#the-reasoning_effort-parameter) - controlling `reasoning_effort`

105* [Announcement](https://x.ai/news/grok-4-5) - launch post with demos and full benchmark figures

106* [Models](/developers/models) - compare available models and their capabilities

107* [Pricing](/developers/pricing) - token pricing for all models

Details

33 33 

34And to specify models the API key has access to:34And to specify models the API key has access to:

35 35 

36* `api-key:model:<model name such as grok-4.3>`36* `api-key:model:<model name such as grok-4.5>`

37 37 

38### Create an API key38### Create an API key

39 39 

Details

161| `audio.output.format.type` | string | Output format: `"audio/pcm"`, `"audio/pcmu"`, or `"audio/pcma"` |161| `audio.output.format.type` | string | Output format: `"audio/pcm"`, `"audio/pcmu"`, or `"audio/pcma"` |

162| `audio.output.format.rate` | number | Output sample rate (PCM only): 8000, 16000, 22050, 24000, 32000, 44100, 48000 |162| `audio.output.format.rate` | number | Output sample rate (PCM only): 8000, 16000, 22050, 24000, 32000, 44100, 48000 |

163| `audio.input.transcription.language_hint` | string | BCP-47 language code (e.g. `"ja"`, `"ar"`, `"es-MX"`, `"pt-BR"`) to bias ASR transcription toward a specific language. Can be updated mid-session. See [Language Hint](#language-hint). |163| `audio.input.transcription.language_hint` | string | BCP-47 language code (e.g. `"ja"`, `"ar"`, `"es-MX"`, `"pt-BR"`) to bias ASR transcription toward a specific language. Can be updated mid-session. See [Language Hint](#language-hint). |

164| `audio.input.transcription.keyterms` | array | List of key terms (e.g. product names, proper nouns) to bias transcription toward. Max 100 terms, each up to 50 characters. Can be updated mid-session. See [Keyterms](#keyterms). |

164| `audio.output.speed` | number | Playback speed multiplier for assistant audio output. Range: 0.7–1.5. Default: `1.0`. Values below 1.0 slow down speech; values above 1.0 speed it up. |165| `audio.output.speed` | number | Playback speed multiplier for assistant audio output. Range: 0.7–1.5. Default: `1.0`. Values below 1.0 slow down speech; values above 1.0 speed it up. |

165| `replace` | object | optional | Map of phrases to spoken substitutions applied to the model's output before TTS, e.g. `{"Acme Mobile": "Acme Mobull"}`. Fixes pronunciation by changing the spoken audio without altering the transcript. See [Pronunciation Replacements](#pronunciation-replacements). |166| `replace` | object | optional | Map of phrases to spoken substitutions applied to the model's output before TTS, e.g. `{"Acme Mobile": "Acme Mobull"}`. Fixes pronunciation by changing the spoken audio without altering the transcript. See [Pronunciation Replacements](#pronunciation-replacements). |

166 167 


511}));512}));

512```513```

513 514 

515### Keyterms

516 

517Bias transcription toward domain-specific vocabulary — product names, proper nouns, brand names, or technical terms that the model might otherwise mis-transcribe — by setting `audio.input.transcription.keyterms` in `session.update`. Provide an array of strings, up to 100 terms with each term up to 50 characters. Keyterms can be updated mid-session.

518 

519```pythonWithoutSDK

520await ws.send(json.dumps({

521 "type": "session.update",

522 "session": {

523 "audio": {

524 "input": {

525 "transcription": {

526 "keyterms": ["xAI", "Grok", "Understand The Universe"]

527 }

528 }

529 }

530 }

531}))

532```

533 

534```javascriptWithoutSDK

535ws.send(JSON.stringify({

536 type: "session.update",

537 session: {

538 audio: {

539 input: {

540 transcription: {

541 keyterms: ["xAI", "Grok", "Understand The Universe"]

542 }

543 }

544 }

545 }

546}));

547```

548 

514## Using Tools with Grok Voice Agent API549## Using Tools with Grok Voice Agent API

515 550 

516The Grok Voice Agent API supports various tools that can be configured in your session to enhance the capabilities of your voice agent. Tools can be configured in the `session.update` message.551The Grok Voice Agent API supports various tools that can be configured in your session to enhance the capabilities of your voice agent. Tools can be configured in the `session.update` message.


578 },613 },

579 {614 {

580 "type": "x_search",615 "type": "x_search",

581 "allowed_x_handles": ["elonmusk", "xai"],

582 },616 },

583 ],617 ],

584 },618 },


596 },630 },

597 {631 {

598 type: "x_search",632 type: "x_search",

599 allowed_x_handles: ["elonmusk", "xai"],

600 },633 },

601 ],634 ],

602 },635 },

Details

34client = Client(api_key=os.getenv("XAI_API_KEY"))34client = Client(api_key=os.getenv("XAI_API_KEY"))

35 35 

36# Attach a file by public URL (or use file(file_id) for uploaded files)36# Attach a file by public URL (or use file(file_id) for uploaded files)

37chat = client.chat.create(model="grok-4.3")37chat = client.chat.create(model="grok-4.5")

38chat.append(user(38chat.append(user(

39 "What was the total revenue in this report?",39 "What was the total revenue in this report?",

40 file(url="https://docs.x.ai/assets/api-examples/documents/sales-report.txt"),40 file(url="https://docs.x.ai/assets/api-examples/documents/sales-report.txt"),


57 57 

58# Attach a file by public URL (or use file_id for uploaded files)58# Attach a file by public URL (or use file_id for uploaded files)

59response = client.responses.create(59response = client.responses.create(

60 model="grok-4.3",60 model="grok-4.5",

61 input=[61 input=[

62 {62 {

63 "role": "user",63 "role": "user",


86# Attach a file by public URL (or use file_id for uploaded files)86# Attach a file by public URL (or use file_id for uploaded files)

87chat_url = "https://api.x.ai/v1/responses"87chat_url = "https://api.x.ai/v1/responses"

88payload = {88payload = {

89 "model": "grok-4.3",89 "model": "grok-4.5",

90 "input": [90 "input": [

91 {91 {

92 "role": "user",92 "role": "user",


111 111 

112// Attach a file by public URL (or use file_id for uploaded files)112// Attach a file by public URL (or use file_id for uploaded files)

113const response = await client.responses.create({113const response = await client.responses.create({

114 model: "grok-4.3",114 model: "grok-4.5",

115 input: [115 input: [

116 {116 {

117 role: "user",117 role: "user",


133 -H "Authorization: Bearer $XAI_API_KEY" \\133 -H "Authorization: Bearer $XAI_API_KEY" \\

134 -H "Content-Type: application/json" \\134 -H "Content-Type: application/json" \\

135 -d '{135 -d '{

136 "model": "grok-4.3",136 "model": "grok-4.5",

137 "input": [137 "input": [

138 {138 {

139 "role": "user",139 "role": "user",


158client = Client(api_key=os.getenv("XAI_API_KEY"))158client = Client(api_key=os.getenv("XAI_API_KEY"))

159 159 

160# Attach a file by public URL (or use file(file_id) for uploaded files)160# Attach a file by public URL (or use file(file_id) for uploaded files)

161chat = client.chat.create(model="grok-4.3")161chat = client.chat.create(model="grok-4.5")

162chat.append(user(162chat.append(user(

163 "What is the weight of the XR-2000?",163 "What is the weight of the XR-2000?",

164 file(url="https://docs.x.ai/assets/api-examples/documents/product-specs.txt"),164 file(url="https://docs.x.ai/assets/api-examples/documents/product-specs.txt"),


194 194 

195// Attach a file by public URL (or use file_id for uploaded files)195// Attach a file by public URL (or use file_id for uploaded files)

196const stream = await client.responses.create({196const stream = await client.responses.create({

197 model: "grok-4.3",197 model: "grok-4.5",

198 input: [198 input: [

199 {199 {

200 role: "user",200 role: "user",


228client = Client(api_key=os.getenv("XAI_API_KEY"))228client = Client(api_key=os.getenv("XAI_API_KEY"))

229 229 

230# Attach files by public URL (or use file(file_id) for uploaded files)230# Attach files by public URL (or use file(file_id) for uploaded files)

231chat = client.chat.create(model="grok-4.3")231chat = client.chat.create(model="grok-4.5")

232chat.append(232chat.append(

233 user(233 user(

234 "Based on these documents, when did the project start, what is the budget, and how many people are on the team?",234 "Based on these documents, when did the project start, what is the budget, and how many people are on the team?",


254 254 

255// Attach files by public URL (or use file_id for uploaded files)255// Attach files by public URL (or use file_id for uploaded files)

256const response = await client.responses.create({256const response = await client.responses.create({

257 model: "grok-4.3",257 model: "grok-4.5",

258 input: [258 input: [

259 {259 {

260 role: "user",260 role: "user",


289 289 

290# Create a multi-turn conversation with encrypted content290# Create a multi-turn conversation with encrypted content

291chat = client.chat.create(291chat = client.chat.create(

292 model="grok-4.3",292 model="grok-4.5",

293 use_encrypted_content=True, # Enable encrypted content for efficient multi-turn293 use_encrypted_content=True, # Enable encrypted content for efficient multi-turn

294)294)

295 295 


333 333 

334// First turn: Ask about the document334// First turn: Ask about the document

335const response1 = await client.responses.create({335const response1 = await client.responses.create({

336 model: "grok-4.3",336 model: "grok-4.5",

337 input: [337 input: [

338 {338 {

339 role: "user",339 role: "user",


350 350 

351// Second turn: Ask about department (uses previous_response_id for context)351// Second turn: Ask about department (uses previous_response_id for context)

352const response2 = await client.responses.create({352const response2 = await client.responses.create({

353 model: "grok-4.3",353 model: "grok-4.5",

354 previous_response_id: response1.id,354 previous_response_id: response1.id,

355 input: [355 input: [

356 { role: "user", content: "What department does this employee work in?" },356 { role: "user", content: "What department does this employee work in?" },


362 362 

363// Third turn: Ask about skills363// Third turn: Ask about skills

364const response3 = await client.responses.create({364const response3 = await client.responses.create({

365 model: "grok-4.3",365 model: "grok-4.5",

366 previous_response_id: response2.id,366 previous_response_id: response2.id,

367 input: [367 input: [

368 { role: "user", content: "What skills does this employee have?" },368 { role: "user", content: "What skills does this employee have?" },


385client = Client(api_key=os.getenv("XAI_API_KEY"))385client = Client(api_key=os.getenv("XAI_API_KEY"))

386 386 

387# Attach files by public URL (or use file(file_id) for uploaded files)387# Attach files by public URL (or use file(file_id) for uploaded files)

388chat = client.chat.create(model="grok-4.3")388chat = client.chat.create(model="grok-4.5")

389chat.append(389chat.append(

390 user(390 user(

391 "Based on the attached care guide, do you have any advice about the pictured cat?",391 "Based on the attached care guide, do you have any advice about the pictured cat?",


409 409 

410// Attach files by public URL (or use file_id for uploaded files)410// Attach files by public URL (or use file_id for uploaded files)

411const response = await client.responses.create({411const response = await client.responses.create({

412 model: "grok-4.3",412 model: "grok-4.5",

413 input: [413 input: [

414 {414 {

415 role: "user",415 role: "user",


446 446 

447# Attach a file by public URL (or use file(file_id) for uploaded files)447# Attach a file by public URL (or use file(file_id) for uploaded files)

448chat = client.chat.create(448chat = client.chat.create(

449 model="grok-4.3",449 model="grok-4.5",

450 tools=[code_execution()], # Enable code execution450 tools=[code_execution()], # Enable code execution

451)451)

452 452 


487 487 

488// Attach a file by public URL (or use file_id for uploaded files)488// Attach a file by public URL (or use file_id for uploaded files)

489const stream = await client.responses.create({489const stream = await client.responses.create({

490 model: "grok-4.3",490 model: "grok-4.5",

491 input: [491 input: [

492 {492 {

493 role: "user",493 role: "user",


538 538 

539### Model Compatibility539### Model Compatibility

540 540 

541* **Recommended model**: `grok-4.3` for best document understanding541* **Recommended model**: `grok-4.5` for best document understanding

542* **Agentic requirement**: File attachments require [agentic-capable](/developers/tools/overview) models that support server-side tools.542* **Agentic requirement**: File attachments require [agentic-capable](/developers/tools/overview) models that support server-side tools.

543 543 

544## Next Steps544## Next Steps

Details

58)58)

59 59 

60image_url = "https://science.nasa.gov/wp-content/uploads/2023/09/web-first-images-release.png"60image_url = "https://science.nasa.gov/wp-content/uploads/2023/09/web-first-images-release.png"

61chat = client.chat.create(model="grok-4.3")61chat = client.chat.create(model="grok-4.5")

62chat.append(62chat.append(

63 user(63 user(

64 "What's in this image?",64 "What's in this image?",


89)89)

90 90 

91response = client.responses.create(91response = client.responses.create(

92 model="grok-4.3",92 model="grok-4.5",

93 input=[93 input=[

94 {94 {

95 "role": "user",95 "role": "user",


128 "https://science.nasa.gov/wp-content/uploads/2023/09/web-first-images-release.png";128 "https://science.nasa.gov/wp-content/uploads/2023/09/web-first-images-release.png";

129 129 

130const response = await client.responses.create({130const response = await client.responses.create({

131 model: "grok-4.3",131 model: "grok-4.5",

132 input: [132 input: [

133 {133 {

134 role: "user",134 role: "user",


158import { generateText } from 'ai';158import { generateText } from 'ai';

159 159 

160const { text, response } = await generateText({160const { text, response } = await generateText({

161 model: xai.responses('grok-4.3'),161 model: xai.responses('grok-4.5'),

162 messages: [162 messages: [

163 {163 {

164 role: 'user',164 role: 'user',


188 -H "Authorization: Bearer $XAI_API_KEY" \188 -H "Authorization: Bearer $XAI_API_KEY" \

189 -m 3600 \189 -m 3600 \

190 -d '{190 -d '{

191 "model": "grok-4.3",191 "model": "grok-4.5",

192 "input": [192 "input": [

193 {193 {

194 "role": "user",194 "role": "user",

Details

33 timeout=3600, # Override default timeout with longer timeout for reasoning models33 timeout=3600, # Override default timeout with longer timeout for reasoning models

34)34)

35 35 

36chat = client.chat.create(model="grok-4.3")36chat = client.chat.create(model="grok-4.5")

37chat.append(system("You are a PhD-level mathematician."))37chat.append(system("You are a PhD-level mathematician."))

38chat.append(user("What is 2 + 2?"))38chat.append(user("What is 2 + 2?"))

39 39 


53)53)

54 54 

55completion = client.chat.completions.create(55completion = client.chat.completions.create(

56 model="grok-4.3",56 model="grok-4.5",

57 messages=[57 messages=[

58 {"role": "system", "content": "You are a PhD-level mathematician."},58 {"role": "system", "content": "You are a PhD-level mathematician."},

59 {"role": "user", "content": "What is 2 + 2?"},59 {"role": "user", "content": "What is 2 + 2?"},


73});73});

74 74 

75const completion = await client.chat.completions.create({75const completion = await client.chat.completions.create({

76 model: "grok-4.3",76 model: "grok-4.5",

77 messages: [77 messages: [

78 {78 {

79 role: "system",79 role: "system",


94import { generateText } from 'ai';94import { generateText } from 'ai';

95 95 

96const result = await generateText({96const result = await generateText({

97 model: xai('grok-4.3'),97 model: xai('grok-4.5'),

98 system:98 system:

99 "You are Grok, a helpful and maximally truthful AI built by xAI.",99 "You are Grok, a helpful and maximally truthful AI built by xAI.",

100 prompt: 'Explain how neural networks learn in two sentences.',100 prompt: 'Explain how neural networks learn in two sentences.',


119 "content": "Explain how neural networks learn in two sentences."119 "content": "Explain how neural networks learn in two sentences."

120 }120 }

121 ],121 ],

122 "model": "grok-4.3",122 "model": "grok-4.5",

123 "stream": false123 "stream": false

124}'124}'

125```125```


169 "id": "0daf962f-a275-4a3c-839a-047854645532",169 "id": "0daf962f-a275-4a3c-839a-047854645532",

170 "object": "chat.completion",170 "object": "chat.completion",

171 "created": 1739301120,171 "created": 1739301120,

172 "model": "grok-4.3",172 "model": "grok-4.5",

173 "choices": [173 "choices": [

174 {174 {

175 "index": 0,175 "index": 0,

Details

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",

Details

18 18 

19## The `reasoning_effort` parameter19## The `reasoning_effort` parameter

20 20 

21`grok-4.3` supports the `reasoning_effort` parameter, which controls how much effort the model spends thinking before responding.21`grok-4.5` supports the `reasoning_effort` parameter, which controls how much effort the model spends thinking before responding.

22 22 

23If not specified, `reasoning_effort` defaults to `"low"`. If set to `"none"`, no reasoning will occur.23If not specified, `reasoning_effort` defaults to `"high"`. Reasoning cannot be disabled.

24 24 

25`presencePenalty`, `frequencyPenalty`, and `stop` cannot be used with reasoning models. Requests that include them return an error.25`presencePenalty`, `frequencyPenalty`, and `stop` cannot be used with reasoning models. Requests that include them return an error.

26 26 


28 28 

29| Setting | Description | Best For |29| Setting | Description | Best For |

30|---|---|---|30|---|---|---|

31| `"none"` | Disables reasoning entirely; no thinking tokens are used | Simple use cases that require a near-instant response. |31| `"low"` | Uses some reasoning tokens, but still fast | Latency-sensitive agentic use and simple tool calling. |

32| `"low"` (default) | Uses some reasoning tokens, but still fast | General agentic use and tool calling. |

33| `"medium"` | More thinking for less-latency sensitive applications | Complex data analysis and long-context reasoning. |32| `"medium"` | More thinking for less-latency sensitive applications | Complex data analysis and long-context reasoning. |

34| `"high"` | Uses more reasoning tokens for deeper thinking | Very challenging problems, complex math, multi-step logic, competition-level tasks |33| `"high"` (default) | Uses more reasoning tokens for deeper thinking | Very challenging problems, complex math, multi-step logic, competition-level tasks |

35 34 

36### Setting reasoning effort35### Setting reasoning effort

37 36 

38The following example sets `reasoning_effort` to `"high"` for a challenging math proof. You can substitute `"none"`, `"low"`, or `"medium"` as needed.37The following example sets `reasoning_effort` to `"high"` for a challenging math proof. You can substitute `"low"` or `"medium"` as needed.

39 38 

40```python customLanguage="pythonXAI" highlightedLines="13"39```python customLanguage="pythonXAI" highlightedLines="13"

41import os40import os


49)48)

50 49 

51chat = client.chat.create(50chat = client.chat.create(

52 model="grok-4.3",51 model="grok-4.5",

53 reasoning_effort="high",52 reasoning_effort="high",

54 messages=[system("You are a highly intelligent AI assistant.")],53 messages=[system("You are a highly intelligent AI assistant.")],

55)54)


73)72)

74 73 

75response = client.responses.create(74response = client.responses.create(

76 model="grok-4.3",75 model="grok-4.5",

77 reasoning={"effort": "high"},76 reasoning={"effort": "high"},

78 input=[77 input=[

79 {"role": "system", "content": "You are a highly intelligent AI assistant."},78 {"role": "system", "content": "You are a highly intelligent AI assistant."},


93import { generateText } from 'ai';92import { generateText } from 'ai';

94 93 

95const result = await generateText({94const result = await generateText({

96 model: xai.responses('grok-4.3'),95 model: xai.responses('grok-4.5'),

97 system: 'You are a highly intelligent AI assistant.',96 system: 'You are a highly intelligent AI assistant.',

98 prompt: 'Find all prime numbers p such that p^2 + 2 is also prime. Prove your answer.',97 prompt: 'Find all prime numbers p such that p^2 + 2 is also prime. Prove your answer.',

99 providerOptions: {98 providerOptions: {


110 -H "Authorization: Bearer $XAI_API_KEY" \109 -H "Authorization: Bearer $XAI_API_KEY" \

111 -m 3600 \110 -m 3600 \

112 -d '{111 -d '{

113 "model": "grok-4.3",112 "model": "grok-4.5",

114 "reasoning": {"effort": "high"},113 "reasoning": {"effort": "high"},

115 "input": [114 "input": [

116 {115 {


133 132 

134| Model | `reasoning` parameter | Behavior |133| Model | `reasoning` parameter | Behavior |

135|---|---|---|134|---|---|---|

136| `grok-4.3` | `reasoning.effort`: `"none"` / `"low"` (default) / `"medium"` / `"high"` | Controls reasoning depth (`"none"` disables it) |135| `grok-4.5` | `reasoning.effort`: `"low"` / `"medium"` / `"high"` (default) | Controls reasoning depth (cannot be disabled) |

137| `grok-4.20-multi-agent` | `reasoning.effort`: `"low"` / `"medium"` / `"high"` / `"xhigh"` | Controls agent count (4 or 16) |136| `grok-4.20-multi-agent` | `reasoning.effort`: `"low"` / `"medium"` / `"high"` / `"xhigh"` | Controls agent count (4 or 16) |

138 137 

139## Summarized Reasoning Content138## Summarized Reasoning Content

140 139 

141For `grok-4.3`, we expose summarizations of the model's internal reasoning. Here's an example of how to stream the reasoning summary deltas alongside the final response:140For `grok-4.5`, we expose summarizations of the model's internal reasoning. Here's an example of how to stream the reasoning summary deltas alongside the final response:

142 141 

143```python customLanguage="pythonXAI"142```python customLanguage="pythonXAI"

144import os143import os


152)151)

153 152 

154chat = client.chat.create(153chat = client.chat.create(

155 model="grok-4.3",154 model="grok-4.5",

156 messages=[system("You are a highly intelligent AI assistant.")],155 messages=[system("You are a highly intelligent AI assistant.")],

157)156)

158chat.append(user("A projectile is launched at 30 m/s at 37° above horizontal from a 45 m cliff. Find its speed on impact. (g=10 m/s²)"))157chat.append(user("A projectile is launched at 30 m/s at 37° above horizontal from a 45 m cliff. Find its speed on impact. (g=10 m/s²)"))


179)178)

180 179 

181stream = client.responses.create(180stream = client.responses.create(

182 model="grok-4.3",181 model="grok-4.5",

183 input=[182 input=[

184 {"role": "system", "content": "You are a highly intelligent AI assistant."},183 {"role": "system", "content": "You are a highly intelligent AI assistant."},

185 {"role": "user", "content": "A projectile is launched at 30 m/s at 37° above horizontal from a 45 m cliff. Find its speed on impact. (g=10 m/s²)"},184 {"role": "user", "content": "A projectile is launched at 30 m/s at 37° above horizontal from a 45 m cliff. Find its speed on impact. (g=10 m/s²)"},


198import { streamText } from 'ai';197import { streamText } from 'ai';

199 198 

200const result = streamText({199const result = streamText({

201 model: xai.responses('grok-4.3'),200 model: xai.responses('grok-4.5'),

202 system: 'You are a highly intelligent AI assistant.',201 system: 'You are a highly intelligent AI assistant.',

203 prompt: 'A projectile is launched at 30 m/s at 37° above horizontal from a 45 m cliff. Find its speed on impact. (g=10 m/s²)'202 prompt: 'A projectile is launched at 30 m/s at 37° above horizontal from a 45 m cliff. Find its speed on impact. (g=10 m/s²)'

204});203});


228 "content": "A ball is thrown upward at 25 m/s from the top of a 60 m building. Find the maximum height above the ground. (g=10 m/s²)"227 "content": "A ball is thrown upward at 25 m/s from the top of a 60 m building. Find the maximum height above the ground. (g=10 m/s²)"

229 }228 }

230 ],229 ],

231 "model": "grok-4.3",230 "model": "grok-4.5",

232 "stream": true231 "stream": true

233}'232}'

234```233```

Details

26 timeout=3600, # Override default timeout with longer timeout for reasoning models26 timeout=3600, # Override default timeout with longer timeout for reasoning models

27)27)

28 28 

29chat = client.chat.create(model="grok-4.3")29chat = client.chat.create(model="grok-4.5")

30chat.append(30chat.append(

31 system("You are Grok, a helpful and maximally truthful AI built by xAI."),31 system("You are Grok, a helpful and maximally truthful AI built by xAI."),

32)32)


53)53)

54 54 

55stream = client.chat.completions.create(55stream = client.chat.completions.create(

56 model="grok-4.3",56 model="grok-4.5",

57 messages=[57 messages=[

58 {"role": "system", "content": "You are Grok, a helpful and maximally truthful AI built by xAI."},58 {"role": "system", "content": "You are Grok, a helpful and maximally truthful AI built by xAI."},

59 {"role": "user", "content": "Explain how neural networks learn in two sentences."},59 {"role": "user", "content": "Explain how neural networks learn in two sentences."},


74});74});

75 75 

76const stream = await openai.chat.completions.create({76const stream = await openai.chat.completions.create({

77 model: "grok-4.3",77 model: "grok-4.5",

78 messages: [78 messages: [

79 { role: "system", content: "You are Grok, a helpful and maximally truthful AI built by xAI." },79 { role: "system", content: "You are Grok, a helpful and maximally truthful AI built by xAI." },

80 {80 {


95import { streamText } from 'ai';95import { streamText } from 'ai';

96 96 

97const result = streamText({97const result = streamText({

98 model: xai.responses('grok-4.3'),98 model: xai.responses('grok-4.5'),

99 system:99 system:

100 "You are Grok, a helpful and maximally truthful AI built by xAI.",100 "You are Grok, a helpful and maximally truthful AI built by xAI.",

101 prompt: 'Explain how neural networks learn in two sentences.',101 prompt: 'Explain how neural networks learn in two sentences.',


122 "content": "Explain how neural networks learn in two sentences."122 "content": "Explain how neural networks learn in two sentences."

123 }123 }

124 ],124 ],

125 "model": "grok-4.3",125 "model": "grok-4.5",

126 "stream": true126 "stream": true

127}'127}'

128```128```


132```json132```json

133data: {133data: {

134 "id":"<completion_id>","object":"chat.completion.chunk","created":<creation_time>,134 "id":"<completion_id>","object":"chat.completion.chunk","created":<creation_time>,

135 "model":"grok-4.3",135 "model":"grok-4.5",

136 "choices":[{"index":0,"delta":{"content":"Ah","role":"assistant"}}],136 "choices":[{"index":0,"delta":{"content":"Ah","role":"assistant"}}],

137 "usage":{"prompt_tokens":41,"completion_tokens":1,"total_tokens":42,137 "usage":{"prompt_tokens":41,"completion_tokens":1,"total_tokens":42,

138 "prompt_tokens_details":{"text_tokens":41,"audio_tokens":0,"image_tokens":0,"cached_tokens":0}},138 "prompt_tokens_details":{"text_tokens":41,"audio_tokens":0,"image_tokens":0,"cached_tokens":0}},


141 141 

142data: {142data: {

143 "id":"<completion_id>","object":"chat.completion.chunk","created":<creation_time>,143 "id":"<completion_id>","object":"chat.completion.chunk","created":<creation_time>,

144 "model":"grok-4.3",144 "model":"grok-4.5",

145 "choices":[{"index":0,"delta":{"content":",","role":"assistant"}}],145 "choices":[{"index":0,"delta":{"content":",","role":"assistant"}}],

146 "usage":{"prompt_tokens":41,"completion_tokens":2,"total_tokens":43,146 "usage":{"prompt_tokens":41,"completion_tokens":2,"total_tokens":43,

147 "prompt_tokens_details":{"text_tokens":41,"audio_tokens":0,"image_tokens":0,"cached_tokens":0}},147 "prompt_tokens_details":{"text_tokens":41,"audio_tokens":0,"image_tokens":0,"cached_tokens":0}},

Details

264 currency: Currency = Field(description="Currency of the invoice")264 currency: Currency = Field(description="Currency of the invoice")

265 265 

266client = Client(api_key=os.getenv("XAI_API_KEY"))266client = Client(api_key=os.getenv("XAI_API_KEY"))

267chat = client.chat.create(model="grok-4.3")267chat = client.chat.create(model="grok-4.5")

268 268 

269chat.append(system("Given a raw invoice, carefully analyze the text and extract the invoice data into JSON format."))269chat.append(system("Given a raw invoice, carefully analyze the text and extract the invoice data into JSON format."))

270chat.append(270chat.append(


338)338)

339 339 

340completion = client.beta.chat.completions.parse(340completion = client.beta.chat.completions.parse(

341 model="grok-4.3",341 model="grok-4.5",

342 messages=[342 messages=[

343 {"role": "system", "content": "Given a raw invoice, carefully analyze the text and extract the invoice data into JSON format."},343 {"role": "system", "content": "Given a raw invoice, carefully analyze the text and extract the invoice data into JSON format."},

344 {"role": "user", "content": """344 {"role": "user", "content": """


395});395});

396 396 

397const completion = await client.chat.completions.parse({397const completion = await client.chat.completions.parse({

398 model: "grok-4.3",398 model: "grok-4.5",

399 messages: [399 messages: [

400 { role: "system", content: "Given a raw invoice, carefully analyze the text and extract the invoice data into JSON format." },400 { role: "system", content: "Given a raw invoice, carefully analyze the text and extract the invoice data into JSON format." },

401 { role: "user", content: \`401 { role: "user", content: \`


449});449});

450 450 

451const result = await generateText({451const result = await generateText({

452 model: xai.responses('grok-4.3'),452 model: xai.responses('grok-4.5'),

453 output: Output.object({ schema: InvoiceSchema }),453 output: Output.object({ schema: InvoiceSchema }),

454 system:454 system:

455 'Given a raw invoice, carefully analyze the text and extract the invoice data into JSON format.',455 'Given a raw invoice, carefully analyze the text and extract the invoice data into JSON format.',


542 542 

543client = Client(api_key=os.getenv("XAI_API_KEY"))543client = Client(api_key=os.getenv("XAI_API_KEY"))

544chat = client.chat.create(544chat = client.chat.create(

545 model="grok-4.3",545 model="grok-4.5",

546 tools=[web_search()],546 tools=[web_search()],

547)547)

548 548 


569)569)

570 570 

571response = client.responses.parse(571response = client.responses.parse(

572 model="grok-4.3",572 model="grok-4.5",

573 input="Find the latest machine-checked proof of the four color theorem.",573 input="Find the latest machine-checked proof of the four color theorem.",

574 tools=[574 tools=[

575 {"type": "web_search"}575 {"type": "web_search"}


600const format = zodResponseFormat(ProofInfoSchema, "proof_info");600const format = zodResponseFormat(ProofInfoSchema, "proof_info");

601 601 

602const response = await client.responses.create({602const response = await client.responses.create({

603 model: "grok-4.3",603 model: "grok-4.5",

604 input: "Find the latest machine-checked proof of the four color theorem.",604 input: "Find the latest machine-checked proof of the four color theorem.",

605 tools: [605 tools: [

606 { type: "web_search" }606 { type: "web_search" }


684 684 

685client = Client(api_key=os.getenv("XAI_API_KEY"))685client = Client(api_key=os.getenv("XAI_API_KEY"))

686chat = client.chat.create(686chat = client.chat.create(

687 model="grok-4.3",687 model="grok-4.5",

688 tools=[collatz_tool],688 tools=[collatz_tool],

689)689)

690 690 


755# Handle tool calls until we get a final response755# Handle tool calls until we get a final response

756while True:756while True:

757 completion = client.chat.completions.create(757 completion = client.chat.completions.create(

758 model="grok-4.3",758 model="grok-4.5",

759 messages=messages,759 messages=messages,

760 tools=tools,760 tools=tools,

761 )761 )


777 777 

778# Final call with structured output778# Final call with structured output

779completion = client.beta.chat.completions.parse(779completion = client.beta.chat.completions.parse(

780 model="grok-4.3",780 model="grok-4.5",

781 messages=messages,781 messages=messages,

782 response_format=CollatzResult,782 response_format=CollatzResult,

783)783)


830// Handle tool calls until we get a final response830// Handle tool calls until we get a final response

831while (true) {831while (true) {

832 const completion = await client.chat.completions.create({832 const completion = await client.chat.completions.create({

833 model: "grok-4.3",833 model: "grok-4.5",

834 messages,834 messages,

835 tools,835 tools,

836 });836 });


855 855 

856// Final call with structured output856// Final call with structured output

857const completion = await client.chat.completions.create({857const completion = await client.chat.completions.create({

858 model: "grok-4.3",858 model: "grok-4.5",

859 messages,859 messages,

860 response_format: {860 response_format: {

861 type: "json_schema",861 type: "json_schema",


947 947 

948# Pass the Pydantic model to response_format instead of using parse()948# Pass the Pydantic model to response_format instead of using parse()

949chat = client.chat.create(949chat = client.chat.create(

950 model="grok-4.3",950 model="grok-4.5",

951 response_format=Invoice, # Pass the Pydantic model here951 response_format=Invoice, # Pass the Pydantic model here

952)952)

953 953 


1000client = Client(api_key=os.getenv("XAI_API_KEY"))1000client = Client(api_key=os.getenv("XAI_API_KEY"))

1001 1001 

1002chat = client.chat.create(1002chat = client.chat.create(

1003 model="grok-4.3",1003 model="grok-4.5",

1004 response_format=Summary, # Pass the Pydantic model here1004 response_format=Summary, # Pass the Pydantic model here

1005)1005)

1006 1006 

quickstart.md +6 −6

Details

44 44 

45## Step 4: Make your first request45## Step 4: Make your first request

46 46 

47Send a coding prompt to [Grok Build](/build/overview) (`grok-build-0.1`) and get a response. The same model powers agentic coding in Grok Build and is available on the API in early access:47Send a coding prompt to [Grok Build](/build/overview) (`grok-4.5`) and get a response. The same model powers agentic coding in Grok Build and is available on the API in early access:

48 48 

49```bash49```bash

50curl https://api.x.ai/v1/responses \50curl https://api.x.ai/v1/responses \

51 -H "Authorization: Bearer $XAI_API_KEY" \51 -H "Authorization: Bearer $XAI_API_KEY" \

52 -H "Content-Type: application/json" \52 -H "Content-Type: application/json" \

53 -d '{53 -d '{

54 "model": "grok-build-0.1",54 "model": "grok-4.5",

55 "input": "Fix this function and explain the bug: function median(a){a.sort();return a[a.length/2]}"55 "input": "Fix this function and explain the bug: function median(a){a.sort();return a[a.length/2]}"

56 }'56 }'

57```57```


63 63 

64client = Client(api_key=os.getenv("XAI_API_KEY"))64client = Client(api_key=os.getenv("XAI_API_KEY"))

65 65 

66chat = client.chat.create(model="grok-build-0.1")66chat = client.chat.create(model="grok-4.5")

67chat.append(user("Fix this function and explain the bug: function median(a){a.sort();return a[a.length/2]}"))67chat.append(user("Fix this function and explain the bug: function median(a){a.sort();return a[a.length/2]}"))

68 68 

69print(chat.sample().content)69print(chat.sample().content)


78)78)

79 79 

80response = client.responses.create(80response = client.responses.create(

81 model="grok-build-0.1",81 model="grok-4.5",

82 input="Fix this function and explain the bug: function median(a){a.sort();return a[a.length/2]}",82 input="Fix this function and explain the bug: function median(a){a.sort();return a[a.length/2]}",

83)83)

84 84 


90import { generateText } from 'ai';90import { generateText } from 'ai';

91 91 

92const { text } = await generateText({92const { text } = await generateText({

93 model: xai.responses('grok-build-0.1'),93 model: xai.responses('grok-4.5'),

94 prompt: 'Fix this function and explain the bug: function median(a){a.sort();return a[a.length/2]}',94 prompt: 'Fix this function and explain the bug: function median(a){a.sort();return a[a.length/2]}',

95});95});

96 96 


106});106});

107 107 

108const response = await client.responses.create({108const response = await client.responses.create({

109 model: 'grok-build-0.1',109 model: 'grok-4.5',

110 input: 'Fix this function and explain the bug: function median(a){a.sort();return a[a.length/2]}',110 input: 'Fix this function and explain the bug: function median(a){a.sort();return a[a.length/2]}',

111});111});

112 112 

rate-limits.md +8 −7

Details

33 33 

34| Model | RPS | TPM |34| Model | RPS | TPM |

35| --- | --- | --- |35| --- | --- | --- |

36| grok-4.3 | T0: 30, T1: 40, T2: 60, T3: 100, T4: 166 | T0: 10M, T1: 15M, T2: 25M, T3: 45M, T4: 85M |36| grok-4.3 | T0: 37, T1: 50, T2: 75, T3: 125, T4: 208 | T0: 10M, T1: 15M, T2: 25M, T3: 45M, T4: 85M |

37| grok-4.20-0309-reasoning | T0: 30, T1: 40, T2: 60, T3: 100, T4: 166 | T0: 10M, T1: 15M, T2: 25M, T3: 45M, T4: 85M |37| grok-4.20-0309-reasoning | T0: 37, T1: 50, T2: 75, T3: 125, T4: 208 | T0: 10M, T1: 15M, T2: 25M, T3: 45M, T4: 85M |

38| grok-4.20-0309-non-reasoning | T0: 30, T1: 40, T2: 60, T3: 100, T4: 166 | T0: 10M, T1: 15M, T2: 25M, T3: 45M, T4: 85M |38| grok-4.20-0309-non-reasoning | T0: 37, T1: 50, T2: 75, T3: 125, T4: 208 | T0: 10M, T1: 15M, T2: 25M, T3: 45M, T4: 85M |

39| grok-build-0.1 | T0: 30, T1: 40, T2: 60, T3: 100, T4: 166 | T0: 10M, T1: 15M, T2: 25M, T3: 45M, T4: 85M |39| grok-build-0.1 | T0: 37, T1: 50, T2: 75, T3: 125, T4: 208 | T0: 10M, T1: 15M, T2: 25M, T3: 45M, T4: 85M |

40| grok-4.20-multi-agent-0309 | T0: 7, T1: 10, T2: 15, T3: 25, T4: 45 | T0: 2.5M, T1: 3.7M, T2: 6.2M, T3: 11M, T4: 21M |40| grok-4.5 | T0: 150, T1: 172, T2: 208, T3: 312, T4: 500 | T0: 50M, T1: 53M, T2: 60M, T3: 74M, T4: 100M |

41| grok-4.20-multi-agent-0309 | T0: 9, T1: 12, T2: 18, T3: 31, T4: 56 | T0: 2.5M, T1: 3.7M, T2: 6.2M, T3: 11M, T4: 21M |

41| grok-imagine-image-quality | 5 | — |42| grok-imagine-image-quality | 5 | — |

42| grok-imagine-image | 5 | — |43| grok-imagine-image | 5 | — |

43| grok-imagine-video-1.5 | 1 | — |44| grok-imagine-video-1.5 | 1 | — |


69 for attempt in range(max_retries):70 for attempt in range(max_retries):

70 try:71 try:

71 return client.chat.completions.create(72 return client.chat.completions.create(

72 model="grok-4.3",73 model="grok-4.5",

73 messages=messages,74 messages=messages,

74 )75 )

75 except RateLimitError:76 except RateLimitError:


88client = Client(api_key=os.getenv("XAI_API_KEY"))89client = Client(api_key=os.getenv("XAI_API_KEY"))

89 90 

90def request_with_backoff(prompt, max_retries=5):91def request_with_backoff(prompt, max_retries=5):

91 chat = client.chat.create(model="grok-4.3")92 chat = client.chat.create(model="grok-4.5")

92 chat.append(user(prompt))93 chat.append(user(prompt))

93 for attempt in range(max_retries):94 for attempt in range(max_retries):

94 try:95 try:

Details

251 251 

252* `metadata` (object) — Not supported. Only maintained for compatibility reasons.252* `metadata` (object) — Not supported. Only maintained for compatibility reasons.

253 253 

254* `min_p` (number | null) — Min-p sampling: tokens whose probability is below \`min\_p\` times the probability of the most likely token are excluded from sampling. Disabled when unset.

255 

254* `model` (string) — Model name for the model to use. Obtainable from \<https://console.x.ai/team/default/models> or \<https://docs.x.ai/docs/models>.256* `model` (string) — Model name for the model to use. Obtainable from \<https://console.x.ai/team/default/models> or \<https://docs.x.ai/docs/models>.

255 257 

256* `parallel_tool_calls` (boolean | null) — Whether to allow the model to run parallel tool calls.258* `parallel_tool_calls` (boolean | null) — Whether to allow the model to run parallel tool calls.


302 304 

303* `tools` (array | null) — A list of tools the model may call in JSON-schema. Currently, only functions and web search are supported as tools. A max of 128 tools are supported.\`web\_search\_preview\` tool, if specified, will be overridden by \`search\_parameters\`.305* `tools` (array | null) — A list of tools the model may call in JSON-schema. Currently, only functions and web search are supported as tools. A max of 128 tools are supported.\`web\_search\_preview\` tool, if specified, will be overridden by \`search\_parameters\`.

304 306 

307* `top_k` (integer | null) — Top-k sampling: only the \`top\_k\` most probable tokens are considered at each sampling step. Disabled when unset.

308 

305* `top_logprobs` (integer | null) — An integer between 0 and 8 specifying the number of most likely tokens to return at each token position, each with an associated log probability. logprobs must be set to true if this parameter is used. Not supported by models \`grok-4.20\` and newer; the field will be silently ignored if set.309* `top_logprobs` (integer | null) — An integer between 0 and 8 specifying the number of most likely tokens to return at each token position, each with an associated log probability. logprobs must be set to true if this parameter is used. Not supported by models \`grok-4.20\` and newer; the field will be silently ignored if set.

306 310 

307* `top_p` (number | null) — An alternative to sampling with \`temperature\`, called nucleus sampling, where the model considers the results of the tokens with \`top\_p\` probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. It is generally recommended to alter this or \`temperature\` but not both.311* `top_p` (number | null) — An alternative to sampling with \`temperature\`, called nucleus sampling, where the model considers the results of the tokens with \`top\_p\` probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. It is generally recommended to alter this or \`temperature\` but not both.


443 -H "Content-Type: application/json" \447 -H "Content-Type: application/json" \

444 -H "Authorization: Bearer $XAI_API_KEY" \448 -H "Authorization: Bearer $XAI_API_KEY" \

445 -d '{449 -d '{

446 "model": "grok-4.3",450 "model": "grok-4.5",

447 "input": "What is the meaning of life?"451 "input": "What is the meaning of life?"

448 }'452 }'

449```453```


453import { generateText } from "ai";457import { generateText } from "ai";

454 458 

455const result = await generateText({459const result = await generateText({

456 model: xai.responses("grok-4.3"),460 model: xai.responses("grok-4.5"),

457 prompt: "What is the meaning of life?",461 prompt: "What is the meaning of life?",

458});462});

459 463 


471)475)

472 476 

473response = client.responses.create(477response = client.responses.create(

474 model="grok-4.3",478 model="grok-4.5",

475 input="What is the meaning of life?",479 input="What is the meaning of life?",

476)480)

477 481 


487});491});

488 492 

489const response = await client.responses.create({493const response = await client.responses.create({

490 model: "grok-4.3",494 model: "grok-4.5",

491 input: "What is the meaning of life?",495 input: "What is the meaning of life?",

492});496});

493 497 


601 -H "Content-Type: application/json" \605 -H "Content-Type: application/json" \

602 -H "Authorization: Bearer $XAI_API_KEY" \606 -H "Authorization: Bearer $XAI_API_KEY" \

603 -d '{607 -d '{

604 "model": "grok-4.3",608 "model": "grok-4.5",

605 "input": [609 "input": [

606 {"role": "system", "content": "You are a concise and knowledgeable science tutor."},610 {"role": "system", "content": "You are a concise and knowledgeable science tutor."},

607 {"role": "user", "content": "What is the Higgs boson and why is it important?"},611 {"role": "user", "content": "What is the Higgs boson and why is it important?"},


623)627)

624 628 

625compacted = client.responses.compact(629compacted = client.responses.compact(

626 model="grok-4.3",630 model="grok-4.5",

627 input=[631 input=[

628 {"role": "system", "content": "You are a concise and knowledgeable science tutor."},632 {"role": "system", "content": "You are a concise and knowledgeable science tutor."},

629 {"role": "user", "content": "What is the Higgs boson and why is it important?"},633 {"role": "user", "content": "What is the Higgs boson and why is it important?"},


659});663});

660 664 

661const compacted = await client.responses.compact({665const compacted = await client.responses.compact({

662 model: "grok-4.3",666 model: "grok-4.5",

663 input: [667 input: [

664 { role: "system", content: "You are a concise and knowledgeable science tutor." },668 { role: "system", content: "You are a concise and knowledgeable science tutor." },

665 { role: "user", content: "What is the Higgs boson and why is it important?" },669 { role: "user", content: "What is the Higgs boson and why is it important?" },

Details

86 ),86 ),

87 ]87 ]

88 88 

89 model = "grok-4.3"89 model = "grok-4.5"

90 ```90 ```

91 91 

922. Perform the tool loop with conversation continuation:922. Perform the tool loop with conversation continuation:


217 # In a real app, this would query your database217 # In a real app, this would query your database

218 return f"The weather in {city} is sunny."218 return f"The weather in {city} is sunny."

219 219 

220 model = "grok-4.3"220 model = "grok-4.5"

221 tools = [221 tools = [

222 {222 {

223 "type": "function",223 "type": "function",


376client = Client(api_key=os.getenv("XAI_API_KEY"))376client = Client(api_key=os.getenv("XAI_API_KEY"))

377# First turn.377# First turn.

378chat = client.chat.create(378chat = client.chat.create(

379 model="grok-4.3", # reasoning model379 model="grok-4.5", # reasoning model

380 tools=[web_search(), x_search()],380 tools=[web_search(), x_search()],

381 store_messages=True,381 store_messages=True,

382)382)


388 388 

389# Second turn.389# Second turn.

390chat = client.chat.create(390chat = client.chat.create(

391 model="grok-4.3", # reasoning model391 model="grok-4.5", # reasoning model

392 tools=[web_search(), x_search()],392 tools=[web_search(), x_search()],

393 # pass the response id of the first turn to continue the conversation393 # pass the response id of the first turn to continue the conversation

394 previous_response_id=response.id,394 previous_response_id=response.id,


421client = Client(api_key=os.getenv("XAI_API_KEY"))421client = Client(api_key=os.getenv("XAI_API_KEY"))

422# First turn.422# First turn.

423chat = client.chat.create(423chat = client.chat.create(

424 model="grok-4.3", # reasoning model424 model="grok-4.5", # reasoning model

425 tools=[web_search(), x_search()],425 tools=[web_search(), x_search()],

426 use_encrypted_content=True,426 use_encrypted_content=True,

427)427)


506 506 

507client = Client(api_key=os.getenv("XAI_API_KEY"))507client = Client(api_key=os.getenv("XAI_API_KEY"))

508chat = client.chat.create(508chat = client.chat.create(

509 model="grok-4.3", # reasoning model509 model="grok-4.5", # reasoning model

510 tools=[510 tools=[

511 web_search(),511 web_search(),

512 x_search(),512 x_search(),


549)549)

550 550 

551response = client.responses.create(551response = client.responses.create(

552 model="grok-4.3",552 model="grok-4.5",

553 input=[553 input=[

554 {554 {

555 "role": "user",555 "role": "user",


579 "Authorization": f"Bearer {os.getenv('XAI_API_KEY')}"579 "Authorization": f"Bearer {os.getenv('XAI_API_KEY')}"

580}580}

581payload = {581payload = {

582 "model": "grok-4.3",582 "model": "grok-4.5",

583 "input": [583 "input": [

584 {584 {

585 "role": "user",585 "role": "user",


604 -H "Content-Type: application/json" \\604 -H "Content-Type: application/json" \\

605 -H "Authorization: Bearer $XAI_API_KEY" \\605 -H "Authorization: Bearer $XAI_API_KEY" \\

606 -d '{606 -d '{

607 "model": "grok-4.3",607 "model": "grok-4.5",

608 "input": [608 "input": [

609 {609 {

610 "role": "user",610 "role": "user",


635 635 

636client = Client(api_key=os.getenv("XAI_API_KEY"))636client = Client(api_key=os.getenv("XAI_API_KEY"))

637chat = client.chat.create(637chat = client.chat.create(

638 model="grok-4.3", # reasoning model638 model="grok-4.5", # reasoning model

639 # research_tools639 # research_tools

640 tools=[640 tools=[

641 web_search(),641 web_search(),


660)660)

661 661 

662response = client.responses.create(662response = client.responses.create(

663 model="grok-4.3",663 model="grok-4.5",

664 input=[664 input=[

665 {665 {

666 "role": "user",666 "role": "user",


691 "Authorization": f"Bearer {os.getenv('XAI_API_KEY')}"691 "Authorization": f"Bearer {os.getenv('XAI_API_KEY')}"

692}692}

693payload = {693payload = {

694 "model": "grok-4.3",694 "model": "grok-4.5",

695 "input": [695 "input": [

696 {696 {

697 "role": "user",697 "role": "user",


717 -H "Content-Type: application/json" \\717 -H "Content-Type: application/json" \\

718 -H "Authorization: Bearer $XAI_API_KEY" \\718 -H "Authorization: Bearer $XAI_API_KEY" \\

719 -d '{719 -d '{

720 "model": "grok-4.3",720 "model": "grok-4.5",

721 "input": [721 "input": [

722 {722 {

723 "role": "user",723 "role": "user",


751# Create the client and define the server-side tools to use751# Create the client and define the server-side tools to use

752client = Client(api_key=os.getenv("XAI_API_KEY"))752client = Client(api_key=os.getenv("XAI_API_KEY"))

753chat = client.chat.create(753chat = client.chat.create(

754 model="grok-4.3", # reasoning model754 model="grok-4.5", # reasoning model

755 tools=[web_search(), x_search()],755 tools=[web_search(), x_search()],

756 include=["verbose_streaming"],756 include=["verbose_streaming"],

757)757)

tools/citations.md +10 −10

Details

58 -H "Content-Type: application/json" \58 -H "Content-Type: application/json" \

59 -H "Authorization: Bearer $XAI_API_KEY" \59 -H "Authorization: Bearer $XAI_API_KEY" \

60 -d '{60 -d '{

61 "model": "grok-4.3",61 "model": "grok-4.5",

62 "input": [62 "input": [

63 {"role": "user", "content": "What is xAI?"}63 {"role": "user", "content": "What is xAI?"}

64 ],64 ],


75 75 

76client = Client(api_key=os.getenv("XAI_API_KEY"))76client = Client(api_key=os.getenv("XAI_API_KEY"))

77chat = client.chat.create(77chat = client.chat.create(

78 model="grok-4.3",78 model="grok-4.5",

79 tools=[79 tools=[

80 web_search(),80 web_search(),

81 x_search(),81 x_search(),


100)100)

101 101 

102response = client.responses.create(102response = client.responses.create(

103 model="grok-4.3",103 model="grok-4.5",

104 input=[104 input=[

105 {"role": "user", "content": "What is xAI?"}105 {"role": "user", "content": "What is xAI?"}

106 ],106 ],


122import { generateText } from 'ai';122import { generateText } from 'ai';

123 123 

124const { text, sources } = await generateText({124const { text, sources } = await generateText({

125 model: xai.responses('grok-4.3'),125 model: xai.responses('grok-4.5'),

126 prompt: 'What is xAI?',126 prompt: 'What is xAI?',

127 tools: {127 tools: {

128 web_search: xai.tools.webSearch(), // inline citations are enabled by default128 web_search: xai.tools.webSearch(), // inline citations are enabled by default


145});145});

146 146 

147const response = await client.responses.create({147const response = await client.responses.create({

148 model: 'grok-4.3',148 model: 'grok-4.5',

149 input: [149 input: [

150 { role: 'user', content: 'What is xAI?' }150 { role: 'user', content: 'What is xAI?' }

151 ],151 ],


176)176)

177 177 

178response = client.responses.create(178response = client.responses.create(

179 model="grok-4.3",179 model="grok-4.5",

180 input=[180 input=[

181 {"role": "user", "content": "What is xAI?"}181 {"role": "user", "content": "What is xAI?"}

182 ],182 ],


205 "Authorization": f"Bearer {os.getenv('XAI_API_KEY')}",205 "Authorization": f"Bearer {os.getenv('XAI_API_KEY')}",

206 },206 },

207 json={207 json={

208 "model": "grok-4.3",208 "model": "grok-4.5",

209 "include": ["no_inline_citations"],209 "include": ["no_inline_citations"],

210 "input": [210 "input": [

211 {"role": "user", "content": "What is xAI?"}211 {"role": "user", "content": "What is xAI?"}


227 -H "Content-Type: application/json" \227 -H "Content-Type: application/json" \

228 -H "Authorization: Bearer $XAI_API_KEY" \228 -H "Authorization: Bearer $XAI_API_KEY" \

229 -d '{229 -d '{

230 "model": "grok-4.3",230 "model": "grok-4.5",

231 "include": ["no_inline_citations"],231 "include": ["no_inline_citations"],

232 "input": [232 "input": [

233 {"role": "user", "content": "What is xAI?"}233 {"role": "user", "content": "What is xAI?"}


283 "completed_at": 1781829888,283 "completed_at": 1781829888,

284 "id": "5808284d-ae14-9981-9289-73515f67ebda",284 "id": "5808284d-ae14-9981-9289-73515f67ebda",

285 "max_output_tokens": null,285 "max_output_tokens": null,

286 "model": "grok-4.3",286 "model": "grok-4.5",

287 "object": "response",287 "object": "response",

288 "output": [288 "output": [

289 ...289 ...


383import { streamText } from 'ai';383import { streamText } from 'ai';

384 384 

385const { fullStream } = streamText({385const { fullStream } = streamText({

386 model: xai.responses('grok-4.3'),386 model: xai.responses('grok-4.5'),

387 prompt: 'What is xAI?',387 prompt: 'What is xAI?',

388 tools: {388 tools: {

389 web_search: xai.tools.webSearch(),389 web_search: xai.tools.webSearch(),

Details

48 48 

49client = Client(api_key=os.getenv("XAI_API_KEY"))49client = Client(api_key=os.getenv("XAI_API_KEY"))

50chat = client.chat.create(50chat = client.chat.create(

51 model="grok-4.3", # reasoning model51 model="grok-4.5", # reasoning model

52 tools=[code_execution()],52 tools=[code_execution()],

53 include=["verbose_streaming"],53 include=["verbose_streaming"],

54)54)


89)89)

90 90 

91response = client.responses.create(91response = client.responses.create(

92 model="grok-4.3",92 model="grok-4.5",

93 input=[93 input=[

94 {94 {

95 "role": "user",95 "role": "user",


116 "Authorization": f"Bearer {os.getenv('XAI_API_KEY')}"116 "Authorization": f"Bearer {os.getenv('XAI_API_KEY')}"

117}117}

118payload = {118payload = {

119 "model": "grok-4.3",119 "model": "grok-4.5",

120 "input": [120 "input": [

121 {121 {

122 "role": "user",122 "role": "user",


138 -H "Content-Type: application/json" \\138 -H "Content-Type: application/json" \\

139 -H "Authorization: Bearer $XAI_API_KEY" \\139 -H "Authorization: Bearer $XAI_API_KEY" \\

140 -d '{140 -d '{

141 "model": "grok-4.3",141 "model": "grok-4.5",

142 "input": [142 "input": [

143 {143 {

144 "role": "user",144 "role": "user",


158import { generateText } from 'ai';158import { generateText } from 'ai';

159 159 

160const { text } = await generateText({160const { text } = await generateText({

161 model: xai.responses('grok-4.3'),161 model: xai.responses('grok-4.5'),

162 prompt: 'Calculate the compound interest for $10,000 at 5% annually for 10 years',162 prompt: 'Calculate the compound interest for $10,000 at 5% annually for 10 years',

163 tools: {163 tools: {

164 code_execution: xai.tools.codeExecution(),164 code_execution: xai.tools.codeExecution(),


180 180 

181# Multi-turn conversation with data analysis181# Multi-turn conversation with data analysis

182chat = client.chat.create(182chat = client.chat.create(

183 model="grok-4.3", # reasoning model183 model="grok-4.5", # reasoning model

184 tools=[code_execution()],184 tools=[code_execution()],

185 include=["verbose_streaming"],185 include=["verbose_streaming"],

186)186)


250 250 

251// Step 1: Load and analyze data251// Step 1: Load and analyze data

252const step1 = await generateText({252const step1 = await generateText({

253 model: xai.responses('grok-4.3'),253 model: xai.responses('grok-4.5'),

254 prompt: \`I have sales data for Q1-Q4: [120000, 135000, 98000, 156000].254 prompt: \`I have sales data for Q1-Q4: [120000, 135000, 98000, 156000].

255Please analyze this data and create a visualization showing:255Please analyze this data and create a visualization showing:

2561. Quarterly trends2561. Quarterly trends


266 266 

267// Step 2: Follow-up analysis using previousResponseId267// Step 2: Follow-up analysis using previousResponseId

268const step2 = await generateText({268const step2 = await generateText({

269 model: xai.responses('grok-4.3'),269 model: xai.responses('grok-4.5'),

270 prompt: 'Now predict Q1 next year using linear regression',270 prompt: 'Now predict Q1 next year using linear regression',

271 tools: {271 tools: {

272 code_execution: xai.tools.codeExecution(),272 code_execution: xai.tools.codeExecution(),


312### 3. **Use Appropriate Model Settings**312### 3. **Use Appropriate Model Settings**

313 313 

314* **Temperature**: Use lower values (0.0-0.3) for mathematical calculations314* **Temperature**: Use lower values (0.0-0.3) for mathematical calculations

315* **Model**: Use reasoning models like `grok-4.3` for better code generation315* **Model**: Use reasoning models like `grok-4.5` for better code generation

316 316 

317## Common Use Cases317## Common Use Cases

318 318 

Details

21 -H "Content-Type: application/json" \21 -H "Content-Type: application/json" \

22 -H "Authorization: Bearer $XAI_API_KEY" \22 -H "Authorization: Bearer $XAI_API_KEY" \

23 -d '{23 -d '{

24 "model": "grok-4.3",24 "model": "grok-4.5",

25 "input": [25 "input": [

26 {"role": "user", "content": "What is the temperature in San Francisco?"}26 {"role": "user", "content": "What is the temperature in San Francisco?"}

27 ],27 ],


69]69]

70 70 

71chat = client.chat.create(71chat = client.chat.create(

72 model="grok-4.3",72 model="grok-4.5",

73 tools=tools,73 tools=tools,

74)74)

75chat.append(user("What is the temperature in San Francisco?"))75chat.append(user("What is the temperature in San Francisco?"))


116]116]

117 117 

118response = client.responses.create(118response = client.responses.create(

119 model="grok-4.3",119 model="grok-4.5",

120 input=[{"role": "user", "content": "What is the temperature in San Francisco?"}],120 input=[{"role": "user", "content": "What is the temperature in San Francisco?"}],

121 tools=tools,121 tools=tools,

122)122)


128 result = {"location": args["location"], "temperature": 59, "unit": args.get("unit", "fahrenheit")}128 result = {"location": args["location"], "temperature": 59, "unit": args.get("unit", "fahrenheit")}

129 129 

130 response = client.responses.create(130 response = client.responses.create(

131 model="grok-4.3",131 model="grok-4.5",

132 input=[{"type": "function_call_output", "call_id": item.call_id, "output": json.dumps(result)}],132 input=[{"type": "function_call_output", "call_id": item.call_id, "output": json.dumps(result)}],

133 tools=tools,133 tools=tools,

134 previous_response_id=response.id,134 previous_response_id=response.id,


145import { z } from 'zod';145import { z } from 'zod';

146 146 

147const result = streamText({147const result = streamText({

148 model: xai.responses('grok-4.3'),148 model: xai.responses('grok-4.5'),

149 tools: {149 tools: {

150 getTemperature: tool({150 getTemperature: tool({

151 description: 'Get current temperature for a location',151 description: 'Get current temperature for a location',


289 output = json.dumps(tools_map[name](**args))289 output = json.dumps(tools_map[name](**args))

290 290 

291 response = client.responses.create(291 response = client.responses.create(

292 model="grok-4.3",292 model="grok-4.5",

293 input=[{"type": "function_call_output", "call_id": item.call_id, "output": output}],293 input=[{"type": "function_call_output", "call_id": item.call_id, "output": output}],

294 tools=tools,294 tools=tools,

295 previous_response_id=response.id,295 previous_response_id=response.id,


325]325]

326 326 

327chat = client.chat.create(327chat = client.chat.create(

328 model="grok-4.3",328 model="grok-4.5",

329 tools=tools,329 tools=tools,

330)330)

331```331```


447import { z } from 'zod';447import { z } from 'zod';

448 448 

449const result = streamText({449const result = streamText({

450 model: xai.responses('grok-4.3'),450 model: xai.responses('grok-4.5'),

451 tools: {451 tools: {

452 getCurrentTemperature: tool({452 getCurrentTemperature: tool({

453 description: 'Get current temperature for a location',453 description: 'Get current temperature for a location',

Details

38 -H "Content-Type: application/json" \38 -H "Content-Type: application/json" \

39 -H "Authorization: Bearer $XAI_API_KEY" \39 -H "Authorization: Bearer $XAI_API_KEY" \

40 -d '{40 -d '{

41 "model": "grok-4.3",41 "model": "grok-4.5",

42 "stream": true,42 "stream": true,

43 "input": [43 "input": [

44 {44 {


63 63 

64client = Client(api_key=os.getenv("XAI_API_KEY"))64client = Client(api_key=os.getenv("XAI_API_KEY"))

65chat = client.chat.create(65chat = client.chat.create(

66 model="grok-4.3",66 model="grok-4.5",

67 tools=[67 tools=[

68 web_search(),68 web_search(),

69 x_search(),69 x_search(),


90)90)

91 91 

92response = client.responses.create(92response = client.responses.create(

93 model="grok-4.3",93 model="grok-4.5",

94 input=[94 input=[

95 {"role": "user", "content": "What are the latest updates from xAI?"}95 {"role": "user", "content": "What are the latest updates from xAI?"}

96 ],96 ],


112import { streamText } from 'ai';112import { streamText } from 'ai';

113 113 

114const { fullStream } = streamText({114const { fullStream } = streamText({

115 model: xai.responses('grok-4.3'),115 model: xai.responses('grok-4.5'),

116 prompt: 'What are the latest updates from xAI?',116 prompt: 'What are the latest updates from xAI?',

117 tools: {117 tools: {

118 web_search: xai.tools.webSearch(),118 web_search: xai.tools.webSearch(),


139});139});

140 140 

141const stream = await client.responses.create({141const stream = await client.responses.create({

142 model: "grok-4.3",142 model: "grok-4.5",

143 input: [143 input: [

144 { role: "user", content: "What are the latest updates from xAI?" }144 { role: "user", content: "What are the latest updates from xAI?" }

145 ],145 ],

Details

36 36 

37client = Client(api_key=os.getenv("XAI_API_KEY"))37client = Client(api_key=os.getenv("XAI_API_KEY"))

38chat = client.chat.create(38chat = client.chat.create(

39 model="grok-4.3",39 model="grok-4.5",

40 tools=[40 tools=[

41 mcp(server_url="https://mcp.deepwiki.com/mcp"),41 mcp(server_url="https://mcp.deepwiki.com/mcp"),

42 ],42 ],


76)76)

77 77 

78response = client.responses.create(78response = client.responses.create(

79 model="grok-4.3",79 model="grok-4.5",

80 input=[80 input=[

81 {81 {

82 "role": "user",82 "role": "user",


105 "Authorization": f"Bearer {os.getenv('XAI_API_KEY')}"105 "Authorization": f"Bearer {os.getenv('XAI_API_KEY')}"

106}106}

107payload = {107payload = {

108 "model": "grok-4.3",108 "model": "grok-4.5",

109 "input": [109 "input": [

110 {110 {

111 "role": "user",111 "role": "user",


129 -H "Content-Type: application/json" \\129 -H "Content-Type: application/json" \\

130 -H "Authorization: Bearer $XAI_API_KEY" \\130 -H "Authorization: Bearer $XAI_API_KEY" \\

131 -d '{131 -d '{

132 "model": "grok-4.3",132 "model": "grok-4.5",

133 "input": [133 "input": [

134 {134 {

135 "role": "user",135 "role": "user",


173 173 

174```pythonXAI174```pythonXAI

175chat = client.chat.create(175chat = client.chat.create(

176 model="grok-4.3",176 model="grok-4.5",

177 tools=[177 tools=[

178 mcp(server_url="https://mcp.deepwiki.com/mcp", server_label="deepwiki"),178 mcp(server_url="https://mcp.deepwiki.com/mcp", server_label="deepwiki"),

179 mcp(server_url="https://your-custom-tools.com/mcp", server_label="custom"),179 mcp(server_url="https://your-custom-tools.com/mcp", server_label="custom"),

Details

23 23 

24client = Client(api_key=os.getenv("XAI_API_KEY"))24client = Client(api_key=os.getenv("XAI_API_KEY"))

25chat = client.chat.create(25chat = client.chat.create(

26 model="grok-4.3",26 model="grok-4.5",

27 tools=[27 tools=[

28 web_search(),28 web_search(),

29 x_search(),29 x_search(),


55import { streamText } from 'ai';55import { streamText } from 'ai';

56 56 

57const { fullStream } = streamText({57const { fullStream } = streamText({

58 model: xai.responses('grok-4.3'),58 model: xai.responses('grok-4.5'),

59 prompt: 'What are the latest updates from xAI?',59 prompt: 'What are the latest updates from xAI?',

60 tools: {60 tools: {

61 web_search: xai.tools.webSearch(),61 web_search: xai.tools.webSearch(),


88 88 

89client = Client(api_key=os.getenv("XAI_API_KEY"))89client = Client(api_key=os.getenv("XAI_API_KEY"))

90chat = client.chat.create(90chat = client.chat.create(

91 model="grok-4.3",91 model="grok-4.5",

92 tools=[92 tools=[

93 web_search(),93 web_search(),

94 x_search(),94 x_search(),


118 118 

119// Synchronous request - waits for complete response119// Synchronous request - waits for complete response

120const { text, sources } = await generateText({120const { text, sources } = await generateText({

121 model: xai.responses('grok-4.3'),121 model: xai.responses('grok-4.5'),

122 prompt: 'What is the latest update from xAI?',122 prompt: 'What is the latest update from xAI?',

123 tools: {123 tools: {

124 web_search: xai.tools.webSearch(),124 web_search: xai.tools.webSearch(),


149 149 

150client = Client(api_key=os.getenv("XAI_API_KEY"))150client = Client(api_key=os.getenv("XAI_API_KEY"))

151chat = client.chat.create(151chat = client.chat.create(

152 model="grok-4.3",152 model="grok-4.5",

153 store_messages=True, # Enable Responses API153 store_messages=True, # Enable Responses API

154 tools=[154 tools=[

155 web_search(),155 web_search(),


178)178)

179 179 

180response = client.responses.create(180response = client.responses.create(

181 model="grok-4.3",181 model="grok-4.5",

182 input=[182 input=[

183 {183 {

184 "role": "user",184 "role": "user",


203 -H "Content-Type: application/json" \\203 -H "Content-Type: application/json" \\

204 -H "Authorization: Bearer $XAI_API_KEY" \\204 -H "Authorization: Bearer $XAI_API_KEY" \\

205 -d '{205 -d '{

206 "model": "grok-4.3",206 "model": "grok-4.5",

207 "input": [207 "input": [

208 {208 {

209 "role": "user",209 "role": "user",


244 244 

245client = Client(api_key=os.getenv("XAI_API_KEY"))245client = Client(api_key=os.getenv("XAI_API_KEY"))

246chat = client.chat.create(246chat = client.chat.create(

247 model="grok-4.3",247 model="grok-4.5",

248 tools=[248 tools=[

249 code_execution(),249 code_execution(),

250 ],250 ],

Details

122 122 

123client = Client(api_key=os.getenv("XAI_API_KEY"))123client = Client(api_key=os.getenv("XAI_API_KEY"))

124chat = client.chat.create(124chat = client.chat.create(

125 model="grok-4.3",125 model="grok-4.5",

126 tools=[126 tools=[

127 web_search(),127 web_search(),

128 x_search(),128 x_search(),