Turn Gemini Pro to a Translate API, can Gemini compet with Google Translate API

Stéphane Giron
3 min readJan 16, 2024

--

Google use for long time AI to build its Translation API but now with the rise of LLM, game is changing. How Gemini Pro can compet in this task to an established API leader.

Technical details

To be used as an API, we need to send the input text and the language we want the translation and get an output we can use programmatically.

For the ouput we will go to a JSON output, which is convenient to use in code. For input we don’t really need a specific format as with Gemini we can send text “as we speak”. We just need to be clear in the prompt to avoid miss understanding and some blabla in the output that could create conflict with the JSON output expected.

The prompt

Translate in french text in input. Use json template in output and replace RESULT by the translation.
Input :
There is a gap between Mistral AI models and most advanced models GPT4 and Gemini Ultra but compared to others models it is a good challenger.
Diffrence will be on performance and pricing. For performance during my tests it was slower. I did not make a a table comparison but by experience after lot of development, I see the diffrence and it is huge some times.
Output :
{“text”:”RESULT”}

The answer

{“text”:”Il existe un fossé entre les modèles Mistral AI et les modèles les plus avancés GPT4 et Gemini Ultra, mais comparé à d’autres modèles, il s’agit d’un bon challenger. La différence se fera sur les performances et les prix. En ce qui concerne les performances, lors de mes tests, il était plus lent. Je n’ai pas fait de comparaison sous forme de tableau, mais par expérience, après beaucoup de développement, je vois la différence et elle est parfois énorme.”}

This request consume :

"usageMetadata": {
"promptTokenCount": 104,
"candidatesTokenCount": 107,
"totalTokenCount": 211
}

Pricing comparison

Could Gemini pro be a cheaper alternative to Google Translate API. Let’s make the comparison. Pricing for both APIs is as follow :

  • Translate API Basic : $20 per million characters = $0.002 / 1k characters
  • Gemini Pro : $0.00025 / 1k characters & $0.0005 / 1k characters

For a text of 10k Characters with an output of 10000 chars also price will be :

  • Translate API : 0.02 $
  • Gemini pro : 0.0025 $ + 0.005$ = 0.0075 $
  • For a 1M characters it will be 2$ Vs 0.75$.

Gemini Pro is 2.5 less expansive.

Is it really a good option

Lot of people already use generative AI to do translation, so yes it can be a valid solution.

Response from the LLM is really stable, I mean he always returned a JSON and don’t add some random text before or after.

Weakness will be confidence in translation, during my tests it happens some time the translation was not 100% accurate and some time the response was weird. I get a german translation one time even if I requested a french one 🙃. It was rare but it happens.

Mathematicaly speaking going with Gemini Pro is less expansive. The price difference for 1 million characters is not really big but Gemini is cheaper.

What is is interestng in this work is how Generative AI can change the way we manipulate and work with text. From my point of view this example is interesting and using the API in this way could be something I will do in the future.

--

--