Skip to main content

Grok

Grok is a family of AI models by xAI that supports text, reasoning, and multimodal capabilities. Integrating Grok into your product allows you to leverage Grok's generative and reasoning capabilities for tasks such as chat, completions, structured output, or function calling.

Credentials Needed

  • xAI API Key (Bearer token)
  • (Optional) Team or Organization ID (if applicable in xAI console)

You obtain this API key from the xAI console under API Keys.

Permissions / API Scopes

Grok uses ACL-based permissions on the API key. During key creation, you can assign permissions such as:

  • chat:write — to use Grok in chat/completion mode
  • sampler:write — for raw model sampling

The API is REST-compatible and supports endpoints similar to OpenAI's (e.g. /v1/chat/completions).

Creating Users / API Keys

  1. Sign up or log in to xAI console (via X / Google or email).
  2. Navigate to API Keys section.
  3. Click Create API Key (or "New Key")
  4. Name the key, select the required permissions (e.g. chat:write, sampler:write)
  5. Save / copy the generated key immediately — it is shown only once.
  6. Optionally, set quotas or rate-limit rules if xAI supports them.

Test Connectivity

Use curl or SDK (OpenAI SDK compatibility) to verify the connection:

curl https://api.x.ai/v1/chat/completions \
-H "Authorization: Bearer <XAI_API_KEY>" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-3-mini",
"messages": [
{"role": "user", "content": "Hello Grok, are you connected?"}
],
"max_tokens": 50
}'

A successful JSON response indicates your integration is working.

Save the Results in the Platform and Create Connection

  1. In your platform's connector config, securely store:
    • XAI_API_KEY
    • (Optional) XAI_ORG_ID
  2. Label the connector as Grok Integration.
  3. During setup, test by sending a small prompt to validate access and response correctness.
  4. Optionally, expose model selection (e.g. grok-4, grok-3-mini) to users.

Best Practices

  • Use least-permission ACLs when creating API keys (only assign needed capabilities).
  • Rotate API keys periodically and disable unused ones.
  • Store keys securely (e.g., in a vault or encrypted secret store), never embed in client-side code.
  • Monitor usage and token costs via xAI console — the API includes usage reporting.
  • Handle rate-limit errors gracefully and implement exponential backoff.
  • Use streaming responses where supported for better UX.
  • Abstract your API layer so that you can switch endpoints or models easily (e.g., future versions of Grok or new base URLs).
  • For teams, manage roles and audit logs via xAI console to track key usage.