Gemini · Gemini API
How to Change System Instructions Mid-Conversation in the Gemini API
In a long session the rules change: a deployment freeze starts, a user turns out to be in a regulated region, a feature gets paused. Editing your original system instruction or tool list makes the model reprocess the whole history and invalidates the prompt cache. A system_input step appends the change instead, so earlier turns stay cached. This guide is for developers calling the API. It does not apply to the Gemini app.
GPTPrompts.AI Editorial
Steps verified against the vendor's own documentation · Last updated December 2026
Affiliate link, we may earn a commission at no extra cost to you.
01 · The steps
Pick the route that matches your situation
Send a new instruction mid-conversation
Python SDK shown. The feature needs the v1beta API version.
- 1Create the client with the v1beta API version.
- 2Send the first turn with client.interactions.create and keep the id it returns.
- 3On the next turn, pass that id as previous_interaction_id.
- 4Make input a list. Put a step with type system_input first, with your instruction as a text item in content.
- 5Put the user_input step directly after it.
- 6Keep your top-level system_instruction the same on every turn, so the cached prefix stays valid.
Add or remove function tools
For example after a user completes OAuth, or when a feature is paused.
- 1Send the same top-level tools list on every turn. Do not edit it between turns.
- 2On the system_input step, add removed_tools as objects with type function and the tool's name.
- 3Add added_tools as full function definitions, using the same schema as entries in tools.
- 4Include a short text note in content when you remove a tool, so the model can explain why the action is unavailable.
- 5On later turns, keep removed tools in the top-level tools list and leave added tools out of it.
Reverse an earlier instruction
You cannot delete a system_input. You can only add another one.
- 1Send a new system_input step on the next user turn.
- 2State what changed and tell the model to ignore the earlier rule, for example that refunds are available again.
- 3If you removed a tool earlier, add it back with added_tools in the same step.
Check what the model was told
Useful when debugging why a rule was or was not followed.
- 1Call client.interactions.get with the interaction's id.
- 2Loop over the steps it returns.
- 3Confirm the system_input step appears before the user_input step, with any added_tools and removed_tools.
02 · Copy and adapt
Code you can adapt
Both examples follow the request shape in Google's documentation. Swap in your own model, instruction and tools.
Add a rule on turn two (Python)
from google import genai client = genai.Client(http_options={"api_version": "v1beta"}) system_instruction = "You are a support assistant for an online store." first = client.interactions.create( model="gemini-4-hydrogen", system_instruction=system_instruction, input="Hi, I need help with an order.", ) second = client.interactions.create( model="gemini-4-hydrogen", previous_interaction_id=first.id, system_instruction=system_instruction, input=[ { "type": "system_input", "content": [ { "type": "text", "text": "Refunds are paused while this account is under billing review. Explain that and offer to escalate.", } ], }, { "type": "user_input", "content": [{"type": "text", "text": "Please refund order 12345."}], }, ], ) print(second.output_text)
Swap a tool in the same step (Python)
# Pass the same top-level tools list on every turn. third = client.interactions.create( model="gemini-4-hydrogen", previous_interaction_id=second.id, system_instruction=system_instruction, tools=tools, input=[ { "type": "system_input", "content": [ {"type": "text", "text": "Refunds are paused. Offer an escalation ticket instead."} ], "removed_tools": [{"type": "function", "name": "issue_refund"}], "added_tools": [ { "type": "function", "name": "create_escalation_ticket", "description": "Escalate a billing review issue to support.", "parameters": { "type": "object", "properties": {"order_id": {"type": "string"}}, "required": ["order_id"], }, } ], }, { "type": "user_input", "content": [{"type": "text", "text": "Can I get my money back?"}], }, ], )
Reverse an earlier rule (instruction text)
Refunds are available again. Ignore the earlier instruction that paused refunds.
03 · Read this first
What most guides leave out
Breaking a placement rule returns HTTP 400
Send system_input directly before a user_input step, at most once per turn, with text only. Do not send it on its own or while returning a function_result in a function-calling loop. Wait for the next user turn.
Instructions add up, they do not replace
Your top-level system_instruction and every earlier system_input stay in context for the rest of the conversation. When two conflict, the model favours the most recent, so say explicitly what changed.
A system_input cannot be removed
Each step stays in context for the rest of the conversation. Keep them short, and keep baseline behaviour in system_instruction.
Do not drop a removed tool from the tools list
The API validates stored history against each request's tools list. Dropping a tool you removed with removed_tools returns HTTP 400 on later turns.
Do not re-declare an added tool
Leave tools you added with added_tools out of the top-level tools list on later turns. Re-declaring an active added tool returns HTTP 400.
Only custom function tools can change
added_tools and removed_tools do not currently support MCP servers or built-in tools such as Google Search or code execution.
tool_choice ignores added tools
Function calling modes only apply to tools in your initial tools list. The model can still call tools added mid-conversation.
It is a preview
Google says the API surface may change before general availability. Other models return HTTP 400.
04 · Questions
Frequently asked questions
Can you change the system instruction mid-conversation in the Gemini API?
Yes, on the Interactions API. Send a system_input step before the user_input step on a later turn. It appends a new instruction and leaves earlier turns cached.
Does system_input work with generateContent?
No. It is supported on the Interactions API only, on the v1beta API version. The generateContent method does not support it.
Which Gemini models support system_input?
Google lists gemini-4-carbon, gemini-4-neon and gemini-4-hydrogen. Other models return an HTTP 400 error.
Does a system_input override the user's message?
Google says a system_input carries the same authority as the top-level system instruction and takes precedence over user messages.
Does a mid-conversation instruction replace the original system instruction?
No. It is added to the conversation as its own step. The original system_instruction and all earlier system_input steps stay in context, and the model favours the most recent one when they conflict.
Why not just edit the system instruction on the next turn?
Because rewriting the system instruction or changing the tools list invalidates the prompt cache. The model reprocesses the entire conversation history, which adds cost and latency.
Can I use system_input with agent interactions?
No. It is supported on model interactions only.
Sources
- Gemini API docs: Mid-conversation system instructions
- Google blog: Introducing mid-conversation instructions in the Gemini API
Menu names change. If a step no longer matches what you see, the vendor documentation above is the authority.
Keep going
Affiliate link, we may earn a commission at no extra cost to you.
Also from the GPTPrompts team
More free AI resources from our sister sites
- Our free AI coursesLearnWithZavi: Learn AI for free, at your own paceShort, practical AI courses with no paywall and no signup, from your first prompt to using AI at work.Start learning free
- Our AI deals siteAIDeals: Check for a deal before you pay full priceDiscounts, promo codes and free tiers on AI tools, each checked against the vendor's own pricing page and dated. Plus cost calculators and plan comparisons.Browse AI deals
- Our AI agents directoryBestAIAgents: Compare AI agents side by sideAn independent directory of AI agents with pricing, limitations and a verification date on every listing. Rankings are not paid.Browse AI agents
- Our AI jobs boardAIGlobalWork: Find paid AI training jobsOpen AI tutor, rater and expert-review roles from Mercor, Alignerr, Scale AI, xAI and more, with the pay each platform lists.Browse AI jobs