# Track Gemini answers

`POST https://api.answerline.dev/v1/monitor/gemini`

Get structured output from Google Gemini for any prompt: the generated answer and the sources it cites, exportable as Markdown

From $1.00 per 1,000 requests. Failed requests are free. Also runs as an async task of type `GEMINI`.

## Body

- `prompt` (string, required): Prompt submitted to Gemini, up to 2,000 characters. A longer prompt is refused with a 400 that states its length.
- `country` (string, required): Code of the country or region used to localize the response
- `include` (object): Flags that add extra output formats to the response (optional)
  - `include.markdown` (boolean): Add a markdown version of the response to the result
  - `include.html` (boolean): A copy of the Gemini page as it was when the answer was captured, stored on our file host and linked in `html`, to check the answer against. It is free.
  - `include.rawResponse` (boolean): Return the answer as normalized stream events. For the engine's answer as received, use `include.rawWire`.
  - `include.rawWire` (boolean): Return the engine's own response as received in result.rawWire: the answer stream, the rendered results pages or the RSS feed, without Gemini's detected location or ChatGPT's session tokens; null where it was not captured. Free. See https://answerline.dev/docs/output-formats#raw-wire
  - `include.screenshot` (boolean): Return a full-page PNG screenshot of the engine's page as it showed the finished answer, in result.screenshot: a link, or one link per results page on Google Search. On ChatGPT, Gemini, AI Mode, Google Search, Perplexity and Grok; other engines refuse it with a 400. Absent when the answer was read without a rendered page or its page was not available. Free. See https://answerline.dev/docs/output-formats#screenshots
- `state` (string): US state code (e.g. "CA", "DC" included). Sent without a country, the request asks for the US; sent with any country other than "US", it is refused with a 400, uncharged. ChatGPT and Gemini answer as a person in that state sees it; every other engine accepts it and answers for the whole US, at the price of a request without it. provenance.requestedState reports the state asked. See https://answerline.dev/docs/coverage#states
- `answerDepth` ("any" | "full" | "quick"): Accepted so existing requests stay valid; it does not change the answer or the price. Every engine writes one depth: Perplexity answers every request with its Quick Search answer, and provenance.answerDepth says quick. See https://answerline.dev/docs/engine-features/#answer-depth

## Returns

