xAI
Route your xAI API calls through AI SpendOps for automatic usage tracking and cost attribution.
Configuration
| Setting | Value |
|---|---|
| Route | /v1/xai/* |
| Upstream | https://api.x.ai |
| Auth header | Authorization: Bearer ... |
| Streaming usage | Auto-injected (stream_options.include_usage) |
SDK base URL
https://proxy.aispendops.com/v1/xai/v1
Example
curl https://proxy.aispendops.com/v1/xai/v1/chat/completions \
-H "Authorization: Bearer your-xai-key" \
-H "X-ASO-API-Key: aso_k_yourkey.secret" \
-H "Content-Type: application/json" \
-d '{"model":"grok-3","messages":[{"role":"user","content":"Hello"}]}'
Usage fields
| Field | Description |
|---|---|
prompt_tokens | Input tokens |
completion_tokens | Output tokens |
total_tokens | Sum of prompt + completion tokens |
prompt_tokens_details.cached_tokens | Tokens served from cache |
Notes
- Grok models. OpenAI-compatible API.
- The proxy automatically injects
stream_options: { include_usage: true }for streaming requests.