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.
{
"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.
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 accountFree 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
- Create a free account. Start with a personal kanban board for this project.
- Add a task for the system prompt you are building. Note the intended model, the purpose, and the key rules.
- Test the prompt with the xAI API. Record the test results in the task: what worked, what failed, what you refined.
- Save the approved version as a Skill in fenbs. Note the model version it was tested on and the date.
- 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.