API / list-models-via-xai-api

API

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

  1. Export the inference key outside of source control:
export XAI_API_KEY="your_api_key"
  1. Call the list endpoint and print the JSON:
curl https://api.x.ai/v1/models \
  -H "Authorization: Bearer $XAI_API_KEY" \
  | jq .
  1. Walk each object in data. Capture id for the request model field, aliases when clients use a shorter alias, context_length for window planning, and capabilities.reasoning_effort plus capabilities.default_reasoning_effort when the model accepts effort. For chat models, read prompt_text_token_price, cached_prompt_text_token_price, and completion_text_token_price (docs price these in USD cents per 100 million tokens). Image generation rows may expose image_price and an optional pricing matrix keyed by quality and resolution.

  2. 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/models list.

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.