Skip to main content

xAI

Route your xAI API calls through AI SpendOps for automatic usage tracking and cost attribution.

Configuration

SettingValue
Route/v1/xai/*
Upstreamhttps://api.x.ai
Auth headerAuthorization: Bearer ...
Streaming usageAuto-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

FieldDescription
prompt_tokensInput tokens
completion_tokensOutput tokens
total_tokensSum of prompt + completion tokens
prompt_tokens_details.cached_tokensTokens served from cache

Notes

  • Grok models. OpenAI-compatible API.
  • The proxy automatically injects stream_options: { include_usage: true } for streaming requests.