Open and read the JSON file (3)·续
curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/v1/chat/completions \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"model": "xai/grok-4.3",
"max_completion_tokens": 8192,
"messages": [
{
"content": "Write a short story opening about a detective finding an unusual clue.",
"role": "user"
}
]
}'
Detective Mara Ellison crouched in the rain-slicked alley behind the shuttered theater, her gloved fingers brushing aside a crumpled playbill. The victim—a reclusive playwright—lay a few feet away, but it was the clue that stopped her cold: a single, flawless chess pawn carved from what looked like human bone, its base etched with the playwright’s own initials in a script too precise for any hurried killer. A faint scent of stage grease clung to it, and when she tilted it toward the streetlight, tiny notches along its side formed a pattern that looked suspiciously like Morse code.
{
"choices": [
{
"finish_reason": "stop",
"index": 0,
"message": {
"content": "Detective Mara Ellison crouched in the rain-slicked alley behind the shuttered theater, her gloved fingers brushing aside a crumpled playbill. The victim—a reclusive playwright—lay a few feet away, but it was the clue that stopped her cold: a single, flawless chess pawn carved from what looked like human bone, its base etched with the playwright’s own initials in a script too precise for any hurried killer. A faint scent of stage grease clung to it, and when she tilted it toward the streetlight, tiny notches along its side formed a pattern that looked suspiciously like Morse code.",
"reasoning_content": "The user asked: \"Write a short story opening about a detective finding an unusual clue.\"\nI need to write a short story opening about a detective finding an unusual clue. I'll start by setting the scene with the detective in a dimly lit office or at a crime scene. Then, I'll introduce the clue in a surprising way to make it unusual.\n\nFor the clue, I'll go with something like a message written in a language that's not recognized, or a symbol that doesn't belong.",
"refusal": null,
"role": "assistant"
}
}
],
"created": 1778620620,
"gatewayMetadata": {
"keySource": "Unified"
},
"id": "e5192068-96c5-9603-b29c-33f9da53ec02",
"model": "grok-4.3",
"object": "chat.completion",
"system_fingerprint": "fp_655c34cb90f68992",
"usage": {
"completion_tokens": 120,
"completion_tokens_details": {
"accepted_prediction_tokens": 0,
"audio_tokens": 0,
"reasoning_tokens": 575,
"rejected_prediction_tokens": 0
},
"cost_in_usd_ticks": 17818500,
"num_sources_used": 0,
"prompt_tokens": 143,
"prompt_tokens_details": {
"audio_tokens": 0,
"cached_tokens": 128,
"image_tokens": 0,
"text_tokens": 143
},
"total_tokens": 838
}
}
</details>
<details>
<summary>Streaming Response — Enable streaming for real-time output</summary>
const response = await env.AI.run(
'xai/grok-4.3',
{
messages: [{ content: 'Explain the concept of recursion with a simple example.', role: 'user' }],
stream: true,
stream_options: { include_usage: true },
},
)
console.log(response)
curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/v1/chat/completions \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"model": "xai/grok-4.3",
"messages": [
{
"content": "Explain the concept of recursion with a simple example.",
"role": "user"
}
],
"stream": true,
"stream_options": {
"include_usage": true
}
}'
**Recursion** is a programming technique where a function solves a problem by calling *itself* with a smaller or simpler version of the original problem. It keeps breaking the problem down until it reaches a simple case that can be solved directly (called the **base case**).
### Simple Example: Factorial
The factorial of a number *n* (written as *n!*) is the product of all positive integers from 1 to *n*. For example:
- 5! = 5 × 4 × 3 × 2 × 1 = 120
Mathematically, we can define it recursively as:
- **Base case**: 0! = 1 or 1! = 1
- **Recursive case**: n! = n × (n-1)!
Here's how this looks in Python:
```python
def factorial(n):
if n == 0 or n == 1: # Base case
return 1
else:
return n * factorial(n - 1) # Recursive call
```
### How it works (step-by-step for `factorial(5)`)
1. `factorial(5)` → returns `5 * factorial(4)`
2. `factorial(4)` → returns `4 * factorial(3)`
3. `factorial(3)` → returns `3 * factorial(2)`
4. `factorial(2)` → returns `2 * factorial(1)`
5. `factorial(1)` → hits the **base case** and returns `1`
The results then "unwind" back up:
- `2 * 1 = 2`
- `3 * 2 = 6`
- `4 * 6 = 24`
- `5 * 24 = 120`
So `factorial(5)` returns **120**.
### Key Points
- **Base case** is crucial — without it, the function would call itself forever (causing a stack overflow).
- Recursion uses the **call stack** to keep track of each function call.
- While elegant for some problems (like tree traversals or divide-and-conquer algorithms), recursion can be less efficient than iteration for simple tasks due to the overhead of function calls.
[
{
"choices": [
{
"delta": {
"reasoning_content": "The",
"role": "assistant"
},
"index": 0
}
],
"created": 1778620632,
"id": "853a0f04-bc0e-525a-cdb9-e035f1d365fa",
"model": "grok-4.3",
"object": "chat.completion.chunk",
"system_fingerprint": "fp_655c34cb90f68992"
},
{
"choices": [
{
"delta": {
"reasoning_content": " question"
},
"index": 0
}
],
"created": 1778620632,
"id": "853a0f04-bc0e-525a-cdb9-e035f1d365fa",
"model": "grok-4.3",
"object": "chat.completion.chunk",
"system_fingerprint": "fp_655c34cb90f68992"
},
"... 471 more chunks omitted ...",
{
"choices": [],
"created": 1778620641,
"id": "853a0f04-bc0e-525a-cdb9-e035f1d365fa",
"model": "grok-4.3",
"object": "chat.completion.chunk",
"system_fingerprint": "fp_655c34cb90f68992",
"usage": {
"completion_tokens": 455,
"completion_tokens_details": {
"accepted_prediction_tokens": 0,
"audio_tokens": 0,
"reasoning_tokens": 358,
"rejected_prediction_tokens": 0
},
"cost_in_usd_ticks": 20731000,
"num_sources_used": 0,
"prompt_tokens": 140,
"prompt_tokens_details": {
"audio_tokens": 0,
"cached_tokens": 128,
"image_tokens": 0,
"text_tokens": 140
},
"total_tokens": 953
}
}
]
</details>
Parameters
▶messages[]
arrayrequiredminItems: 1maxItems: 500
deferred
boolean
frequency_penalty
number | null
logprobs
boolean
max_completion_tokens
integer | null
max_tokens
integer | null
n
integer | null
parallel_tool_calls
boolean
presence_penalty
number | null
reasoning_effort
string | nullenum: none, low, medium, high
▶response_format
one of
▶search_parameters{}
object
seed
integer | null
stop
array | null
stream
boolean
▶stream_options{}
object
temperature
number | null
▶tool_choice
one of
tools
array | null
top_logprobs
integer | null
top_p
number | null
user
string
▶web_search_options{}
object
id
string
object
stringconst: chat.completion
created
number
model
string
▶choices[]
array
citations
array | null
output_files
array | null
system_fingerprint
string
▶usage{}
object
API Schemas (Raw)
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/ai/models/xai/grok-4.3/#page","headline":"Grok 4.3","description":"xAI's Grok 4.3 model with a 1M-token context window and strong agentic tool calling with minimal hallucinations. Accepts text and image inputs, and supports function calling, structured outputs, and configurable reasoning effort (none, low, medium, high).","url":"https://developers.cloudflare.com/ai/models/xai/grok-4.3/","inLanguage":"en","image":"https://developers.cloudflare.com/og-docs.png","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}
description: xAI's Grok 4.5, a frontier model built for coding, agentic tasks, and knowledge work. Accepts text and image inputs, and supports function calling, structured outputs, and configurable reasoning effort (low, medium, high). title: Grok 4.5 image: https://developers.cloudflare.com/og-docs.png
Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/llms.txt
Use this file to discover all available pages before exploring further.

