I have had partaken will always be ungrammatical. So, the sentence needs to be rephrased no matter what.
To me, there are more idiomatic ways of writing the sentence:
1. By the time I finish writing this text, I will have partaken of the brew for a total of 3 times.
In this version, the text has not yet been written, and it is talking about a future event—from which point in time a past event will have happened.
2. By the time I had written this text, I had partaken of the brew for a total of 3 times.
Here, both the writing and the drinking have already occurred.
The phrase by the time of writing this text does not sound completely natural because of its ambiguous nature. It can be interpreted in either of the above senses—the writing of the text is still to happen or it has already happened. Because of this ambiguity, it is better to rephrase it in order to make the meaning explicit.
Note, however, that, semantically, there is a problem with the writing of the text being either in the past or the future—unless the context makes it clear that this text is a very long passage (say a book) rather than the single sentence.
If the long passage is still to be written (the sentence in the question is introducing it), then the first rephrasing is appropriate. If the long passage has already been written (the sentence in the question is explaining it), then the second rephrasing is appropriate.
But if this text refers only to the sentence itself, then it is in the process of being written (between the sentence's first word and its last word).
As such, it should be phrased in neither the past nor the future. It should be phrased in the present:
3. As I write this text, I have already partaken of the brew for a total of 3 times.