Grok (xAI) API: endpoints, authentication, models and limits
Connection details
| Base URL | https://api.x.ai/v1 |
| Auth | Bearer token via XAI_API_KEY |
| OpenAI SDK compatible | Yes |
| SDKs | OpenAI SDK, Anthropic-compatible endpoint, xAI SDK |
Models and token pricing
| Model | Model ID | Context | In / 1M | Out / 1M |
|---|---|---|---|---|
| Grok 3 | grok-3 | 131K | $3.00 | $15.00 |
| Grok 4.5 | grok-4.5 | 500K | $2.00 | $6.00 |
| Grok 4.6 | grok-4.6 | 500K | $2.00 | $6.00 |
| Grok 4.3 | grok-4.3 | 1000K | $1.25 | $2.50 |
| Grok 3 Mini | grok-3-mini | 131K | $0.300 | $0.500 |
Full pricing breakdown, including cached-input rates and tier comparisons: Grok (xAI) API pricing.
Call Grok 3 through Swfte Connect
Swfte Connect is an OpenAI-compatible gateway. One Connect key reaches this model and the other providers Connect is credentialed for, with failover and cost tracking on the same endpoint. Prices below are the provider list prices from our model directory; see the AI model price index to compare them with every other model.
Connect also accepts your own provider keys and can be self-deployed (designed for, on request). See Connect providers and BYOK and self-deploying Connect.
Grok 3
| Model ID on Connect | xai:grok-3 |
| Context window | 131K tokens |
| Input / 1M tokens | $3.00 |
| Output / 1M tokens | $15.00 |
curl https://api.swfte.com/agents/v2/gateway/chat/completions \
-H "Authorization: Bearer $SWFTE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "xai:grok-3",
"messages": [{"role": "user", "content": "Hello"}]
}'Swfte Connect · Connect pricing · AI FinOps. Other Grok (xAI) models in the table above are listed for reference and are not offered through Connect here.
What is distinctive about this API
- xAI exposes both OpenAI-compatible and Anthropic-compatible surfaces, so a migration from either provider is a base-URL change rather than a rewrite.
- Live search against X/web can be enabled per request, which is the main reason to choose this API over a general-purpose model for recency-sensitive work.
- Function calling and structured outputs follow the OpenAI schema conventions.
Constraints worth knowing first
- Search-augmented requests are billed differently from plain completions — read the response usage block rather than assuming token-only billing.
- Model aliases move as new versions ship; pin an explicit dated model ID in production or behaviour will change under you.
Frequently asked
- What is the Grok (xAI) API base URL?
- https://api.x.ai/v1. Authenticate with a bearer token, conventionally read from the XAI_API_KEY environment variable.
- Is the Grok (xAI) API compatible with the OpenAI SDK?
- Yes. The chat completions surface is wire-compatible, so the official OpenAI client libraries work by pointing base_url at https://api.x.ai/v1 and supplying a XAI_API_KEY. No client library change is needed.
- How do I get a Grok (xAI) API key?
- Create an account with the provider and generate a key from the developer console, then expose it to your application as XAI_API_KEY. Keys are secrets: keep them server-side, never in client bundles or committed config.
- Can I call Grok 3 through Swfte Connect?
- Yes. Swfte Connect exposes Grok 3 as xai:grok-3 behind one OpenAI-style chat completions endpoint (api.swfte.com/agents/v2/gateway). Create a Connect key and send the model ID in the request body. Other Grok (xAI) models in the table are listed for reference and are not offered through Connect on this page.
- Which models does the Grok (xAI) API expose?
- Grok 3, Grok 4.5, Grok 4.6, Grok 4.3, Grok 3 Mini. Context windows run to 1000K tokens.
Other provider APIs
xAI publishes official documentation at https://docs.x.ai. Pricing and limits change; verify against the provider before committing to a budget.