- `result.text` (string): Text of Gemini's reply
- `result.markdown` (string): Gemini's reply as Markdown
- `result.model` (string): The model Gemini names as the one that answered; null when the answer does not name it.
- `result.videos` (object[]): Video cards Gemini shows in its answer, in answer order
- `result.searchQueries` (string[]): Searches Gemini ran for the answer, when it shows them
- `result.html` (string): Present when include.html is true: the link to the stored copy of the Gemini page.
- `result.sources` (object[]): Sources that Gemini cited
- `result.citationPills` (object[]): Citation pills that appear inline in the Gemini answer. Every element pairs one chip with one source: a chip backed by N sources (Gemini's equivalent of `+N`, or a section-summary chip) yields N elements with the same `citationPillId`, each holding that source's own `label`, `url` and `domain`. Grouping by `citationPillId` rebuilds the pills. `label` is always sent; it may be an empty string if the rail gives that source no title. Empty when the answer has no pills.
- `result.places` (object[]): Place cards included in lodging and local answers
- `result.rawResponse` (object[]): The answer as normalized stream events (present when include.rawResponse is true). For the engine's answer as received, use include.rawWire.
- `result.shoppingCards` (object[]): Product cards Gemini shows beside a shopping-related answer, in display order. Absent when the answer has none.
- `result.entities` (object[]): The brands and products Gemini's answer shows as entity cards, in answer order. Absent when the answer has none.
- `result.screenshot` (string): Present when include.screenshot is true and the answer came from a rendered page: the link to the PNG screenshot of the Gemini page once the answer finished.
- `result.links` (object[]): The links in the answer's text, in the order a reader meets them: one entry per web (http or https) link the answer shows, images and code aside, with the words it shows (text), where it goes (url), its domain and its 1-based position. Sources cited by pills are in citationPills; links to the same page appear in both when the answer does both. Empty when the text links nowhere.

## Responses

- 200: Gemini monitoring result (success)
- 400: Bad Request - the request failed validation
- 401: Unauthorized - authentication failed
- 403: Forbidden - INSUFFICIENT_CREDITS: the balance does not cover this request
- 404: Not Found - No such route, or the engine is paused
- 409: Conflict - the resource is in a conflicting state
- 429: Too Many Requests - the call could not start now (`CONCURRENT_LIMIT_EXCEEDED`), or the service dropped the request because it was overloaded (`SERVICE_OVERLOADED`); that case returns `Retry-After` without any limit headers. `RATE_LIMIT_EXCEEDED`, with `Retry-After`, is sent only when one address presented too many unknown keys
- 499: Client Closed Request - the client cancelled the request
- 500: Internal Server Error
- 502: Bad Gateway - the engine failed

## Request

curl:

```bash
curl -X POST "https://api.answerline.dev/v1/monitor/gemini" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"prompt":"iPhone 17 or Galaxy S26?","country":"US"}'
```

TypeScript:

```ts
import { Client } from "@answerline/sdk";

const client = new Client({ apiKey: process.env.API_KEY! });
const answer = await client.monitor.gemini({
  "prompt": "iPhone 17 or Galaxy S26?",
  "country": "US"
});
```

Python:

```python
import os
from answerline import Client

with Client(os.environ["API_KEY"]) as client:
    answer = client.monitor.gemini(
        prompt="iPhone 17 or Galaxy S26?",
        country="US",
    )
```


## Example responses

200:

```json
{
  "success": true,
  "result": {
    "text": "Quantum computing applies quantum mechanics to...",
    "markdown": "**Machine learning** is a branch of artificial intelligence...",
    "model": "3.5 Flash-Lite",
    "videos": [
      {
        "title": "I Tested Every Running Shoe Under $150 So You Don't Overpay",
        "link": "https://www.youtube.com/watch?v=A6l77V2gkGE",
        "platform": "YouTube",
        "channel": "RunnersVibe · Running Shoe Reviews",
        "duration": "5:30",
        "thumbnail": "https://i.ytimg.com/vi/A6l77V2gkGE/maxresdefault.jpg"
      }
    ],
    "searchQueries": [
      "best running shoes under $150",
      "running shoe reviews 2026"
    ],
    "html": "https://files.answerline.dev/html/c45a5081-808d-4ed3-9c86-e4baf16c8ab8/1/page-1.html",
    "sources": [
      {
        "position": 1,
        "label": "Wikipedia - Machine Learning",
        "url": "https://en.wikipedia.org/wiki/Quantum_computing",
        "description": "Quantum computing uses qubits to process information..."
      }
    ],
    "citationPills": [
      {
        "label": "Photosynthesis — Wikipedia",
        "citationPillId": 1,
        "url": "https://en.wikipedia.org/wiki/Quantum_computing",
        "domain": "en.wikipedia.org",
        "description": "Quantum computing uses qubits to process information...",
        "position": 1
      },
      {
        "label": "IBM Quantum",
        "citationPillId": 1,
        "url": "https://www.ibm.com/quantum",
        "domain": "ibm.com",
        "position": 3
      }
    ],
    "places": [
      {
        "index": 0,
        "title": "Sofitel Sydney Darling Harbour",
        "link": "https://www.google.com/travel/search?q=Pullman+Quay+Grand+Sydney+Harbour",
        "thumbnail": "https://lh3.googleusercontent.com/gps-cs-s/example",
        "rating": 4.4,
        "reviews": 1307,
        "type": "5-star hotel",
        "description": "Boutique riverside hotel with elegant rooms, a rooftop terrace, a spa & an all-day café.",
        "price": "$565"
      }
    ],
    "rawResponse": [
      null
    ],
    "shoppingCards": [
      {
        "position": 1,
        "title": "Brooks Ghost 16",
        "productLink": "https://google.com/search?q=Brooks+Ghost+16&prds=productid%3A123",
        "productId": "16919532047675658099",
        "price": {
          "value": 329.99,
          "currency": "USD",
          "raw": "$329.99"
        },
        "oldPrice": {
          "value": 329.99,
          "currency": "USD",
          "raw": "$329.99"
        },
        "store": "Runner's Depot",
        "storeLink": "string",
        "storeCount": 4,
        "shipping": "string",
        "deliveryTime": "string",
        "rating": 4.4,
        "reviews": 1261,
        "brand": "Brooks",
        "description": "string",
        "thumbnail": "string",
        "images": [
          "string"
        ],
        "catalogId": "14325977521193745857",
        "gpcId": "11523404812175301769"
      }
    ],
    "entities": [
      {
        "type": "product",
        "name": "Nike Court Vision Low"
      },
      {
        "type": "product",
        "name": "Nike Air Force 1 '07"
      },
      {
        "type": "product",
        "name": "New Balance 550 Leather"
      }
    ],
    "screenshot": "https://files.answerline.dev/html/c45a5081-808d-4ed3-9c86-e4baf16c8ab8/1/3f9a1c2e8b7d4a6f9e0c1b2a3d4e5f60/page-1.png",
    "links": [
      {
        "position": 1,
        "text": "Nike Pegasus 42",
        "url": "https://www.nike.com/t/pegasus-42-mens-road-running-shoes",
        "domain": "nike.com"
      }
    ]
  }
}
```

400:

```json
{
  "success": false,
  "error": "Request validation failed",
  "details": [
    {
      "field": "prompt",
      "message": "Prompt must not be empty"
    }
  ]
}
```

502:

```json
{
  "error": {
    "code": "EXTERNAL_SERVICE_ERROR",
    "message": "External service error: the service failed",
    "details": {
      "service": "CHATGPT"
    },
    "timestamp": "2025-01-15T12:00:00.000Z"
  }
}
```

