Choose your access path
For direct Grok API access, create an account in the xAI Console, add credits, create an API key, and send requests to https://api.x.ai/v1. For a new integration, xAI identifies the Responses API (/v1/responses) as its primary interface for text generation, reasoning, and tool use. The older Chat Completions endpoint still exists, but xAI describes it as a legacy predecessor and recommends Responses for new integrations. (xAI API quickstart)
This is direct API access—not a requirement to use a third-party framework. If your application already uses Pipecat, its GrokLLMService is a separate integration option, described below.
Get an API key
- Sign up at
console.x.ai. - Add credits to the account to use the API.
- Create a key on the Console’s API Keys page.
- Store it as an environment variable named
XAI_API_KEYrather than placing it in browser code or committing it to a repository.
The official quickstart shows the key being exported as an environment variable. Keep it secret: anyone who obtains a usable key may be able to make API requests under its access and billing conditions.
For example, in a Bash or zsh terminal:
export XAI_API_KEY="your_api_key"
Use the same terminal session for the request below, or configure the variable securely in your deployment environment.
Make your first direct API request
This curl example uses the official quickstart’s grok-4.7 example model and the Responses API endpoint. It sends a prompt and returns the API response.
curl -i -sS https://api.x.ai/v1/responses \\
-H "Authorization: Bearer $XAI_API_KEY" \\
-H "Content-Type: application/json" \\
-d '{
"model": "grok-4.7",
"input": "Reply with a short greeting."
}'
The request uses POST; authentication uses Authorization: Bearer <API key>, and the body includes a model and input, matching the xAI quickstart. The -i option displays the HTTP status and headers. A 2xx status indicates HTTP-level success; also check the response body: for a completed response, status should be completed, and the generated text is in an output item of type message, inside a content item of type output_text, in its text field. For this prompt, that field is where the greeting appears. This is a field-path guide, not a recorded API response. (Responses API reference; response structure)
The model shown is the quickstart’s example; check xAI’s documentation for current model availability and model-specific behavior.
Direct API or Pipecat?
| Path | Use it when | What you configure |
|---|---|---|
| Direct xAI API | You want to call xAI from your own application or use a supported SDK. | xAI API key, base URL, endpoint, model, and request. The example above uses the Responses API. |
| Pipecat integration | Your application uses Pipecat and you want its Grok service layer. | Install Pipecat’s Grok dependency and initialize GrokLLMService with the key. These are Pipecat-specific steps, not direct HTTP instructions. |
Pipecat documents this install command:
uv add "pipecat-ai[grok]"
Its documentation uses XAI_API_KEY and shows model selection through settings=GrokLLMService.Settings(model=...). It also marks the service’s top-level model parameter as deprecated since Pipecat 0.0.105 and removed in 2.0.0. Because that page does not pin the package release these details apply to, check the documentation for your installed version before relying on version-specific behavior. (Pipecat Grok documentation)
Pipecat describes its service as supporting streaming responses, function calling, and context management. Those are claims about the documented Pipecat integration; the page does not provide a raw HTTP streaming example or establish that every feature is available for every model or account.
Credits and pricing
The xAI quickstart says to load the account with credits before using the API. Pricing depends on the model and usage; check the official xAI API pricing page for current rates, billing units, and applicable conditions.
Sources
Grok API Quickstart: Get Your API Key
