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.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.
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.
- Which models does the Grok (xAI) API expose?
- Grok 3, Grok 4.5, 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.