Skip to main content

xAI's Grok models are now available in AI Gateway

AI Gateway now supports five new built-in models from xAI:

  • grok-4.3, with a 1M token context window
  • grok-4.5, with a 500K token context window
  • grok-4.6, with a 500K token context window
  • grok-4.7, with a 500K token context window
  • grok-build-0.1, with a 256K token context window

Use your ngrok access key and credits for built-in inference. Point an OpenAI SDK client at AI Gateway to try these models in your application and inspect their requests in one place.

Check Models for each model’s input and output token prices, context window, and supported request formats. Costs depend on the model you choose and the tokens your application sends and receives.

Get started

Create an ngrok account or sign in. Create an access key that allows your chosen provider and model, and confirm your account has credits.

Optionally, try one of the new Grok models in the playground.

Follow the setup guide and select OpenAI and TypeScript.

Install the OpenAI SDK and TypeScript runner:

npm install openai && npm install --save-dev tsx

Save your ngrok access key in .env.local. Keep this file out of version control:

AI_GATEWAY_API_KEY=your_access_key_here

Use an ES module project ("type": "module" in package.json) for top-level await. Save this example as index.ts:

import OpenAI from "openai"; const client = new OpenAI({	baseURL: "https://gateway.ngrok.ai/v1",	apiKey: process.env.AI_GATEWAY_API_KEY,}); const response = await client.chat.completions.create({	model: "xai/grok-4.3",	messages: [{ role: "user", content: "Explain HTTP retries in two sentences." }],}); console.log(response.choices[0]?.message.content);

Run the example from your project directory to print the response:

node --env-file=.env.local --import tsx index.ts

To try another model, change model to "xai/grok-4.5", "xai/grok-4.6", "xai/grok-4.7", or "xai/grok-build-0.1".

Open Logs, find the request you just sent, and inspect its model, provider, status, token usage, and cost.