Repository Public
1<!-- source: https://docs.x.ai/developers/community/google-cloud-vertex-ai (from https://docs.x.ai/llms-full.txt, retrieved 2026-09-19T05:28:55Z) -->2#### Community Integrations34# Google Cloud Vertex AI56Access xAI’s Grok models through Google Cloud’s managed platform with enterprise security, governance, and unified billing.78This guide walks through setting up and using Grok models on Google Cloud Vertex AI / Gemini Enterprise Agent Platform. Grok on Vertex AI is accessed as a partner model through the OpenAI-compatible API, including the Responses API and Chat Completions. Models are enabled through Model Garden.910## Prerequisites1112Before you begin, ensure you have:1314* An active Google Cloud Platform (GCP) project with billing enabled.15* Permissions to enable APIs and access Model Garden, such as the Vertex AI User or Project Editor role.16* The `aiplatform.googleapis.com` API, or equivalent Agent Platform API, enabled in your project.17* Google Cloud CLI (`gcloud`) installed and authenticated for Application Default Credentials (ADC).1819Set up ADC and your project:2021```bash customLanguage="bash"22gcloud auth application-default login23gcloud config set project YOUR_PROJECT_ID24```2526Enable the required API if it is not already enabled:2728```bash customLanguage="bash"29gcloud services enable aiplatform.googleapis.com30```3132## Install required packages3334```bash customLanguage="bash"35pip install -U openai google-cloud-aiplatform36```3738## Enable Grok models in Model Garden39401. Go to the Google Cloud Console Model Garden, or search for “Model Garden” in the console.412. Search for “Grok”, or browse by publisher xAI.423. Select the desired Grok model, such as Grok 4.2 or Grok 4.3.434. Review the model card for capabilities, quotas, pricing, and regions.445. Click **Enable** or **Deploy / request access** if prompted.456. Once enabled, the model becomes available for API calls.4647Use the model ID shown in Model Garden. Vertex model names may use a publisher prefix, for example:4849* `xai/grok-4.6`5051Model availability generally matches the xAI API, subject to Google Cloud regional availability and quotas.5253## Make your first API call5455Grok on Vertex uses the OpenAI-compatible interface. You can use the standard `openai` Python library.5657### Authentication5859Use Application Default Credentials. The client can pick up your `gcloud` auth or service account credentials.6061You may need to set the Vertex/OpenAI-compatible base URL or endpoint with an environment variable or directly in the client. Use the exact endpoint from the model card or Google documentation for the Agent Platform.6263```bash customLanguage="bash"64export OPENAI_BASE_URL="https://YOUR_VERTEX_ENDPOINT"65```6667### Responses API example6869```python customLanguage="pythonOpenAISDK"70from openai import OpenAI7172client = OpenAI() # Uses ADC / env vars automatically7374response = client.responses.create(75 model="xai/grok-4.6",76 input="Explain the advantages of using Grok for agentic workflows with parallel tool calling.",77 max_output_tokens=800,78)7980print(response.output_text)81```8283### Chat Completions example8485```python customLanguage="pythonOpenAISDK"86from openai import OpenAI8788client = OpenAI()8990response = client.chat.completions.create(91 model="xai/grok-4.6",92 messages=[93 {94 "role": "user",95 "content": "Which city has a higher temperature right now, Boston or New Delhi, and by how much in Fahrenheit?",96 }97 ],98 tools=[99 {100 "type": "function",101 "function": {102 "name": "get_current_weather",103 "description": "Get the current weather in a given location",104 "parameters": {105 "type": "object",106 "properties": {107 "location": {108 "type": "string",109 "description": "The city and state, e.g., San Francisco, CA",110 },111 "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},112 },113 "required": ["location"],114 },115 },116 }117 ],118 tool_choice="auto",119)120121print(response.choices[0].message.content)122```123124Streaming is supported on both interfaces for lower-latency experiences.125126## Function calling and tool use127128Grok excels at tool use and parallel function calling across the Responses API and Chat Completions interfaces. Define clear, strict schemas for tools so the model can select and call them reliably.129130## Data retention and compliance131132Data retention and processing for Grok models on Google Cloud are governed by Google Cloud Vertex AI policies.133134* Many deployments support Zero Data Retention (ZDR) options.135* Review the specific model card and your organization’s Google Cloud data governance settings.136* Activity logging can be enabled with Vertex AI request-response logging for audit and debugging purposes.137138See Google Cloud documentation on Vertex AI data governance and logging for details.139140## Feature support141142Supported capabilities include:143144* Responses API and Chat Completions.145* Function calling and tool use, including parallel function calling.146* Reasoning modes / extended thinking.147* Structured outputs / JSON mode.148* Streaming.149* Fixed quotas and committed use discounts through Google Cloud.150151Context windows vary by model. Check the specific Grok model card in Model Garden for the current limit.152153## Global, multi-region, and regional endpoints154155Vertex AI / Gemini Enterprise Agent Platform offers flexible endpoint routing:156157* **Global endpoints:** maximum availability with dynamic routing; recommended for most use cases.158* **Regional endpoints:** routing through specific regions for strict compliance requirements.159160## Best practices161162* Choose the Grok model and endpoint configuration that match your latency, throughput, and reasoning requirements.163* Prefer Application Default Credentials and IAM roles over long-lived keys. Use service accounts for production workloads.164* Monitor usage in Google Cloud Billing and Quotas pages. Request quota increases as needed.165* Use clear tool schemas and explicit output formats.166* Enable request logging and integrate with Google Cloud Monitoring / Logging.167* When migrating from the direct xAI API, update the base URL, client configuration, and model prefix. Most prompts and tool definitions transfer with minimal changes.168169## Troubleshooting170171| Issue | What to check |172|---|---|173| Authentication errors | Run `gcloud auth application-default login` and verify project permissions. |174| Model not found | Confirm the model is enabled in Model Garden and use the exact `xai/...` ID. |175| Quota exceeded | Check quotas in the Google Cloud console and request increases as needed. |176| Endpoint / base URL issues | Use the exact endpoint or environment variable from the model card or Google documentation. |177178Start in the Google Cloud console playground / Model Garden interface when available, then move to code.179180## Next steps181182* Explore enabled models in Model Garden.183* Build agentic applications that use Grok’s tool-calling strengths.184* Integrate with Google Cloud services such as Cloud Functions and Vertex AI Pipelines.185* Review the full xAI Grok documentation and model cards for prompting tips and capabilities.186