
List models via the xAI API
Pull every model your inference API key can call — including ids, aliases, context length, reasoning-effort options, and token or image prices — so you can pick a live model string before you ship a client or ACL change. Official Models REST reference documents GET /v1/models on https://api.x.ai, authorized with a Bearer inference key. The response wraps a data array of model objects plus object: "list". Create a key and load credits at console.x.ai.
What you need
An XAI_API_KEY that can hit inference routes, a terminal with curl and preferably jq, and a reason to inventory what this key sees rather than guessing from the marketing table. Neighboring jobs include Get a model via the xAI API when you already know the id, List team models via the xAI Management API when you need cluster-scoped ACL names with a management key, and List available models with grok models for the Build CLI catalog. More API jobs live on the API hub.
List models for this key
- Export the inference key outside of source control:
export XAI_API_KEY="your_api_key"
- Call the list endpoint and print the JSON:
curl https://api.x.ai/v1/models \
-H "Authorization: Bearer $XAI_API_KEY" \
| jq .
Walk each object in
data. Captureidfor the requestmodelfield,aliaseswhen clients use a shorter alias,context_lengthfor window planning, andcapabilities.reasoning_effortpluscapabilities.default_reasoning_effortwhen the model accepts effort. For chat models, readprompt_text_token_price,cached_prompt_text_token_price, andcompletion_text_token_price(docs price these in USD cents per 100 million tokens). Image generation rows may exposeimage_priceand an optionalpricingmatrix keyed by quality and resolution.Prefer ids and aliases from this response over hard-coding a slug you saw in a blog post last month. When you need modalities, fingerprints, or search price, call the fuller
GET /v1/language-models(or image/video generation model lists) from the same reference — those routes return richer fields than the minimal/v1/modelslist.
Pitfalls
Using a management key against https://api.x.ai/v1/models will fail auth — management listing lives on https://management-api.x.ai. Treating token price integers as dollars per million without converting from the documented cents-per-100M scale will mis-estimate spend. Assuming every alias in marketing docs appears for your key is wrong when team ACLs or regional availability hide a model from that key’s list.