页面简介
Official Grok API documentation from SpaceXSI. Build with Grok: chat, image and video generation, voice, tool calling, and structured outputs. Quickstarts, guides, and API reference.
正文摘录
Get started with SpaceX Super IntelligenceBuild with the Grok API: intelligent, fast, and cost-effective models across code, text, voice, image, and video.Create API keyGet StartedJavaScriptPython (OpenAI)cURLPythonimport { xai } from "@ai-sdk/xai"; import { generateText } from "ai"; const { text } = await generateText({ model: xai.responses("grok-4.7"), prompt: "Fix this function and explain the bug: function median(a){a.sort();return a[a.length/2]}", }); console.log(text);from openai import OpenAI client = OpenAI( api_key="<YOUR_XAI_API_KEY_HERE>", base_url="https://api.x.ai/v1", ) response = client.responses.create( model="grok-4.7", input="Fix this function and explain the bug: function median(a){a.sort();return a[a.length/2]}", ) print(response.output_text)curl https://api.x.ai/v1/responses \ -H "Authorization: Bearer $XAI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "grok-4.7", "input": "Fix this function and explain the bug: function median(a){a.sort();return a[a.length/2]}" }'import os from xai_sdk import Client from xai_sdk.chat import user client = Client(api_key=os.getenv("XAI_API_KEY")) chat = client.chat.create(model="grok-4.7") chat.append(user("Fix this function and explain the bug: function median(a){a.sort();return a[a.length/2]}")) print(chat.sample().content)ModelsGrok 4.7Newgrok-4.7Our flagship model for code and everything else: agentic tool calling, minimal hallucinations, configurable reasoning.Context500k tokensInput$2.00 / 1M tokensOutput$6.00 / 1M tokensReasoningConfigurableView modelTry in playgroundVoice APIReal-time conversations, speech-to-text, and text-to-speech.STS$0.08 / minTTS$15.00 / 1M charsSTT (Batch)$0.10 / hourSTT (Streaming)$0.20 / hourRead docsTry in playgroundImage & Video APITurn ideas into reality with image and video generation.ModesGeneration & editingSpeedIndustry-leadingImage · 1K / 2KStarting at $0.02 / imageVideo · 480p / 720p / 1080pStarting at $0.02 / secRead docsTry in playgroundJump straight inTry code, text, voice, image, and video models belowCodeTextVoiceImageVideo JavaScriptPython (OpenAI)Bash Pythonimport { xai } from "@ai-sdk/xai"; import { generateText } from "ai"; const { text } = await generateText({ model: xai.responses("grok-4.7"), prompt: "Fix this function and explain the bug: function median(a){a.sort();return a[a.length/2]}", }); console.log(text);from openai import OpenAI client = OpenAI( api_key="<YOUR_XAI_API_KEY_HERE>", base_url="https://api.x.ai/v1", ) response = client.responses.create( model="grok-4.7", input="Fix this function and explain the bug: function median(a){a.sort();return a[a.length/2]}", ) print(response.output_text)curl https://api.x.ai/v1/responses \ -H "Authorization: Bearer $XAI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "grok-4.7", "input": "Fix this function and explain the bug: function median(a){a.sort();return a[a.length/2]}" }'import os from xai_sdk import Client from xai_sdk.chat import user client = Client(api_key=os.getenv("XAI_API_KEY")) chat = client.chat.create(model="grok-4.7") chat.append(user("Fix this function and explain the bug: function median(a){a.sort();return a[a.length/2]}")) print(chat.sample().content)Responses APIAgentic coding with Grok Build on the API—refactor, debug, and build in your own tools.Agentic codingIDE & tool integrationsPowers Grok Build$2.00 / 1M input tokens$6.00 / 1M output tokensRead docsExplore the Grok API documentationGet startedCreate an API keyPurchase creditsQuickstart guideModelsPricingGrok BuildFunction callingWeb searchStructured outputsBatch APIResourcesAPI referenceCommunity integrationsRelease notes