Grok 4.5·续2

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.5",
  "messages": [
    {
      "content": [
        {
          "image_url": {
            "url": "https://v3.fal.media/files/koala/NLVPfOI4XL1cWT2PmmqT3_Hope.png"
          },
          "type": "image_url"
        },
        {
          "text": "Describe the person in this image and their surroundings in one sentence.",
          "type": "text"
        }
      ],
      "role": "user"
    }
  ]
}'
A smiling young woman with dark hair pulled back, wearing a blue knit sweater and multiple rings, holds a small fuzzy microphone while posing in a cozy indoor room with warm lighting, a framed photo collage on the wall, and decorative elements like a plant and artwork.
{
  "id": "f864bc43-a81c-995b-bb6c-253294c05423",
  "object": "chat.completion",
  "created": 1784491003,
  "model": "grok-4.5",
  "choices": [
    {
      "index": 0,
      "finish_reason": "stop",
      "message": {
        "role": "assistant",
        "content": "A smiling young woman with dark hair pulled back, wearing a blue knit sweater and multiple rings, holds a small fuzzy microphone while posing in a cozy indoor room with warm lighting, a framed photo collage on the wall, and decorative elements like a plant and artwork.",
        "reasoning_content": "The user wants me to describe the person in the image and their surroundings in one sentence.\n",
        "refusal": null
      }
    }
  ],
  "service_tier": "default",
  "system_fingerprint": "fp_a39489019fa99b6e",
  "usage": {
    "prompt_tokens": 2628,
    "completion_tokens": 52,
    "total_tokens": 2827,
    "prompt_tokens_details": {
      "text_tokens": 221,
      "audio_tokens": 0,
      "image_tokens": 2407,
      "cached_tokens": 128
    },
    "completion_tokens_details": {
      "reasoning_tokens": 147,
      "audio_tokens": 0,
      "accepted_prediction_tokens": 0,
      "rejected_prediction_tokens": 0
    },
    "cost_in_usd_ticks": 62324000,
    "num_sources_used": 0
  },
  "gatewayMetadata": {
    "keySource": "Unified"
  }
}

</details>

<details>

<summary>Function Calling — Force the model to return a typed function call</summary>

const response = await env.AI.run(
  'xai/grok-4.5',
  {
    messages: [{ content: 'What is the current temperature in San Francisco?', role: 'user' }],
    tool_choice: 'required',
    tools: [
      {
        function: {
          description: 'Get the current temperature for a city',
          name: 'get_temperature',
          parameters: {
            additionalProperties: false,
            properties: {
              city: { type: 'string' },
              unit: { enum: ['celsius', 'fahrenheit'], type: 'string' },
            },
            required: ['city', 'unit'],
            type: 'object',
          },
          strict: true,
        },
        type: 'function',
      },
    ],
  },
)
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.5",
  "messages": [
    {
      "content": "What is the current temperature in San Francisco?",
      "role": "user"
    }
  ],
  "tool_choice": "required",
  "tools": [
    {
      "function": {
        "description": "Get the current temperature for a city",
        "name": "get_temperature",
        "parameters": {
          "additionalProperties": false,
          "properties": {
            "city": {
              "type": "string"
            },
            "unit": {
              "enum": [
                "celsius",
                "fahrenheit"
              ],
              "type": "string"
            }
          },
          "required": [
            "city",
            "unit"
          ],
          "type": "object"
        },
        "strict": true
      },
      "type": "function"
    }
  ]
}'
I'll check the current temperature in San Francisco for you.
{
  "id": "5e8b5367-6685-95f6-8a15-fd3d5e785de5",
  "object": "chat.completion",
  "created": 1784491007,
  "model": "grok-4.5",
  "choices": [
    {
      "index": 0,
      "finish_reason": "tool_calls",
      "message": {
        "role": "assistant",
        "content": "I'll check the current temperature in San Francisco for you.",
        "reasoning_content": "The user wants the current temperature in San Francisco. I have a tool for that: get_temperature. I need to specify the city and the unit. The city is San Francisco, but what unit? It doesn't specify,...",
        "refusal": null,
        "tool_calls": [
          {
            "id": "call-206bc4d0-666a-48ea-8b03-28467f98b9df-0",
            "type": "function",
            "function": {
              "name": "get_temperature",
              "arguments": "{\"city\":\"San Francisco\",\"unit\":\"fahrenheit\"}"
            }
          }
        ]
      }
    }
  ],
  "service_tier": "default",
  "system_fingerprint": "fp_a39489019fa99b6e",
  "usage": {
    "prompt_tokens": 333,
    "completion_tokens": 31,
    "total_tokens": 445,
    "prompt_tokens_details": {
      "text_tokens": 333,
      "audio_tokens": 0,
      "image_tokens": 0,
      "cached_tokens": 128
    },
    "completion_tokens_details": {
      "reasoning_tokens": 81,
      "audio_tokens": 0,
      "accepted_prediction_tokens": 0,
      "rejected_prediction_tokens": 0
    },
    "cost_in_usd_ticks": 11204000,
    "num_sources_used": 0
  },
  "gatewayMetadata": {
    "keySource": "Unified"
  }
}

</details>

<details>

<summary>Structured Output — Constrain the response to a JSON schema</summary>

const response = await env.AI.run(
  'xai/grok-4.5',
  {
    messages: [
      {
        content: 'Classify the sentiment of: The launch was smooth and customers loved it.',
        role: 'user',
      },
    ],
    response_format: {
      json_schema: {
        name: 'sentiment_result',
        schema: {
          additionalProperties: false,
          properties: {
            confidence: { maximum: 1, minimum: 0, type: 'number' },
            sentiment: { enum: ['positive', 'neutral', 'negative'], type: 'string' },
          },
          required: ['sentiment', 'confidence'],
          type: 'object',
        },
        strict: true,
      },
      type: 'json_schema',
    },
  },
)
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.5",
  "messages": [
    {
      "content": "Classify the sentiment of: The launch was smooth and customers loved it.",
      "role": "user"
    }
  ],
  "response_format": {
    "json_schema": {
      "name": "sentiment_result",
      "schema": {
        "additionalProperties": false,
        "properties": {
          "confidence": {
            "maximum": 1,
            "minimum": 0,
            "type": "number"
          },
          "sentiment": {
            "enum": [
              "positive",
              "neutral",
              "negative"
            ],
            "type": "string"
          }
        },
        "required": [
          "sentiment",
          "confidence"
        ],
        "type": "object"
      },
      "strict": true
    },
    "type": "json_schema"
  }
}'
{"confidence":0.95,"sentiment":"positive"}
{
  "id": "da248276-7d35-9291-9645-7f495af55158",
  "object": "chat.completion",
  "created": 1784491010,
  "model": "grok-4.5",
  "choices": [
    {
      "index": 0,
      "finish_reason": "stop",
      "message": {
        "role": "assistant",
        "content": "{\"confidence\":0.95,\"sentiment\":\"positive\"}",
        "reasoning_content": "The user wants me to classify the sentiment of: \"The launch was smooth and customers loved it.\"\n",
        "refusal": null
      }
    }
  ],
  "service_tier": "default",
  "system_fingerprint": "fp_a39489019fa99b6e",
  "usage": {
    "prompt_tokens": 300,
    "completion_tokens": 12,
    "total_tokens": 472,
    "prompt_tokens_details": {
      "text_tokens": 300,
      "audio_tokens": 0,
      "image_tokens": 0,
      "cached_tokens": 128
    },
    "completion_tokens_details": {
      "reasoning_tokens": 160,
      "audio_tokens": 0,
      "accepted_prediction_tokens": 0,
      "rejected_prediction_tokens": 0
    },
    "cost_in_usd_ticks": 14144000,
    "num_sources_used": 0
  },
  "gatewayMetadata": {
    "keySource": "Unified"
  }
}

</details>

Parameters

▶messages[]

arrayrequiredminItems: 1maxItems: 500

max_completion_tokens

integer | null

max_tokens

integer | null

n

integer | null

parallel_tool_calls

boolean

prompt_cache_key

string

reasoning_effort

string | nullenum: low, medium, high

▶response_format

one of

▶search_parameters{}

object

seed

integer | null

service_tier

stringenum: default, priority

stream

boolean

▶stream_options{}

object

temperature

number | null

▶tool_choice

one of

tools

array | 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

service_tier

stringenum: default, priority

system_fingerprint

string

▶usage{}

object

API Schemas (Raw)

Input Open Download

Output Open Download

Was this helpful?

YesNo

On this page

Grok 4.5·续2 - 图1Docs

{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/ai/models/xai/grok-4.5/#page","headline":"Grok 4.5","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).","url":"https://developers.cloudflare.com/ai/models/xai/grok-4.5/","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.6, a flagship reasoning model for coding, agentic tasks, and visual work. Accepts text and image inputs, and supports function calling and structured outputs. title: Grok 4.6 image: https://developers.cloudflare.com/og-docs.png


Skip to content

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.

xAI logo