Home › SpaceXSI API tutorial for beginners
SpaceXSI API tutorial for beginners
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
- Go to console.x.ai and create a SpaceXSI account.
- Add credits to the account (the API is paid by usage).
- Open the API Keys page and create a key.
- Store it as an environment variable named XAI_API_KEY, or in a .env file that you keep out of version control.
- 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
- Create your account at console.x.ai and add credits.
- Create an API key on the API Keys page and run: export XAI_API_KEY="your_api_key"
- Install the OpenAI SDK for Python: pip install openai
- Create a client with base_url="https://api.x.ai/v1" and your key.
- Call client.responses.create(model="grok-4.7", input="…") and print response.output_text.
- Try the same request in the console Playground if you'd rather not write code yet.
Try it: examples
- First request (input text)
Fix this function and explain the bug: function median(a){a.sort();return a[a.length/2]} - A plain-language task
Rewrite this product description in under 50 words for a phone screen: [paste text]
Good to know
- Never paste your key into code you share or commit; read it from XAI_API_KEY.
- The docs recommend grok-4.7 for text and code and dedicated models for audio, image and video.
- grok-4.7 has a 500k-token context; prompts of 200k tokens or more are billed at the higher long-context rate for the whole request.
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.