Notebooks
G
Google Gemini
System Instructions REST

System Instructions REST

quickstartsrestgemini-cookbookgemini-apigemini
Copyright 2025 Google LLC.
[ ]

Gemini API: System instructions example

This notebook provides a quick code example that shows you how to get started with system instructions using curl.

You can run this in Google Colab, or you can copy/paste the curl commands into your terminal.

To run this notebook, your API key must be stored it in a Colab Secret named GOOGLE_API_KEY. If you are running in a different environment, you can store your key in an environment variable. See Authentication to learn more.

[ ]
[ ]

Use system instructions

Call the generateContent method with the system_instruction field set:

[ ]
MODEL_ID
[ ]
{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "text": "Meow 😺 \n"
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP",
      "index": 0,
      "safetyRatings": [
        {
          "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_HATE_SPEECH",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_HARASSMENT",
          "probability": "NEGLIGIBLE"
        },
        {
          "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
          "probability": "NEGLIGIBLE"
        }
      ]
    }
  ]
}
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   167    0     0  100   167      0    138  0:00:01  0:00:01 --:--:--   138
100   877    0   710  100   167    585    137  0:00:01  0:00:01 --:--:--   724

Use system instructions with chat

system_instruction works for multi-turn, or chat, generations too.

[ ]
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "text": "Neko! Neko is my name! 😸 I like milkies! 🥛 \n"
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP",