← All integrations

Integration · xAI / Grok

xAI / Grok Prompt Management

Grok 4 is xAI's flagship model. Version your Grok system prompts in PromptForge and serve them via REST API, no redeployment when you iterate.

Integration Example

PromptForge + xAI / Grok in one file

Version, template, and serve xAI Grok prompts via REST API. Use the official @ai-sdk/xai package with generateText — fetch your versioned system prompt from PromptForge, pass it as the system field, and read the result from text. No redeployment when you iterate.

  1. 1
  2. Fetch your versioned, interpolated prompt from the PromptForge REST API with a single fetch() call.
  3. 2
  4. Pass the returned content string directly to the xAI / Grok SDK as the system prompt, no transformation needed.
  5. 3
  6. Update the prompt in the PromptForge dashboard anytime, running applications pick up the change on the next request. No redeployment required.
integration.ts
TypeScript
import { createXai } from "@ai-sdk/xai";
import { generateText } from "ai";

const xai = createXai({ apiKey: process.env.XAI_API_KEY });

async function fetchPrompt(persona: string, context: string) {
  const res = await fetch(
    "https://www.promptforge-app.com/api/v1/prompts/your-prompt-id",
    {
      method: "POST",
      headers: {
        Authorization: "Bearer pfk_your_api_key",
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        version: "latest",
        variables: { persona, context },
      }),
    }
  );
  const { content } = await res.json();
  return content as string;
}

// Prompt template in PromptForge (e.g.):
//   You are a {{persona}}. Context: {{context}}. Provide a concise response.
// 1. Fetch your versioned system prompt with dynamic variables
const system = await fetchPrompt("analyst", "market_research");

// 2. Pass the interpolated prompt to Grok 4
//    Update the prompt in PromptForge; no code change needed
const { text } = await generateText({
  model: xai.responses("grok-4"),
  system,
  prompt: "Summarise the key trends in AI infrastructure.",
});

console.log(text);
How It Works

xAI / Grok + PromptForge in Three Steps

Add a prompt management layer to your xAI / Grok integration without refactoring your application.

Step 1

Write your Grok system prompt template

Grok 4 accepts a dedicated system field in generateText. Create your prompt in PromptForge with {{persona}}, {{context}}, or {{task}} variables — one template, unlimited variations.

Step 2

Version every change with full diff history

Grok's long context and reasoning capabilities mean prompt wording matters. PromptForge tracks every edit, shows line-by-line diffs, and lets you roll back to any previous version in one click.

Step 3

Fetch and inject via the xAI SDK

Install @ai-sdk/xai and ai. Call createXai() with your XAI_API_KEY, then pass the PromptForge prompt string as the system field in generateText. The result comes back as text — no nested choices to unwrap.

Features

Powerful Prompt Management Features for AI Developers

From simple prompt storage to production-ready APIs with version control, dynamic variables, rollback, and a public gallery.

Dynamic Variables

Use {{variable}} syntax to create reusable prompt templates. Pass different values via API for endless customization across any LLM.

Instant Prompt API

RESTful API endpoint ready in seconds. Fetch any prompt with version pinning and variable interpolation. No redeployment needed.

Rollback with Diff Checker

View a line-by-line diff of every change and roll back to any previous version in one click. Never lose a working prompt again.

Publish to Gallery

Share your best prompts with the community in the public gallery. Get discovered by other developers and grow your personal library.

Start for free, upgrade anytime

No credit card required to get started. Paid plans include a 14-day free trial.

HobbyNo credit card
  • 1k API requests/month
  • 1 prompt
  • Unlimited versions
  • Dynamic variables
  • Version pinning
  • API key management
Start Managing My Prompts
Starter
14-day free trial
$9/month

No charge until your trial ends

  • 10k API requests/month
  • 5 prompt
  • Unlimited versions
  • Dynamic variables
  • Version pinning
  • API key management
Start 14-day Free Trial
Most Popular
Pro
14-day free trial
$29/month

No charge until your trial ends

  • 100k API requests/month
  • 25 prompt
  • Unlimited versions
  • Dynamic variables
  • Version pinning
  • API key management
Start 14-day Free Trial
Business
14-day free trial
$49/month

No charge until your trial ends

  • 500k API requests/month
  • 100 prompt
  • Unlimited versions
  • Dynamic variables
  • Version pinning
  • API key management
Start 14-day Free Trial

Questions? Contact us

FAQ

xAI / Grok + PromptForge: Common Questions

Specific answers for developers integrating PromptForge with xAI / Grok.

How do I use PromptForge with Grok's function calling?

The Vercel AI SDK supports tools via the tools parameter in generateText. Store the system prompt that instructs Grok when and how to use tools in PromptForge. Fetch it at runtime and pass it as the system field alongside your tools object. The tool schemas stay in code; only the instructional prompt lives in PromptForge for versioning.

Does PromptForge work with Grok's reasoning models?

Yes. Pass any xAI model string to xai.responses() — for example grok-4 or grok-4-1-fast-reasoning. The system prompt you fetch from PromptForge is the same regardless; choose the model variant based on whether you need extended reasoning. PromptForge only supplies the prompt text; model selection is a separate parameter.

Why use @ai-sdk/xai instead of the OpenAI SDK?

@ai-sdk/xai is xAI's first-party JavaScript SDK. It exposes a clean system field, returns text directly, and gives you streaming, structured outputs, and tool calling through a unified API. The OpenAI SDK works too (pointed at https://api.x.ai/v1) but requires using the responses.create() shape. Both approaches work identically with PromptForge since it returns plain text.

How do I use PromptForge with Grok's long context window?

Grok supports up to 131,072 tokens. Your PromptForge system prompt is typically a small fraction of that. Fetch the prompt from PromptForge as usual and pass it as the system field — the long context is used for conversation history and user-provided documents, not for the system prompt retrieval. PromptForge adds no constraint on context length.