xAI REST API Review
Introducing the xAI API#
It's always an exciting day when a major tech company launches their first API, and the internet was certainly buzzing when Elon announced the new xAI API.
Most AI platform companies (ex. OpenAI and Anthropic) see a large amount of traffic from companies integrating their REST APIs to add AI features to their apps/websites. xAI has long been seen as an underdog in the AI race, however with a recent funding round of $6B, the platform has accelerated development to catch up with its rivals. The question that lingered on my mind is if the developer experience of xAI might be good enough to lure away users of OpenAI or Anthropic's APIs.
xAI API Functionality#
The xAI Rest API, powered by Grok, provides a robust set of capabilities for developers to build AI-driven applications. The API grants access to Grok, a powerful large language model designed for various tasks, including text and code generation, as well as image-related functionalities.
Key capabilities include:
- Text and Code: The API can generate text and code, extract data, create summaries, and support various natural language processing tasks
- Vision: The API supports image generation, object identification, and visual analysis, which can be useful in applications that require visual data interpretation or content creation.
- Function Calling: It offers advanced function-calling capabilities, allowing developers to connect the model to external tools, which enables handling complex workflows involving external data and functions.
- Model Options: Developers can choose between Grok-2, which is optimized for complex reasoning tasks, and Grok-2 mini, a lighter model offering faster responses with a trade-off in output depth.
The API also supports streaming responses for real-time applications like chatbots. It’s compatible with OpenAI and Anthropic SDKs, making it easier for developers familiar with those platforms to integrate xAI with minimal adjustments.
Onboarding Experience#
Getting started with the xAI REST API is quite straightforward. Simply create an xAI account. You can choose to authenticate with your X account, Google, Microsoft, or plain-old email + password.
From what I observed, there's a different onboarding for users coming from free-mails (ex. gmail) compared to work email domains. The work-mail onboarding flow guides you through creating an account, inviting team members, and importantly - getting your first API key.
The free-mail version dumps you out to your account management screen with a small button to go to the API console. Once you click the "API console" button, it takes you to the same flow as above.
Getting Your API Key & Time To First Call#
After signing up, you are prompted to create your first key, which is
provisioned immediately, and accompanied by a curl
code sample.
I really appreciate how quickly they aim to get users onboarded, this significantly reduces the time-to-first-call (TTFC), especially since you just need an API key rather than a complicated JWT setup.
Other than the weird flow for free-mail users, I was feeling really good about the onboarding flow, until I actually tried making the API call. I was immediately greeted by an error:
{
"code": "The caller does not have permission to execute the specified operation",
"error": "Your new team 9e287ee1-ad55-41d6-91b4-24fe8ba21b40 has just been created and is still being initialized. Please try again shortly."
}
I navigated the the API console to see what was going on (I thought the key was provisioned already?) and saw this banner up-top.
How perplexing - what "initialization" needs to be made here? Their API Key service seems to have already worked, and their models are already deployed - so what is going on behind the scenes?
Disappointingly, this first call is also your last free one - you are forced to pay for the API after receiving that initial error.
This feels like a bit of a bait & switch, the onboarding made me feel like there was some sort of free-tier, but instead, I am forced to pay to get started. The onboarding was very seamless up to this point, so despite this rug-pull, it still deserves a respectable score.
Onboarding Score: 7/10
API Documentation#
Now let's move onto the API docs. They are split between the introductory materials and the API Reference which is common. The quickstart is just a more in-depth version of the onboarding flow, while the API reference goes into more depth around topics like authentication and streaming.
The API reference is nicely laid out in the typical 2 column + navbar format.
Here's my pros & cons
Pros
- Nice layout
- Docs cover common usecases (ex. streaming)
- All query parameters, including optional fields are documented
- Some error codes are documented (ex. 400, 404)
Cons
- Many parameters lack descriptions so you have to infer what they mean from the examples provided
- Definition and Example tab are separate for no reason
- Headers needed are not documented inline
- Naming doesn't follow a consistent convention (ex.
Completions
vsCreate embeddings
) - No interactive playground
- Many errors are undocumented or poorly documented
xAI OpenAPI Specification#
Does xAI offer an OpenAPI/Swagger spec? Initially, the answer was no because I couldn't find a link to it anywhere. I did notice that their docs were bespoke however, so I did some network tab sniffing and found it! The OpenAPI specification lives at https://docs.x.ai/openapi.json.
In its raw form - the OpenAPI spec is not pretty. I ran it through RateMyOpenAPI, and wasn't surprised by the low score.
The lack of interactive playground in the docs bothered me a lot, so I decided to create my own. I had to modify the OpenAPI from its original state to make it compliant with most tooling. Here's the end result
View API InYou can find the full OpenAPI specification in this repository.
Code Samples & SDKs#
Unfortunately, the API Reference does not provide any code samples (not even curl) beyond the onboarding sample. My Zudoku project above does include code samples in case you want them.
The integration docs make reference to a gRPC and Python SDK - but do not link to them. You can use the Grok API via the OpenAI and Anthropic SDKs however - which makes migration easier, but isn't useful for developers that aren't already using those SDKs.
Overall, I feel like this documentation is below average, especially compared to other AI platform companies that offer richer docs, playgrounds, and SDKs.
API Documentation Score: 3/10
Developer Portal#
The developer portal for the xAI API is actually quite robust in its feature set. I suspect some engineers from X (formerly known as Twitter) were "loaned" to help with this. An engineer named Toby Phalen provided a feature overview via X, covering some prominent features of the dev portal.
Analytics#
The API features a usage explorer which includes breakdowns by tokens and spend.
Billing & Pricing#
Speaking of spend, you can easily connect a credit card to your account to start
purchasing credits. Pricing is determined by your choice of model. For example,
the grok-beta
model costs $5 per million input text tokens, and $15 per
million output text tokens.
There isn't a spend estimate tool to help you understand the translation from dollars to tokens - so you need to do your own math.
User Management#
User management is quite simple, invite your coworkers by email and they will get access. There is also a nice feature where you can verify a domain and everyone who signs up with that domain will get access to your team.
Auth & Security#
As stated earlier, we are a big fan of using API Keys for API authentication, and creating/managing keys is quite simple in the xAI console.
Account security is also top notch, with built-in session management and options for multi-factor authentication.
All things considered, this developer portal has everything you would expect from a modern API, and some nice security features.
Developer Portal Score: 9/10
Final Score#
Overall I'd give this API a final score of 19/30 which is slightly above average for an API - but I definitely expected more given how long it took to release. Some obvious improvements to be made include:
- Free credits to get started
- Fully documented API docs with a playground and code samples
- First-party SDKs rather than reusing OpenAI's
It's a bit frustrating to give this API a low score, because its so close to greatness, but falls flat right at the end.
Should You Consider the xAI API?#
The only reason to use the xAI API would be to get access to Grok, which differs greatly from GPT or Claude in terms of moderation and safety. So in reality, this API is likely your only option to use Grok. If you aren't too fussy about the model, and want a better DevX, I would recommend using OpenAI or Anthropic.
Alternatives to the xAI REST API#
The only alternative I was able to find was via the OpenRouter platform.
Building a Better API DevX Than xAI#
If you are revamping your API - and want to have:
- Automatically issued API Keys that actually work
- Autogenerated API documentation with code samples and a live playground
- Monetization system where you can offer a free tier
- Live usage analytics for yourself and your users
Then you need Zuplo - get in touch!