Skip to main content
This guide provides instructions for integrating Grok Build with the TrueFoundry AI Gateway.

What is Grok Build?

Grok Build is xAI’s coding agent that runs in your terminal as an interactive TUI, headlessly in scripts, or through the Agent Client Protocol (ACP). The CLI is invoked with the grok command. Grok Build supports custom models, which lets you point it at the TrueFoundry AI Gateway and route requests through a single endpoint with unified auth, logging, and governance.

Prerequisites

Before integrating Grok Build with TrueFoundry, ensure you have:
  1. TrueFoundry Account: Create a TrueFoundry account with at least one model provider configured and generate a Personal Access Token by following the instructions in Generating Tokens. For a quick setup guide, see our Gateway Quick Start
  2. Grok Build Installation: Install the grok CLI using the appropriate command for your platform:
curl -fsSL https://x.ai/cli/install.sh | bash
See the Grok Build install guide for the latest installation options.

Setup Process

1. Get Configuration Details

Get the base URL and model name from your TrueFoundry AI Gateway playground using the unified code snippet:
TrueFoundry playground showing unified code snippet with base URL and model name highlighted for Grok Build integration

2. Configure Grok Build

Grok Build reads configuration from ~/.grok/config.toml. Create the file (and the ~/.grok directory) if it does not exist, then register the TrueFoundry Gateway as a custom model:
[endpoints]
models_base_url = "{GATEWAY_BASE_URL}"

[model.grok-build]
model = "xai-main/grok-build-0.1"
name = "Grok Build (TrueFoundry)"
env_key = "TFY_API_KEY"

[models]
default = "grok-build"
Then export your TrueFoundry API key. Add this line to your shell profile (.bashrc, .zshrc, etc.) to make it persistent:
export TFY_API_KEY="your-truefoundry-api-key"
Replace the placeholders:
  • {GATEWAY_BASE_URL} → Your TrueFoundry Gateway Base URL (how to find it)
  • your-truefoundry-api-key → Your TrueFoundry Personal Access Token from Generating Tokens
  • xai-main/grok-build-0.1 → Your desired model in provider-account-name/model-name format
The model value must be the fully qualified model name as shown in the TrueFoundry AI Gateway playground (e.g. xai-main/grok-build-0.1, openai-main/gpt-5.4, anthropic/claude-opus-4-7). The [model.<key>] section name (grok-build above) is just a local alias you use to select this model with the -m flag or the /model command in the TUI — pick whatever name is convenient.
[endpoints] models_base_url sets a single base URL for every [model.*] entry, so you only configure the Gateway URL once. See the Grok Build custom models reference for all available fields.

3. Configure Multiple Models (Optional)

You can register multiple models from different providers and switch between them inside a session with /model <alias>:
[endpoints]
models_base_url = "{GATEWAY_BASE_URL}"

[model.grok-build]
model = "xai-main/grok-build-0.1"
name = "Grok Build (TrueFoundry)"
env_key = "TFY_API_KEY"

[model.gpt-5-4]
model = "openai-main/gpt-5.4"
name = "GPT-5.4 (TrueFoundry)"
env_key = "TFY_API_KEY"

[model.opus-4-7]
model = "anthropic/claude-opus-4-7"
name = "Claude Opus 4.7 (TrueFoundry)"
env_key = "TFY_API_KEY"

[models]
default = "grok-build"
All three models share the same models_base_url and TFY_API_KEY, so the Gateway routes each request to the correct upstream provider based on the model value.

Usage Examples

Interactive Mode

Launch the TUI in your project directory:
cd your-project/
grok
Once inside the session, you can ask questions about your codebase, generate code, and run shell commands using natural language. Switch models mid-session with /model <alias>.

Headless Mode

Use the -p flag to run Grok Build without the interactive UI — ideal for scripts, automation, and CI/CD:
# Run with the default model
grok -p "Explain this codebase"

# Pick a specific model alias from your config
grok -p "Refactor this function to use async/await" -m gpt-5-4

# Stream JSON output for downstream tooling
grok -p "Write unit tests for the auth module" --output-format streaming-json

Inspect Configuration

Verify that Grok Build picked up your TrueFoundry models, config sources, and MCP servers:
grok inspect
This is useful for debugging which model and base URL Grok Build will use for a given request.

Observability

All requests routed through the TrueFoundry AI Gateway are automatically logged and available for monitoring. View request traces, latencies, token usage, and full request/response details in the TrueFoundry dashboard. This gives you full visibility into:
  • Request traces: See every request made by Grok Build, including the model used and response times
  • Token usage: Track input and output token consumption across sessions
  • Cost monitoring: Monitor spend across different models and providers
  • Governance: Enforce policies, rate limits, and access controls on all AI requests