xAI System Prompts: Set and Test Grok Instructions

xAI provides the Grok models through an API and a product interface. Here is how to supply a system prompt through the xAI API, what the Grok product lets you change, and how to carry prompts across models.

Updated 5 min read

xAI offers Grok models through two channels: the Grok product at grok.x.ai and the xAI API for developers. The Grok product gives end users limited customization options. The xAI API accepts a full system prompt in the standard messages format, similar to the OpenAI and Anthropic APIs. Tools like fenbs keep your tested prompts alongside the project context they belong to, so the same instructions are available when you switch between models or sessions.

Check the xAI API documentation (opens in a new tab) for the current endpoint addresses, available models, and supported parameters. Both the API and the Grok product change as xAI updates the platform.

Two ways to reach xAI models

The Grok product (grok.x.ai) is the conversational interface. Users can set some preferences and use a "memory" feature if they have it enabled. The product system prompt -- the instructions xAI uses to define Grok's default behavior -- is not editable by users.

The xAI API gives developers direct access to the underlying models. You send a request with a messages array, include a system role message, and the model follows those instructions for the session. This is where you set your own system prompt, independent of the Grok product.

Setting a system prompt through the xAI API

The xAI API uses a request format compatible with OpenAI's Chat Completions endpoint. You set the base URL to https://api.x.ai/v1, use an xAI API key, and send requests in the same structure. A system role message in the messages array sets the instructions for the session.

A minimal xAI API request with a system prompt
{
  "model": "grok-3",
  "messages": [
    {
      "role": "system",
      "content": "You are a technical writing assistant. Respond in plain US English. Use active voice. Keep paragraphs to four sentences or fewer."
    },
    {
      "role": "user",
      "content": "Explain what a context window is."
    }
  ]
}

Because the format is OpenAI-compatible, existing code that sets a system prompt for GPT models can be pointed at the xAI endpoint with minimal changes. Test after switching: the same instruction may produce slightly different behavior on a different model family.

What the Grok product lets you change

In the Grok product interface, users can set a name and some conversation preferences. If the memory feature is available and enabled on your account, Grok can recall facts from previous conversations. These are product features, not system prompt controls. The base instructions that define Grok's personality and behavior policies are set by xAI.

This mirrors how most AI products work: the vendor defines the base instructions, and users add preferences on top. Your additions influence tone and focus but do not override xAI's policies.

Testing your instructions

After writing a system prompt for a Grok model, test it with the xAI API Playground or send a few requests through the API directly. Check that the model follows your format rules, stays in scope, and handles the edge cases you care about.

Specifically test what happens when the user asks the model to ignore your instructions. A clear, specific instruction -- "do not answer questions outside the topic of technical documentation" -- resists override better than a vague one. Note where the model complies and where it does not, and refine the instruction for the failing cases.

Also test after model updates. xAI releases updated Grok versions; an instruction that worked on an earlier version may behave differently on a newer one. Note the model version you tested on and re-verify when you upgrade.

Carrying prompts across models

A system prompt you wrote for a Grok model is mostly portable to other OpenAI-compatible APIs -- the same format, the same role names, the same message structure. The content of the instructions usually travels too. What changes is how each model interprets and applies them. Grok may emphasize different aspects of an instruction than Claude or GPT-4o would.

When moving a prompt between models, test the core behavior and edge cases again. A subtle difference in how models handle ambiguous instructions can produce noticeably different output. For more on keeping context when switching, portable AI memory covers what to save.

How fenbs helps

Keep your tested prompts where any model can use them

fenbs keeps a shared Skills and prompts library for your projects. Save the system prompt you finalized for Grok, note the model version, and record what you tested. When you try the same prompt on Claude or another model, update the Skill with the result. Any connected assistant can read the current version at the start of a session.

Create a free account

Free for one person · No credit card · Works with Claude, ChatGPT, Cursor and more

Operator and user instructions in the xAI API

In the xAI API, the system message represents the operator's instructions -- the rules set by whoever is building with the API. User messages represent what the end user sends. The model is expected to follow the operator's system message as a higher-priority set of instructions and to assist the user within those constraints.

This distinction matters when you are building a product with the xAI API rather than using it directly. Write the system prompt for the operator role: define scope, persona, and restrictions. Think through the cases where a user might ask for something outside the scope and write the system prompt to handle those cases gracefully.

How to do this with fenbs

  1. Create a free account. Start with a personal kanban board for this project.
  2. Add a task for the system prompt you are building. Note the intended model, the purpose, and the key rules.
  3. Test the prompt with the xAI API. Record the test results in the task: what worked, what failed, what you refined.
  4. Save the approved version as a Skill in fenbs. Note the model version it was tested on and the date.
  5. When you use the same prompt with a different model, add a test note to the Skill with the new model's results.

Related: system prompt examples has patterns worth adapting for xAI API work. Prompt engineering covers the general principles. For the tradeoffs between system prompts and user-level instructions, system prompt vs. user prompt is the right reference.

Questions people ask.

Does the xAI API support system prompts?

Yes. The xAI API uses an OpenAI-compatible messages format. Include a message with "role": "system" at the start of the array. The API endpoint and available models are documented at docs.x.ai.

Can I set a system prompt in the Grok product interface?

No. The Grok product interface lets you set some preferences and use memory features, but the base system prompt is set by xAI and is not editable. For full system prompt control, use the xAI API.

Is the xAI API format the same as OpenAI's?

The request structure is compatible: same messages array, same role names, same general format. You change the base URL and use an xAI API key. The models themselves behave differently, so test your instructions after switching.

Which Grok model should I use for API calls?

Check the current model list in the xAI API documentation. Model availability and capabilities change as xAI releases updates. The documentation is the authoritative source.

Can a user override my xAI API system prompt?

A user message can sometimes weaken or override a system prompt, especially if the instruction is vague. Test with adversarial inputs and write specific, verifiable rules rather than general principles.

Start with one thing.

Free for one person · No credit card · Works with Claude, ChatGPT, Cursor and more

There is nothing to set up first. Write one line and you’ve started.