You can reuse existing prompts in GCP Generative AI by leveraging prompt tuning or prompt templates stored in a database or a configuration file, referencing them with an ID instead of sending full content in every request.
Here is the code snippet you can refer to:

In the above code we are using the following key points:
- Prompt Storage – Saves prompts in a dictionary (PROMPT_TEMPLATES), reducing redundant API payloads.
- Dynamic Prompt Retrieval – Retrieves stored prompts using an identifier (prompt_id).
- Parameterization – Supports dynamic content replacement via .format(**kwargs).
- Efficient API Calls – Sends only the necessary information to GCP Generative AI.
- Scalability – Can be extended to use a database or configuration file instead of a dictionary.
Hence, using prompt templates stored locally or in a database allows efficient reuse of existing prompts while reducing API request payload size.
.