Getting Started with Google Gemini API

Here are the blocks I’ve configured that provide a valid JSON response from the Google Gemini API. You will need your own API key.

Here’s an example of part of the JSON response formatted in https://codebeautify.org/jsonviewer:

Here’s an example of the blocks that will allow you to parse out the “text” property from that API response:

If you are able to get a response but need more help parsing the JSON text, see my full tutorial here: API JSON Tutorial (Video).

5 Likes

thanks for the help :smile:

@tatiang I created a text generating app using gemini api. It is giving me good results but the gemini api key is not working for the European regions. Is there any solution for this? Kindly guide

I’m sorry, I’m not familiar with that problem.

Hi Mr. Tatiang!
This tutorial is very very helpful for text generation but suppose i wanted to get images from the API too how would we go about implementing that?

Please do let me know.

Thank you!

I’m not sure. You would need to post the JSON response from an API call that returns an image url. Then I could help you parse that in Thunkable.

Thank you @tatiang very much! Works like a charm.

1 Like

VPN will do.

good tutorial but when i tried the app it gave an error that says invalid api key but i know that it is not so can you help


I just tried the same project using my API key and it worked fine.

do you know any way to fix it?
i tried everything but it still didn’t working.

Can you post a link to your project but remove your API key? I can try it with mine. I suspect your API key is invalid but you’d have to work with Google to fix that.

Actually, before you do that, post the full text of the Web_API1’s URL without your key. What is the value of the first text block from the join block? Post it as text, not a screenshot.

edited
https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key=YOUR_API_KEY
:Thunkable

I used my API key with your project and your url and got a valid response:

{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "text": "The dolphin's playful leap sent shimmering spray skyward, a joyous arc against the setting sun.  A splash of silver, a moment of pure freedom. \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"
        }
      ]
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 10,
    "candidatesTokenCount": 32,
    "totalTokenCount": 42
  },
  "modelVersion": "gemini-1.5-flash-001"
}

can you send me the web api settings ?

They are blank. I never use those. I like to set those values using blocks. So what you see at the top of this topic are the settings I use. But more importantly, I used my API key with your project and it worked. So the settings aren’t the problem. The problem is your API key.

ok thank you so much