> For the complete documentation index, see [llms.txt](https://docs.scraperapi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.scraperapi.com/structured-data-endpoints/ai-results/gemini.md).

# Gemini

The `Gemini API` endpoint fetches response data from a results page of a Gemini prompt. Results can be returned in raw HTML format or as a structured JSON format.

{% tabs %}
{% tab title="cURL" %}

```bash
curl --request GET \
--url "https://api.scraperapi.com/structured/google/gemini?api_key=API_KEY&\
query=QUERY&output_format=OUTPUT_FORMAT&include_html=Boolean"
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

payload = {
    'api_key': 'API_KEY',
    'query': 'QUERY',
    'output_format': 'OUTPUT_FORMAT',
    'include_html': 'Boolean' #True/False
}

r = requests.get('https://api.scraperapi.com/structured/google/gemini',params=payload)

print(r.text)
```

{% endtab %}

{% tab title="NodeJS" %}

```javascript
import fetch from 'node-fetch';

fetch(
  'https://api.scraperapi.com/structured/google/gemini?api_key=API_KEY&query=QUERY&output_format=OUTPUT_FORMAT&include_html=Boolean'
)
  .then(response => response.json()) 
  .then(data => {
    console.log(data);
  })
  .catch(error => {
    console.error(error);
  });
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
$url = "https://api.scraperapi.com/structured/google/gemini?api_key=API_KEY&query=QUERY&output_format=OUTPUT_FORMAT&include_html=Boolean";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);

$response = curl_exec($ch);
curl_close($ch);

print_r($response);
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require 'net/http'
require 'json'

params = {
  :api_key => "API_KEY",
  :query => "QUERY",
  :output_format => "OUTPUT_FORMAT",
  :include_html => "Boolean" #True/False
}

uri = URI('https://api.scraperapi.com/structured/google/gemini')
uri.query = URI.encode_www_form(params)

website_content = Net::HTTP.get(uri)
print(website_content)
```

{% endtab %}

{% tab title="Java" %}

```java
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class Main {
    public static void main(String[] args) {
        try {
            String apiKey = "API_KEY";
            String query = "QUERY";
            String output_format = "OUTPUT_FORMAT";
            String include_html = "Boolean"; // True/False

            String urlStr = "https://api.scraperapi.com/structured/google/gemini?api_key=" 
                            + apiKey + "&query=" + query + "&coutput_format=" + output_format + "&include_html=" + include_html;

            URL url = new URL(urlStr);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");

            int responseCode = conn.getResponseCode();
            if (responseCode == HttpURLConnection.HTTP_OK) {
                BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                StringBuilder response = new StringBuilder();
                String line;
                while ((line = in.readLine()) != null) {
                    response.append(line);
                }
                in.close();
                System.out.println(response.toString());
            } else {
                System.out.println("Error in API Call. Response code: " + responseCode);
            }

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
```

{% endtab %}
{% endtabs %}

**Async Request**

{% tabs %}
{% tab title="cURL" %}

```bash
curl -s -X POST \
"https://async.scraperapi.com/structured/google/gemini" \
	-H "Content-Type: application/json" \
	-d '{
			"apiKey": "API_KEY",
			"query": "PROMPT_TEXT",
			"output_format": "OUTPUT_FORMAT",
		  "include_html": "true"
		}'
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
url = "https://async.scraperapi.com/structured/google/gemini"
headers = {
    "Content-Type": "application/json"
}
data = {
    "apiKey": "API_KEY",
    "query": "QUERY",
    "output_format": "OUTPUT_FORMAT",
    "include_html": "Boolean" #True/False
}
response = requests.post(url, json=data, headers=headers)
print(response.text)
```

{% endtab %}

{% tab title="NodeJS" %}

```javascript
import fetch from 'node-fetch';

const options = {
  method: 'POST',
  body: JSON.stringify({
    apiKey: 'API_KEY',
    query: 'QUERY',
    output_format: 'OUTPUT_FORMAT',
    include_html: 'Boolean' // True/False
  }),
  headers: {
    'Content-Type': 'application/json',
  },
}

fetch('https://async.scraperapi.com/structured/google/gemini', options)
  .then(response => {
    response.text().then(text => console.log(text));
  })
  .catch(error => {
    console.log(error)
  })
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
$curl = curl_init();

$data = json_encode(array(
    'apiKey' => 'API_KEY',
    'query' => 'QUERY',
    'output_format' => 'OUTPUT_FORMAT',
    'include_html' => 'Boolean' // True/False
));

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://async.scraperapi.com/structured/google/gemini',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => $data,
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json'
  ),
  CURLOPT_SSL_VERIFYPEER => false,
  CURLOPT_SSL_VERIFYHOST => false
));

$response = curl_exec($curl);

if (curl_errno($curl)) {
    echo 'Error:' . curl_error($curl);
} else {
    echo $response;
}

curl_close($curl);
?>
```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require 'net/http'
require 'json'
require 'uri'

uri = URI('https://async.scraperapi.com/structured/google/gemini')
request = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
request.body = {
  apiKey: 'API_KEY',
  query: 'QUERY',
  output_format: 'OUTPUT_FORMAT',
  include_html: 'Boolean' # True/False
}.to_json
begin
  response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
    http.request(request)
  end
  puts response.body
rescue => e
  puts "Error: #{e.message}"
end
```

{% endtab %}

{% tab title="Java" %}

```java
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import javax.net.ssl.HttpsURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;

public class Main {
    public static void main(String[] args) {
        try {
            String apiKey = "API_KEY";
            String jsonInputString = "{"
                + "\"apiKey\": \"" + apiKey + "\", "
                + "\"query\": \"QUERY\", "
                + "\"output_format\": \"OUTPUT_FORMAT\", "
                + "\"include_html\": \"Boolean\" " // True/False
                + "}";

            URL url = new URL("https://async.scraperapi.com/structured/google/gemini");
            HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Content-Type", "application/json");
            connection.setRequestProperty("Accept", "*/*");
            connection.setDoOutput(true);

            try (OutputStream os = connection.getOutputStream()) {
                byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8);
                os.write(input, 0, input.length);
            }

            int responseCode = connection.getResponseCode();
            StringBuilder response = new StringBuilder();
            BufferedReader in = new BufferedReader(
                new InputStreamReader(connection.getInputStream())
            );

            String readLine;
            while ((readLine = in.readLine()) != null) {
                response.append(readLine);
            }
            in.close();

            if (responseCode == HttpURLConnection.HTTP_OK) {
                System.out.println("Response: " + response.toString());
            } else {
                throw new Exception("Error in API Call: Response code " + responseCode + "\nbody: " + response.toString());
            }

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
```

{% endtab %}
{% endtabs %}

{% hint style="success" %}
**Note**: If you want to send multiple prompts at once use queries instead of query.

Example: `"queries": ["PROMPT_TEXT1", "PROMPT_TEXT2"]`,
{% endhint %}

**Async Response**

```json
{
"id":"ffa6e04a-c11d-40a4-9777-44f070b89a8c",
"attempts":0,
"status":"running",
"statusUrl":"https://async.scraperapi.com/jobs/ffa6e04a-c11d-40a4-9777-44f070b89a8c",
"query":"best electric cars",
"output_format":"html",
"supposedToRunAt":"2026-05-19T19:25:00.000Z"
}
```

After the job(s) finish, you will find the response payload by polling the statusURL.

**Supported Parameters**

<table><thead><tr><th width="274.2591552734375">Parameters</th><th>Details</th></tr></thead><tbody><tr><td><code>API_KEY</code> (required)</td><td>Your API Key.</td></tr><tr><td><code>QUERY</code> (required)</td><td>The prompt to send to Gemini.</td></tr><tr><td><code>OUTPUT_FORMAT</code></td><td><code>json</code> returns parsed structured data (default). <code>html</code> returns raw HTML.</td></tr><tr><td><code>INCLUDE_HTML</code></td><td>Determines whether raw HTML is included in the response (this can increase the size of the response). Can be set to true or false (default).</td></tr></tbody></table>

**JSON Response**

```json
{
  "query": "string",              // the submitted prompt, echoed back
  "url": "string|null",           // result/thread URL for the answer
  "model": "string|null",         // model that produced the answer (see notes)
  "answer": "string",             // the full answer, in Markdown
  "sources": [                    // citations / web results (may be empty)
    {
      "title": "string",
      "url": "string",
      "domain": "string",         // bare hostname, www. stripped
      "snippet": "string"         // may be empty when the engine gives none
    }
  ],
  "related_queries": ["string"]   // follow-up suggestions (may be empty)
}
```

**Field Reference**

<table data-search="false"><thead><tr><th width="172.8887939453125">Field</th><th width="165.1480712890625">Type</th><th width="177.5555419921875">Always present?</th><th>Notes</th></tr></thead><tbody><tr><td><code>query</code></td><td>string</td><td>yes</td><td>Echoed prompt</td></tr><tr><td><code>url</code></td><td>string | null</td><td>yes</td><td>Result/thread URL</td></tr><tr><td><code>model</code></td><td>string | null</td><td>yes</td><td>Best-effort. <code>null</code> when not surfaced</td></tr><tr><td><code>answer</code></td><td>string (Markdown)</td><td>yes</td><td>The answer body</td></tr><tr><td><code>sources[]</code></td><td>array of object</td><td>yes (may be empty)</td><td><code>{ title, url, domain, snippet }</code></td></tr><tr><td><code>related_queries[]</code></td><td>array of string</td><td>yes (may be empty)</td><td>Follow-up suggestions</td></tr></tbody></table>

{% hint style="success" %}
All fields are always present in the JSON (empty array or `null` rather than omitted).
{% endhint %}

#### Specifics

**`model`**

* **Populated** for Gemini. For example  `3.5 Flash`.

**`sources`**

* Empty when the answer was not web-grounded (common for plain Gemini answers that did not trigger a web search).
* **snippet**
* **domain** is normalized to a bare hostname (**[www](http://www).** stripped) across all engines.

#### Pricing

Gemini queries run on ScraperAPI's standard credit system.

| **Request Type** | **Credits Charged** |
| ---------------- | ------------------- |
| `Any Parameter`  | 25                  |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.scraperapi.com/structured-data-endpoints/ai-results/gemini.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
