What is the difference between system and user prompt
system prompt sets the AI's overall behavior and context before interaction, guiding tone and constraints. A user prompt is the actual input or question the user wants the AI to respond to during the conversation.VERDICT
system prompts to define AI behavior and context; use user prompts for specific user queries and instructions.| Prompt type | Purpose | When used | Example role | Typical content |
|---|---|---|---|---|
system prompt | Set AI behavior and context | At conversation start or reset | System | Instructions, tone, constraints |
user prompt | User's question or command | During conversation | User | Queries, tasks, requests |
Key differences
The system prompt defines the AI's role, style, and rules before any user input. It acts as a guiding framework for the entire session. The user prompt is the actual input from the user that the AI responds to, such as questions or commands. System prompts are typically set once per session, while user prompts occur repeatedly during interaction.
Side-by-side example
Example of using system and user prompts together in OpenAI's gpt-4o chat API:
from openai import OpenAI
import os
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": "You are a helpful assistant that responds formally."},
{"role": "user", "content": "Explain the difference between system and user prompts."}
]
)
print(response.choices[0].message.content) The system prompt sets the assistant's formal tone and behavior, while the user prompt asks the specific question to answer.
User prompt equivalent
Using only a user prompt without a system prompt results in default AI behavior. Here is the same question asked without system instructions:
from openai import OpenAI
import os
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "user", "content": "Explain the difference between system and user prompts."}
]
)
print(response.choices[0].message.content) User prompts are the inputs you give to the AI, while system prompts set the AI's behavior and context.
When to use each
Use system prompts to establish AI personality, tone, or constraints before user interaction. Use user prompts to ask questions, give commands, or provide data during the conversation.
| Prompt type | Use case | Example |
|---|---|---|
system prompt | Set tone and rules | "You are a friendly assistant." |
user prompt | Ask questions or commands | "Summarize the latest news." |
Pricing and access
Both system and user prompts count toward token usage in API calls. They are part of the same message array in chat completions, so pricing is identical.
| Option | Free | Paid | API access |
|---|---|---|---|
| OpenAI chat API | Yes, limited tokens | Yes, pay per token | Yes |
| Anthropic Claude | Yes, limited tokens | Yes, pay per token | Yes |
| Google Gemini | Check pricing | Yes, pay per token | Yes |
| Open-source models | Yes, fully free | No | No API |
Key Takeaways
- Use
systemprompts to control AI behavior and conversation context globally. - Use
userprompts for specific user inputs and queries during interaction. - Both prompt types are required for effective AI conversations and count toward token usage.