Home › SpaceXSI API tutorial for beginners

SpaceXSI API tutorial for beginners

Last checked

The API is reached at https://api.x.ai/v1 and works with the OpenAI and Vercel AI SDKs as well as SpaceXSI's own xAI SDK, so you only change the base URL and the key.

Sign up and log in

  1. Go to console.x.ai and create a SpaceXSI account.
  2. Add credits to the account (the API is paid by usage).
  3. Open the API Keys page and create a key.
  4. Store it as an environment variable named XAI_API_KEY, or in a .env file that you keep out of version control.
  5. Install an SDK: the xAI SDK (pip install xai-sdk), the OpenAI SDK (pip install openai or npm install openai) or the Vercel AI SDK (npm install ai @ai-sdk/xai zod).

Step by step

  1. Create your account at console.x.ai and add credits.
  2. Create an API key on the API Keys page and run: export XAI_API_KEY="your_api_key"
  3. Install the OpenAI SDK for Python: pip install openai
  4. Create a client with base_url="https://api.x.ai/v1" and your key.
  5. Call client.responses.create(model="grok-4.7", input="…") and print response.output_text.
  6. Try the same request in the console Playground if you'd rather not write code yet.

Try it: examples

Good to know

Prices (US$)

Text model grok-4.7: US$2.00 per million input tokens and US$6.00 per million output tokens (prompts under 200k tokens). Images from US$0.02 each. All API prices are listed in USD on the docs pricing page.

Sources (official pages, read Nov 8, 2026)

Written from SpaceXSI's official documentation and product pages; we don't run hands-on tests. Features and limits vary by plan and country.

Report an error on this page